Skip to content

Merge pull request #7 from hykim02/main #1

Merge pull request #7 from hykim02/main

Merge pull request #7 from hykim02/main #1

Workflow file for this run

name: Deploy to GCP
on:
push:
branches:
- main
paths-ignore:
- '.github/workflows/**'
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
# CI에서 생성한 JAR 파일 다운로드
- name: Download JAR Artifact
uses: actions/download-artifact@v4
with:
name: application-jar
path: build/libs/
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build & Push Docker Image
uses: docker/build-push-action@v6
with:
push: true
context: .
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest
- name: Authenticate to GCP
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
- name: Deploy to GCP Compute Engine
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: |
cd /app/${{ github.repository }}
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