Push ai #200
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to EC2 | |
| # on의 이벤트가 발생하면 jobs 실행 | |
| # 자율적으로 구성: 진짜로 배포할 코드를 push하는 branch 이름으로 변경 | |
| on: | |
| push: | |
| branches: | |
| - prod_aws # main브랜치에 push되었을 때 | |
| pull_request: | |
| branches: | |
| - prod_aws # main브랜치에 pr 날렸을 때 | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| # GitHub 리포지토리를 체크아웃 | |
| - name: Free Disk Space on GitHub Runner | |
| run: | | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /usr/local/lib/android | |
| sudo rm -rf /opt/ghc | |
| sudo rm -rf /usr/local/share/powershell | |
| sudo apt-get clean | |
| df -h | |
| - name: checkout | |
| uses: actions/checkout@v4 | |
| # Action Secret에 설정한 ENV_VARS 값을 .env 파일로 만듦 | |
| - name: create env file | |
| run: | | |
| touch .env | |
| echo "${{ secrets.ENV_VARS }}" >> .env | |
| # EC2에 접속해 원격디렉토리 생성 | |
| - name: create remote directory | |
| uses: appleboy/ssh-action@v0.1.3 | |
| with: | |
| host: ${{ secrets.HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.KEY }} | |
| script: mkdir -p /home/ubuntu/srv/ubuntu | |
| # SSH 키를 통해 소스 코드를 EC2 인스턴스(서버)로 복사 | |
| - name: copy source via ssh key | |
| uses: burnett01/rsync-deployments@4.1 | |
| with: | |
| switches: -avzr --delete | |
| remote_path: /home/ubuntu/srv/ubuntu/ | |
| remote_host: ${{ secrets.HOST }} | |
| remote_user: ubuntu | |
| remote_key: ${{ secrets.KEY }} | |
| # 서버에 접속한 뒤 deploy.sh(배포 스크립트)를 실행 | |
| - name: executing remote ssh commands using password | |
| uses: appleboy/ssh-action@v0.1.3 | |
| with: | |
| host: ${{ secrets.HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.KEY }} | |
| command_timeout: 120m | |
| script: | | |
| cd /home/ubuntu/srv/ubuntu | |
| sh config/scripts/deploy.sh |