-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (124 loc) · 4.9 KB
/
manual-preview-ee.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
name: Preview EE PR
on:
repository_dispatch:
types: [preview-ee]
jobs:
build-push:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- image: teable-ee
file: Dockerfile
- image: teable-db-migrate-ee
file: Dockerfile.db-migrate
steps:
- name: Checkout private repository
uses: actions/checkout@v4
with:
repository: teableio/teable-ee
token: ${{ secrets.PACKAGES_KEY }}
submodules: 'true'
ref: ${{ github.event.client_payload.ref }}
- name: Get teable-ee SHA
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Login to Ali container registry
uses: docker/login-action@v3
with:
registry: registry.cn-shenzhen.aliyuncs.com
username: ${{ vars.ALI_DOCKER_USERNAME }}
password: ${{ secrets.ALI_DOCKER_PASSWORD }}
- uses: actions/setup-node@v4
with:
node-version: 20.9.0
- name: ⚙️ Install zx
run: npm install -g zx
- name: ⚙️ Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
registry.cn-shenzhen.aliyuncs.com/teable/${{ matrix.image }}
tags: |
type=raw,value=alpha-pr-${{ github.event.client_payload.pr_number }}
type=raw,value=${{ steps.get_sha.outputs.sha }}
- name: ⚙️ Set up QEMU
uses: docker/setup-qemu-action@v3
- name: 📦 Build and push
run: |
zx scripts/build-image.mjs --file=dockers/teable/${{ matrix.file }} \
--build-arg="ENABLE_CSP=false" \
--build-arg="NEXT_BUILD_ENV_EDITION=EE" \
--tag="${{ steps.meta.outputs.tags }}" \
--platform="linux/amd64" \
--push
deploy:
needs: [build-push]
runs-on: ubuntu-latest
env:
NAMESPACE: 38puz7wo
INSTANCE_NAME: pr-ee-${{ github.event.client_payload.pr_number }}
INSTANCE_DOMAIN: pr-ee-${{ github.event.client_payload.pr_number }}
DISPLAY_NAME: "teable-pr-ee-${{ github.event.client_payload.pr_number }}"
steps:
- name: Checkout private repository
uses: actions/checkout@v4
with:
repository: teableio/teable-ee
token: ${{ secrets.PACKAGES_KEY }}
submodules: 'true'
ref: ${{ github.event.client_payload.ref }}
- name: Get teable-ee SHA
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Create deployment YAML
env:
MAIN_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-ee
DB_MIGRATE_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-db-migrate-ee
IMAGE_TAG: ${{ steps.get_sha.outputs.sha }}-amd64
run: |
cp .github/workflows/templates/preview-template.yaml deploy.yaml
sed -i "s#__NAMESPACE__#${{ env.NAMESPACE }}#g" deploy.yaml
sed -i "s#__INSTANCE_NAME__#${{ env.INSTANCE_NAME }}#g" deploy.yaml
sed -i "s#__INSTANCE_DOMAIN__#${{ env.INSTANCE_DOMAIN }}#g" deploy.yaml
sed -i "s#__MAIN_IMAGE_REPOSITORY__#${{ env.MAIN_IMAGE_REPOSITORY }}#g" deploy.yaml
sed -i "s#__DB_MIGRATE_IMAGE_REPOSITORY__#${{ env.DB_MIGRATE_IMAGE_REPOSITORY }}#g" deploy.yaml
sed -i "s#__IMAGE_TAG__#${{ env.IMAGE_TAG }}#g" deploy.yaml
sed -i "s#__DISPLAY_NAME__#${{ env.DISPLAY_NAME }}#g" deploy.yaml
- name: Apply deploy job
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: apply -f deploy.yaml
- name: Rollout status
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout status deployment/teable-${{ env.INSTANCE_NAME }} --timeout=300s
- name: Wait for application health check
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: exec deployment/teable-${{ env.INSTANCE_NAME }} -- curl -f --retry 30 --retry-delay 5 --retry-connrefused http://localhost:3000/health
- name: Create deployment status comment
if: always()
run: |
SUCCESS="${{ job.status == 'success' }}"
DOMAIN="pr-ee-${{ github.event.client_payload.pr_number }}"
URL="https://${DOMAIN}.sealoshzh.site"
if [ "$SUCCESS" = "true" ]; then
STATUS="✅ Success"
BODY="**Deployment Status: ${STATUS}** 🔗 Preview URL: ${URL}"
else
STATUS="❌ Failed"
BODY="**Deployment Status: ${STATUS}**"
fi
curl -X POST \
-H "Authorization: token ${{ secrets.PACKAGES_KEY }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/teableio/teable-ee/issues/${{ github.event.client_payload.pr_number }}/comments" \
-d "{\"body\":\"${BODY}\"}"