-
Notifications
You must be signed in to change notification settings - Fork 2
78 lines (66 loc) · 2.14 KB
/
github-actions.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Deploy using GitHub Actions
# event trigger
# develop/main 브랜치에 push 혹은 pull_request가 되었을 때 실행
on:
push:
branches: [ "develop/main" ]
pull_request:
branches: [ "develop/main" ]
env:
GITHUB_SHA: ${{ github.sha }}
PROJECT_ID: ${{secrets.PROJECT_ID}}
GCE_INSTANCE: ${{secrets.GCE_INSTANCE}}
GCE_INSTANCE_ZONE: ${{secrets.GCE_INSTANCE_ZONE}}
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
# 기본 체크아웃
- name: Checkout
uses: actions/checkout@v4
# Gradlew 실행 허용
- name: Run chmod to make gradlew executable
run: |
chmod +x ./withmate/gradlew
# JDK 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# prod 설정
- name: make application-prod.yml
run: |
cd ./withmate/src/main/resources
touch ./application-prod.yml
echo "${{ secrets.YML_PROD }}" > ./application-prod.yml
shell: bash
# GCP Setup
- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
- name: 'Use gcloud CLI'
run: 'gcloud info'
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
# Build the Docker image
- name: Build
run: |-
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" -f ./withmate/Dockerfile ./withmate
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"
- name: Deploy
run: |-
gcloud compute instances update-container "$GCE_INSTANCE" \
--zone "$GCE_INSTANCE_ZONE" \
--container-image "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"