Skip to content

build-cloud

build-cloud #25

name: Build teable cloud
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
repository_dispatch:
types: [build-cloud]
jobs:
build-push:
runs-on: ubuntu-latest
strategy:
matrix:
target: [app, db-migrate]
include:
- target: app
file: Dockerfile
image: teable-cloud
- target: db-migrate
file: Dockerfile.db-migrate
image: teable-db-migrate-cloud
steps:
- name: Checkout private repository
uses: actions/checkout@v4
with:
repository: teableio/teable-ee
token: ${{ secrets.PACKAGES_KEY }}
submodules: 'true'
- name: Get teable-ee SHA
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Login to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGES_KEY }}
- name: Login to Docker Hub registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_HUB_NAME }}
password: ${{ secrets.DOCKER_HUB_AK }}
- 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=latest
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
steps:
- name: Checkout private repository
uses: actions/checkout@v4
with:
repository: teableio/teable-ee
token: ${{ secrets.PACKAGES_KEY }}
submodules: 'true'
- name: Get teable-ee SHA
id: get_sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Create Job YAML
run: |
cat <<EOF > migration-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: teable-migration-${{ steps.get_sha.outputs.sha }}
labels:
cloud.sealos.io/deploy-on-sealos: teable
spec:
completions: 1
template:
metadata:
name: teable-cloud-teable
spec:
restartPolicy: Never
imagePullSecrets:
- name: teable
containers:
- name: teable
image: "registry.cn-shenzhen.aliyuncs.com/teable/teable-db-migrate-cloud:${{ steps.get_sha.outputs.sha }}-amd64"
imagePullPolicy: Always
env:
- name: "PRISMA_DATABASE_URL"
value: "${{ secrets.PRISMA_DATABASE_URL }}"
resources:
limits:
memory: 512Mi
cpu: 500m
requests:
cpu: 100m
backoffLimit: 0
ttlSecondsAfterFinished: 300
EOF
- name: Apply migration job
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: apply -f migration-job.yaml
- name: Wait for migration job to complete
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: wait --for=condition=complete job/teable-migration-${{ steps.get_sha.outputs.sha }} --timeout=600s
- name: Update application deployment
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: set image deployment/teable teable=registry.cn-shenzhen.aliyuncs.com/teable/teable-cloud:${{ steps.get_sha.outputs.sha }}-amd64
- name: Update deployment annotations
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: annotate deployment/teable originImageName="registry.cn-shenzhen.aliyuncs.com/teable/teable-cloud:${{ steps.get_sha.outputs.sha }}-amd64" --overwrite
- name: Rollout status
uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: rollout status deployment/teable