-
Notifications
You must be signed in to change notification settings - Fork 3
188 lines (162 loc) · 5.48 KB
/
build_deploy_websocket.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
177
178
179
180
181
182
183
184
185
186
187
188
name: Build and Deploy Websocket
on:
workflow_call:
inputs:
sha_short:
required: true
type: string
new_tag:
required: true
type: string
new_tag_short:
required: true
type: string
name:
required: true
type: string
sha:
required: true
type: string
jobs:
build-websocket:
name: Build Websocket
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install Protocol Buffers Compiler
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install Thrift Compiler
run: |
sudo apt-get install -y thrift-compiler
- name: Build Websocket
run: |
cd server/websocket
cargo build --release
- name: Create distribution directory
run: |
mkdir -p server/websocket/dist
cp server/target/release/websocket server/websocket/dist/reearth-flow-websocket
- name: Rename Artifacts
if: ${{ inputs.name != 'blank' }}
run: |
cd server/websocket/dist
mv reearth-flow-websocket reearth-flow-websocket_${{ inputs.name }}
- name: List Artifacts
run: ls -l server/websocket/dist
- name: Upload Websocket Artifacts
uses: actions/upload-artifact@v4
with:
name: websocket-artifacts
path: server/websocket/dist/*
build-docker-image:
name: Build and Push Docker Image
needs: build-websocket
runs-on: ubuntu-latest
if: ${{ inputs.name != 'blank' || inputs.new_tag != 'blank' }}
permissions:
contents: read
id-token: write
env:
IMAGE_NAME: reearth/reearth-flow-websocket
IMAGE_GCP: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-flow-websocket
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Websocket Artifacts
uses: actions/download-artifact@v4
with:
name: websocket-artifacts
path: server/websocket/dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
service_account: ${{ secrets.GCP_SA_EMAIL }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine Build Options
id: options
run: |
TAG="${{ inputs.new_tag_short != 'blank' && inputs.new_tag_short || '' }}"
NAME="${{ inputs.name }}"
SHA="${{ inputs.sha_short }}"
if [[ -n "$TAG" ]]; then
PLATFORMS="linux/amd64"
VERSION="$TAG"
TAGS="$IMAGE_NAME:$TAG"
if [[ ! "$TAG" =~ '-' ]]; then
TAGS+=",${IMAGE_NAME}:${TAG%.*}"
TAGS+=",${IMAGE_NAME}:${TAG%%.*}"
TAGS+=",${IMAGE_NAME}:latest"
fi
else
PLATFORMS="linux/amd64"
VERSION="$SHA"
TAGS="$IMAGE_NAME:$NAME"
fi
echo "platforms=$PLATFORMS" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: server/websocket
file: server/websocket/Dockerfile.websocket
platforms: ${{ steps.options.outputs.platforms }}
push: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Configure Docker for GCP
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
- name: Push Docker Image to GCP Artifact Registry
if: ${{ inputs.name == 'nightly' }}
run: |
docker pull $IMAGE_NAME:${{ inputs.name }}
docker tag $IMAGE_NAME:${{ inputs.name }} $IMAGE_GCP:${{ inputs.name }}
docker push $IMAGE_GCP:${{ inputs.name }}
deploy-to-cloud-run:
name: Deploy to Cloud Run (Nightly)
needs: build-docker-image
runs-on: ubuntu-latest
if: ${{ inputs.name == 'nightly' }}
permissions:
contents: read
id-token: write
env:
IMAGE: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-flow-websocket:nightly
GCP_REGION: us-central1
CLOUD_RUN_SERVICE: reearth-flow-websocket
steps:
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
service_account: ${{ secrets.GCP_SA_EMAIL }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Deploy to Cloud Run
run: |
gcloud run deploy $CLOUD_RUN_SERVICE \
--image $IMAGE \
--region $GCP_REGION \
--platform managed \
--quiet