preview-cloud #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Preview Cloud PR | |
on: | |
repository_dispatch: | |
types: [preview-cloud] | |
jobs: | |
build-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- image: teable-cloud | |
file: Dockerfile | |
- image: teable-db-migrate-cloud | |
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=CLOUD" \ | |
--tag="${{ steps.meta.outputs.tags }}" \ | |
--platform="linux/amd64" \ | |
--push | |
deploy: | |
needs: [build-push] | |
runs-on: ubuntu-latest | |
env: | |
INSTANCE_NAME: pr-cloud-${{ github.event.client_payload.pr_number }} | |
INSTANCE_DOMAIN: pr-cloud-${{ github.event.client_payload.pr_number }} | |
DISPLAY_NAME: "teable-pr-cloud-${{ 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-cloud | |
DB_MIGRATE_IMAGE_REPOSITORY: registry.cn-shenzhen.aliyuncs.com/teable/teable-db-migrate-cloud | |
IMAGE_TAG: ${{ steps.get_sha.outputs.sha }}-amd64 | |
run: | | |
cp .github/workflows/templates/preview-template.yaml 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-cloud-${{ github.event.client_payload.pr_number }}" | |
URL="https://${DOMAIN}.sealosgzg.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}\"}" |