Skip to content

Commit 06f744e

Browse files
authored
Merge pull request #24 from teableio/feat/preview-cloud-update
feat: add GitHub Actions workflow for preview cloud deployment
2 parents 85d1ae0 + 2132ae0 commit 06f744e

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: Preview Cloud PR Update
2+
3+
on:
4+
repository_dispatch:
5+
types: [preview-cloud-update]
6+
7+
jobs:
8+
build-push:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
start_time: ${{ steps.start_time.outputs.start }}
12+
pr_number: ${{ github.event.client_payload.pr_number }}
13+
ref: ${{ github.event.client_payload.ref }}
14+
main_commit_sha: ${{ steps.get_sha.outputs.sha }}
15+
main_commit_author: ${{ steps.get_commit_info.outputs.author }}
16+
strategy:
17+
matrix:
18+
include:
19+
- image: teable-cloud-preview
20+
file: Dockerfile
21+
- image: teable-sandbox-cloud-preview
22+
file: Dockerfile.sandbox
23+
steps:
24+
- name: Record start time
25+
id: start_time
26+
run: echo "start=$(date +%s)" >> $GITHUB_OUTPUT
27+
28+
- name: Checkout private repository
29+
uses: actions/checkout@v4
30+
with:
31+
repository: teableio/teable-ee
32+
token: ${{ secrets.PACKAGES_KEY }}
33+
submodules: "true"
34+
ref: ${{ github.event.client_payload.ref }}
35+
36+
- name: Get teable-ee SHA
37+
id: get_sha
38+
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
39+
40+
- name: Get commit info
41+
id: get_commit_info
42+
run: |
43+
echo "author=$(git log -1 --pretty=format:'%an')" >> $GITHUB_OUTPUT
44+
45+
- name: Login to Ali container registry
46+
uses: docker/login-action@v3
47+
with:
48+
registry: registry.cn-shenzhen.aliyuncs.com
49+
username: ${{ vars.ALI_DOCKER_USERNAME }}
50+
password: ${{ secrets.ALI_DOCKER_PASSWORD }}
51+
52+
- name: Login to GitHub Container Registry
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.PACKAGES_KEY }}
58+
59+
- name: Configure AWS credentials
60+
uses: aws-actions/configure-aws-credentials@v4
61+
with:
62+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
63+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
64+
aws-region: us-west-2
65+
66+
- name: Login to AWS ECR
67+
uses: aws-actions/amazon-ecr-login@v2
68+
69+
- uses: actions/setup-node@v4
70+
with:
71+
node-version: 20.9.0
72+
- name: ⚙️ Install zx
73+
run: npm install -g zx
74+
75+
- name: ⚙️ Docker meta
76+
id: meta
77+
uses: docker/metadata-action@v5
78+
with:
79+
images: |
80+
registry.cn-shenzhen.aliyuncs.com/teable/${{ matrix.image }}
81+
ghcr.io/teableio/${{ matrix.image }}
82+
649941507946.dkr.ecr.us-west-2.amazonaws.com/teable/${{ matrix.image }}
83+
tags: |
84+
type=raw,value=alpha-pr-${{ github.event.client_payload.pr_number }}
85+
type=raw,value=${{ steps.get_sha.outputs.sha }}
86+
- name: ⚙️ Set up QEMU
87+
uses: docker/setup-qemu-action@v3
88+
89+
- name: 📦 Build and push
90+
run: |
91+
zx scripts/build-image.mjs --file=dockers/teable/${{ matrix.file }} \
92+
--build-arg="ENABLE_CSP=false" \
93+
--build-arg="NEXT_BUILD_ENV_EDITION=CLOUD" \
94+
--tag="${{ steps.meta.outputs.tags }}" \
95+
--platform="linux/amd64" \
96+
--push
97+
98+
deploy:
99+
needs: [build-push]
100+
runs-on: ubuntu-latest
101+
env:
102+
INSTANCE_NAME: pr-cloud-${{ github.event.client_payload.pr_number }}
103+
steps:
104+
- name: Checkout private repository
105+
uses: actions/checkout@v4
106+
with:
107+
repository: teableio/teable-ee
108+
token: ${{ secrets.PACKAGES_KEY }}
109+
submodules: "true"
110+
ref: ${{ github.event.client_payload.ref }}
111+
112+
- name: Get teable-ee SHA
113+
id: get_sha
114+
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
115+
116+
- name: Update deployment images
117+
uses: actions-hub/kubectl@master
118+
env:
119+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
120+
MAIN_IMAGE: registry.cn-shenzhen.aliyuncs.com/teable/teable-cloud-preview:${{ needs.build-push.outputs.main_commit_sha }}-amd64
121+
SANDBOX_IMAGE: registry.cn-shenzhen.aliyuncs.com/teable/teable-sandbox-cloud-preview:${{ needs.build-push.outputs.main_commit_sha }}-amd64
122+
with:
123+
args: set image deployment/teable-${{ env.INSTANCE_NAME }} teable=${{ env.MAIN_IMAGE }} teable-sandbox=${{ env.SANDBOX_IMAGE }}
124+
125+
- name: Rollout status
126+
uses: actions-hub/kubectl@master
127+
env:
128+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
129+
with:
130+
args: rollout status deployment/teable-${{ env.INSTANCE_NAME }} --timeout=300s
131+
132+
- name: Wait for application health check
133+
uses: actions-hub/kubectl@master
134+
env:
135+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
136+
with:
137+
args: exec deployment/teable-${{ env.INSTANCE_NAME }} -- curl -f --retry 30 --retry-delay 5 --retry-connrefused http://localhost:3000/health
138+
139+
- name: Create deployment status comment
140+
if: always()
141+
run: |
142+
SUCCESS="${{ job.status == 'success' }}"
143+
DOMAIN="pr-cloud-${{ github.event.client_payload.pr_number }}"
144+
URL="https://${DOMAIN}.sealoshzh.site"
145+
146+
if [ "$SUCCESS" = "true" ]; then
147+
STATUS="✅ Success"
148+
BODY="**Deployment Status: ${STATUS}** 🔗 Preview URL: ${URL}"
149+
else
150+
STATUS="❌ Failed"
151+
BODY="**Deployment Status: ${STATUS}**"
152+
fi
153+
154+
curl -X POST \
155+
-H "Authorization: token ${{ secrets.PACKAGES_KEY }}" \
156+
-H "Accept: application/vnd.github.v3+json" \
157+
"https://api.github.com/repos/teableio/teable-ee/issues/${{ github.event.client_payload.pr_number }}/comments" \
158+
-d "{\"body\":\"${BODY}\"}"

0 commit comments

Comments
 (0)