-
-
Notifications
You must be signed in to change notification settings - Fork 25
176 lines (131 loc) · 5 KB
/
publish.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
on: [push]
jobs:
build-api:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- id: get_branch
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- id: set_image_name
run: echo "IMAGE_NAME=us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/api/${BRANCH}" >> $GITHUB_ENV
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:$GITHUB_SHA -f api.Dockerfile .
- name: Push Docker Image to Google Artifact Registry
run: |
gcloud auth configure-docker us-east1-docker.pkg.dev
docker push $IMAGE_NAME:$GITHUB_SHA
build-chat:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- id: get_branch
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- id: set_image_name
run: echo "IMAGE_NAME=us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/chat/${BRANCH}" >> $GITHUB_ENV
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:$GITHUB_SHA -f chat.Dockerfile .
- name: Push Docker Image to Google Artifact Registry
run: |
gcloud auth configure-docker us-east1-docker.pkg.dev
docker push $IMAGE_NAME:$GITHUB_SHA
build-cron:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- id: get_branch
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- id: set_image_name
run: echo "IMAGE_NAME=us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/cron/${BRANCH}" >> $GITHUB_ENV
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:$GITHUB_SHA -f cron.Dockerfile .
- name: Push Docker Image to Google Artifact Registry
run: |
gcloud auth configure-docker us-east1-docker.pkg.dev
docker push $IMAGE_NAME:$GITHUB_SHA
build-status:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- id: get_branch
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- id: set_image_name
run: echo "IMAGE_NAME=us-east1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/status/${BRANCH}" >> $GITHUB_ENV
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:$GITHUB_SHA -f status.Dockerfile .
- name: Push Docker Image to Google Artifact Registry
run: |
gcloud auth configure-docker us-east1-docker.pkg.dev
docker push $IMAGE_NAME:$GITHUB_SHA
deploy-k8s:
runs-on: ubuntu-latest
needs:
- build-api
- build-chat
- build-cron
- build-status
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Deploy if on main
run: |
set -eu
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [[ "${BRANCH_NAME:-}" != main ]]; then
exit
fi
# == Set up credentials ===
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/.ssh/google_compute_engine
echo "$SSH_PUBLIC_KEY" > ~/.ssh/google_compute_engine.pub
sudo chmod 600 ~/.ssh/google_compute_engine
sudo chmod 600 ~/.ssh/google_compute_engine.pub
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/google_compute_known_hosts
set -x
# == ssh into the machine ===
gcloud compute scp \
--zone "us-east1-b" \
--project "duolicious" \
vm/ci-deployment.sh \
vm/deployment.yaml \
"duolicious_app@instance-1:~"
gcloud compute ssh \
"duolicious_app@instance-1" \
--zone "us-east1-b" \
--project "duolicious" \
--command "~/ci-deployment.sh ${BRANCH_NAME} ${GITHUB_SHA}"
shell: bash
env:
SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}}
SSH_PUBLIC_KEY: ${{secrets.SSH_PUBLIC_KEY}}
SSH_KNOWN_HOSTS: ${{secrets.SSH_KNOWN_HOSTS}}