๐ fix: ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์์ ์บ ํผ์ค ์ ํ ํ ํ๋ฉด์ด ์ ํ๋์ง ์๋ ๋ฌธ์ ํด๊ฒฐ #137
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: CI/CD Pipeline | |
| # main ๋ธ๋์น์ ๋ํ Pull request ๋ฐ Merge | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - ".github/**" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| # 1. ๋ ํฌ์งํ ๋ฆฌ ์์ค ์ฝ๋ ์์ ํ๊ฒฝ์ผ๋ก ๊ฐ์ ธ์ค๊ธฐ | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # 2. ํ๊ฒฝ๋ณ์(.env) ํ์ผ ์์ฑ | |
| - name: Set Environment File | |
| run: | | |
| echo "${{ secrets.PROD_ENV }}" > .env | |
| chmod 644 .env | |
| cat .env | |
| # 3. ๋์ปคํ๋ธ ๋ก๊ทธ์ธ | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # 4. ๋์ปค ํ๋ธ์ ์ด๋ฏธ์ง ํธ์ | |
| - name: Push Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| context: . | |
| tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest | |
| # 5. GCP ์ธ์ฆ | |
| - name: Authenticate to GCP | |
| id: 'auth' | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} # ์์ฑํ ์ํฌ๋ก๋ ์์ด๋ดํฐํฐ ํ์ ID | |
| service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }} # IAM ์๋น์ค ๊ณ์ | |
| # 6. GCP Compute Engine SSH๋ก ๋ฐฐํฌ | |
| - name: Deploy to GCP Compute Engine | |
| id: 'compute-ssh' | |
| uses: 'google-github-actions/ssh-compute@v1' | |
| with: | |
| instance_name: ${{ secrets.GCP_INSTANCE_NAME }} | |
| zone: ${{ secrets.GCP_INSTANCE_ZONE }} | |
| ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} | |
| command: | | |
| mkdir ./${{ github.repository }} | |
| cd ./${{ github.repository }} | |
| ls -al | |
| sudo curl -o docker-compose.yml https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml | |
| sudo docker-compose down | |
| sudo docker-compose up -d ${{ secrets.DOCKER_IMAGE_NAME }} | |
| sudo docker image prune -a -f | |
| # Example of using the output | |
| - id: 'debug' | |
| run: |- | |
| echo '${{ steps.compute-ssh.outputs.stdout }}' | |
| echo '${{ steps.compute-ssh.outputs.stderr }}' | |
| # 7. Sentry ์ค์ | |
| - name: Create Sentry release | |
| uses: getsentry/action-release@v1 | |
| env: | |
| SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} | |
| SENTRY_ORG: ${{ secrets.SENTRY_ORG }} | |
| SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} | |
| with: | |
| environment: production | |
| inject: true | |
| sourcemaps: './dist' |