CD #6
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: CD | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 깃 레포 체크아웃 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # .env 생성 | |
| - name: Create .env file | |
| run: echo "${{ secrets.ENV_FILE }}" > .env | |
| # EC2로 파일 전송 | |
| - name: Copy files to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: 22 | |
| source: "docker/,.env,nginx/,deploy.sh" | |
| target: "/home/ubuntu/growin/" | |
| # EC2에서 도커 컨테이너 재배포 | |
| - name: Deploy to EC2 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_KEY }} | |
| port: 22 | |
| script: | | |
| cd /home/ubuntu/growin | |
| export GHCR_TOKEN=${{ secrets.GHCR_TOKEN }} | |
| export GHCR_USERNAME=${{ github.actor }} | |
| echo $GHCR_TOKEN | docker login ghcr.io -u $GHCR_USERNAME --password-stdin | |
| # 공통 컨테이너 실행 | |
| sudo docker compose -f docker/docker-compose.common.yml up -d | |
| # 배포 로직 실행 | |
| chmod +x deploy.sh | |
| ./deploy.sh |