-
Notifications
You must be signed in to change notification settings - Fork 5
65 lines (53 loc) · 1.94 KB
/
GCE_CD.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
name: Deploy to GCP VM
on:
workflow_dispatch: # 버튼 생성
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }} # 브랜치 자동 감지
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
- name: Clean up GCP authentication files
run: |
if gcloud auth list --format="value(account)" | grep -q '@'; then
gcloud auth revoke --all
fi
rm -f ~/.config/gcloud/application_default_credentials.json
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: '${{ secrets.GCP_PROJECT_ID }}'
- name: Generate SSH key
run: |
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -q -N ""
- name: Add SSH key to GCP project metadata
run: |
gcloud compute project-info add-metadata --metadata "ssh-keys=${GCP_VM_USER}:$(cat ~/.ssh/id_rsa.pub)"
env:
GCP_VM_USER: '${{ secrets.GCP_VM_USER }}'
- name: Copy code to GCP VM
run: |
gcloud compute scp --recurse --quiet ./* $GCP_VM_USER@$GCP_INSTANCE_NAME:/home/$GCP_VM_USER/app --zone $GCP_ZONE
env:
GCP_INSTANCE_NAME: '${{ secrets.GCP_INSTANCE_NAME }}'
GCP_VM_USER: '${{ secrets.GCP_VM_USER }}'
GCP_ZONE: '${{ secrets.GCP_ZONE }}'
- name: Deploy to GCP VM
run: |
gcloud compute ssh $GCP_VM_USER@$GCP_INSTANCE_NAME --zone $GCP_ZONE --command "
cd /home/$GCP_VM_USER/app &&
sudo docker compose -f sandol/docker-compose.yml up -d --build
"
env:
GCP_INSTANCE_NAME: '${{ secrets.GCP_INSTANCE_NAME }}'
GCP_VM_USER: '${{ secrets.GCP_VM_USER }}'
GCP_ZONE: '${{ secrets.GCP_ZONE }}'
- name: Delete leftover GCP credential files
run: |
rm -f ~/app/gha-creds-*.json