Update ci-cd pipeline.yml #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: CI/CD Pipeline | |
| on: | |
| # main 브랜치에 커밋된 경우, CI/CD 파이프라인 실행 | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| DOCKER_REGISTRY: dongho18 | |
| DOCKER_IMAGE_NAME: connect-gnu-node | |
| DOCKER_TAG: latest | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1. 레포지토리 소스 코드 작업 환경으로 가져오기 | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| # 2. 환경변수(.env) 파일 생성 | |
| - name: Set Environment File | |
| run: | | |
| echo "${{ secrets.PROD_ENV }}" > .env | |
| chmod 644 .env | |
| cat .env | |
| # 3. 도커 이미지 빌드 | |
| - name: Build Docker Image | |
| run: docker compose build backend_node_server | |
| # 4. 도커허브 로그인 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # 5. 도커 허브에 이미지 푸시 | |
| - name: Push Docker Image | |
| run: | | |
| docker tag $DOCKER_IMAGE_NAME $DOCKER_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG | |
| docker push $DOCKER_REGISTRY/$DOCKER_IMAGE_NAME:$DOCKER_TAG | |
| # 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: 'echo Hello world' | |