Skip to content

Commit 42d8d68

Browse files
authored
Create cd.yml
1 parent 8c3e748 commit 42d8d68

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/cd.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy to GCP
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '.github/workflows/**'
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
contents: read
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
# CI에서 생성한 JAR 파일 다운로드
20+
- name: Download JAR Artifact
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: application-jar
24+
path: build/libs/
25+
26+
- name: Login to DockerHub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKER_USERNAME }}
30+
password: ${{ secrets.DOCKER_PASSWORD }}
31+
32+
- name: Build & Push Docker Image
33+
uses: docker/build-push-action@v6
34+
with:
35+
push: true
36+
context: .
37+
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest
38+
39+
- name: Authenticate to GCP
40+
uses: google-github-actions/auth@v2
41+
with:
42+
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
43+
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
44+
45+
- name: Deploy to GCP Compute Engine
46+
uses: google-github-actions/ssh-compute@v1
47+
with:
48+
instance_name: ${{ secrets.GCP_INSTANCE_NAME }}
49+
zone: ${{ secrets.GCP_INSTANCE_ZONE }}
50+
ssh_private_key: ${{ secrets.GCP_SSH_PRIVATE_KEY }}
51+
command: |
52+
cd /app/${{ github.repository }}
53+
sudo curl -o docker-compose.yml https://raw.githubusercontent.com/${{ github.repository }}/main/docker-compose.yml
54+
sudo docker-compose down
55+
sudo docker-compose up -d ${{ secrets.DOCKER_IMAGE_NAME }}
56+
sudo docker image prune -a -f

0 commit comments

Comments
 (0)