2023-08-29 13:07:05 +03:00
|
|
|
name: Deploy
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
flavor:
|
2023-12-21 10:58:16 +03:00
|
|
|
description: 'Select what enverionment to deploy to'
|
|
|
|
type: choice
|
2023-08-29 13:07:05 +03:00
|
|
|
default: canary
|
2023-12-21 10:58:16 +03:00
|
|
|
options:
|
|
|
|
- canary
|
|
|
|
- beta
|
|
|
|
- stable
|
|
|
|
- internal
|
2023-08-29 13:07:05 +03:00
|
|
|
env:
|
|
|
|
APP_NAME: affine
|
|
|
|
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-server:
|
|
|
|
name: Build Server
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-09-29 06:02:26 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-12-21 10:58:16 +03:00
|
|
|
- name: Setup Version
|
2023-12-21 13:00:12 +03:00
|
|
|
id: version
|
2023-12-21 10:58:16 +03:00
|
|
|
uses: ./.github/actions/setup-version
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Setup Node.js
|
|
|
|
uses: ./.github/actions/setup-node
|
|
|
|
with:
|
|
|
|
electron-install: false
|
2024-01-10 11:35:21 +03:00
|
|
|
extra-flags: workspaces focus @affine/server
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Build Server
|
|
|
|
run: yarn workspace @affine/server build
|
|
|
|
- name: Upload server dist
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
name: server-dist
|
2023-10-18 18:30:08 +03:00
|
|
|
path: ./packages/backend/server/dist
|
2023-08-29 13:07:05 +03:00
|
|
|
if-no-files-found: error
|
|
|
|
build-core:
|
|
|
|
name: Build @affine/core
|
|
|
|
runs-on: ubuntu-latest
|
2023-12-01 10:25:08 +03:00
|
|
|
environment: ${{ github.event.inputs.flavor }}
|
2023-08-29 13:07:05 +03:00
|
|
|
steps:
|
2023-09-29 06:02:26 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-12-21 10:58:16 +03:00
|
|
|
- name: Setup Version
|
2023-12-21 13:00:12 +03:00
|
|
|
id: version
|
2023-12-21 10:58:16 +03:00
|
|
|
uses: ./.github/actions/setup-version
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Setup Node.js
|
|
|
|
uses: ./.github/actions/setup-node
|
|
|
|
- name: Build Core
|
2023-11-28 09:59:50 +03:00
|
|
|
run: yarn nx build @affine/core --skip-nx-cache
|
2023-08-29 13:07:05 +03:00
|
|
|
env:
|
|
|
|
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
|
|
|
|
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
|
|
|
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
2023-11-28 09:59:48 +03:00
|
|
|
BUILD_TYPE: ${{ github.event.inputs.flavor }}
|
2023-08-29 13:07:05 +03:00
|
|
|
SHOULD_REPORT_TRACE: true
|
|
|
|
TRACE_REPORT_ENDPOINT: ${{ secrets.TRACE_REPORT_ENDPOINT }}
|
2023-10-18 11:06:07 +03:00
|
|
|
CAPTCHA_SITE_KEY: ${{ secrets.CAPTCHA_SITE_KEY }}
|
2023-12-01 10:25:08 +03:00
|
|
|
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
|
|
|
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
|
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
|
|
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
2024-01-10 11:35:21 +03:00
|
|
|
PERFSEE_TOKEN: ${{ secrets.PERFSEE_TOKEN }}
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Upload core artifact
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
name: core
|
2023-10-18 18:30:08 +03:00
|
|
|
path: ./packages/frontend/core/dist
|
2023-08-29 13:07:05 +03:00
|
|
|
if-no-files-found: error
|
|
|
|
|
2024-01-10 11:35:21 +03:00
|
|
|
build-core-selfhost:
|
2024-02-22 17:56:25 +03:00
|
|
|
name: Build @affine/core selfhost
|
2023-08-29 13:07:05 +03:00
|
|
|
runs-on: ubuntu-latest
|
2024-01-10 11:35:21 +03:00
|
|
|
environment: ${{ github.event.inputs.flavor }}
|
2023-08-29 13:07:05 +03:00
|
|
|
steps:
|
2023-09-29 06:02:26 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-12-21 10:58:16 +03:00
|
|
|
- name: Setup Version
|
2023-12-21 13:00:12 +03:00
|
|
|
id: version
|
2023-12-21 10:58:16 +03:00
|
|
|
uses: ./.github/actions/setup-version
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Setup Node.js
|
|
|
|
uses: ./.github/actions/setup-node
|
2024-01-10 11:35:21 +03:00
|
|
|
- name: Build Core
|
|
|
|
run: yarn nx build @affine/core --skip-nx-cache
|
|
|
|
env:
|
|
|
|
BUILD_TYPE: ${{ github.event.inputs.flavor }}
|
|
|
|
SHOULD_REPORT_TRACE: false
|
|
|
|
PUBLIC_PATH: '/'
|
2024-03-06 08:42:56 +03:00
|
|
|
SELF_HOSTED: true
|
2024-01-10 11:35:21 +03:00
|
|
|
- name: Download selfhost fonts
|
|
|
|
run: node ./scripts/download-blocksuite-fonts.mjs
|
|
|
|
- name: Upload core artifact
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
2024-01-10 11:35:21 +03:00
|
|
|
name: selfhost-core
|
|
|
|
path: ./packages/frontend/core/dist
|
2023-08-29 13:07:05 +03:00
|
|
|
if-no-files-found: error
|
|
|
|
|
2024-01-10 11:35:21 +03:00
|
|
|
build-storage:
|
|
|
|
name: Build Storage - ${{ matrix.targets.name }}
|
2023-10-19 11:59:02 +03:00
|
|
|
runs-on: ubuntu-latest
|
2024-01-10 11:35:21 +03:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
targets:
|
|
|
|
- name: x86_64-unknown-linux-gnu
|
|
|
|
file: storage.node
|
|
|
|
- name: aarch64-unknown-linux-gnu
|
|
|
|
file: storage.arm64.node
|
|
|
|
- name: armv7-unknown-linux-gnueabihf
|
|
|
|
file: storage.armv7.node
|
2023-10-19 11:59:02 +03:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
2023-12-21 10:58:16 +03:00
|
|
|
- name: Setup Version
|
2023-12-21 13:00:12 +03:00
|
|
|
id: version
|
2023-12-21 10:58:16 +03:00
|
|
|
uses: ./.github/actions/setup-version
|
2023-10-19 11:59:02 +03:00
|
|
|
- name: Setup Node.js
|
|
|
|
uses: ./.github/actions/setup-node
|
2024-01-10 11:35:21 +03:00
|
|
|
with:
|
|
|
|
electron-install: false
|
|
|
|
extra-flags: workspaces focus @affine/storage
|
2023-12-08 09:39:16 +03:00
|
|
|
- name: Build Rust
|
2023-10-19 11:59:02 +03:00
|
|
|
uses: ./.github/actions/build-rust
|
|
|
|
with:
|
2024-01-10 11:35:21 +03:00
|
|
|
target: ${{ matrix.targets.name }}
|
2023-10-19 11:59:02 +03:00
|
|
|
package: '@affine/storage'
|
|
|
|
nx_token: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
|
2024-01-10 11:35:21 +03:00
|
|
|
- name: Upload ${{ matrix.targets.file }}
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/upload-artifact@v4
|
2023-10-19 11:59:02 +03:00
|
|
|
with:
|
2024-01-10 11:35:21 +03:00
|
|
|
name: ${{ matrix.targets.file }}
|
2023-10-19 11:59:02 +03:00
|
|
|
path: ./packages/backend/storage/storage.node
|
|
|
|
if-no-files-found: error
|
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
build-docker:
|
|
|
|
name: Build Docker
|
|
|
|
runs-on: ubuntu-latest
|
2024-03-06 13:14:22 +03:00
|
|
|
permissions:
|
|
|
|
contents: 'write'
|
|
|
|
id-token: 'write'
|
|
|
|
packages: 'write'
|
2023-08-29 13:07:05 +03:00
|
|
|
needs:
|
|
|
|
- build-server
|
|
|
|
- build-core
|
2024-01-10 11:35:21 +03:00
|
|
|
- build-core-selfhost
|
2023-08-29 13:07:05 +03:00
|
|
|
- build-storage
|
|
|
|
steps:
|
2023-09-29 06:02:26 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Download core artifact
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/download-artifact@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
name: core
|
2023-10-18 18:30:08 +03:00
|
|
|
path: ./packages/frontend/core/dist
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Download server dist
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/download-artifact@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
name: server-dist
|
2023-10-18 18:30:08 +03:00
|
|
|
path: ./packages/backend/server/dist
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Download storage.node
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/download-artifact@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
name: storage.node
|
2023-10-18 18:30:08 +03:00
|
|
|
path: ./packages/backend/server
|
2023-10-19 11:59:02 +03:00
|
|
|
- name: Download storage.node arm64
|
2023-12-26 15:40:10 +03:00
|
|
|
uses: actions/download-artifact@v4
|
2023-10-19 11:59:02 +03:00
|
|
|
with:
|
|
|
|
name: storage.arm64.node
|
|
|
|
path: ./packages/backend/storage
|
2024-01-10 11:35:21 +03:00
|
|
|
- name: Download storage.node arm64
|
|
|
|
uses: actions/download-artifact@v4
|
|
|
|
with:
|
|
|
|
name: storage.armv7.node
|
|
|
|
path: .
|
|
|
|
- name: move storage files
|
|
|
|
run: |
|
|
|
|
mv ./packages/backend/storage/storage.node ./packages/backend/server/storage.arm64.node
|
|
|
|
mv storage.node ./packages/backend/server/storage.armv7.node
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Setup env
|
|
|
|
run: |
|
|
|
|
echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
|
|
|
|
if [ -z "${{ inputs.flavor }}" ]
|
|
|
|
then
|
|
|
|
echo "RELEASE_FLAVOR=canary" >> "$GITHUB_ENV"
|
|
|
|
else
|
|
|
|
echo "RELEASE_FLAVOR=${{ inputs.flavor }}" >> "$GITHUB_ENV"
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Login to GitHub Container Registry
|
2023-10-24 12:01:09 +03:00
|
|
|
uses: docker/login-action@v3
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
logout: false
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up QEMU
|
2023-10-24 08:13:58 +03:00
|
|
|
uses: docker/setup-qemu-action@v3
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Set up Docker Buildx
|
2023-10-23 10:22:34 +03:00
|
|
|
uses: docker/setup-buildx-action@v3
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Build front Dockerfile
|
2023-10-23 10:23:04 +03:00
|
|
|
uses: docker/build-push-action@v5
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
push: true
|
|
|
|
pull: true
|
|
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
provenance: true
|
|
|
|
file: .github/deployment/front/Dockerfile
|
|
|
|
tags: ghcr.io/toeverything/affine-front:${{env.RELEASE_FLAVOR}}-${{ env.GIT_SHORT_HASH }},ghcr.io/toeverything/affine-front:${{env.RELEASE_FLAVOR}}
|
|
|
|
|
|
|
|
# setup node without cache configuration
|
|
|
|
# Prisma cache is not compatible with docker build cache
|
|
|
|
- name: Setup Node.js
|
2023-10-24 08:59:16 +03:00
|
|
|
uses: actions/setup-node@v4
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
registry-url: https://npm.pkg.github.com
|
|
|
|
scope: '@toeverything'
|
|
|
|
|
2024-01-10 11:35:21 +03:00
|
|
|
- name: Remove core dist
|
|
|
|
run: rm -rf ./packages/frontend/core/dist
|
|
|
|
|
|
|
|
- name: Download selfhost core artifact
|
|
|
|
uses: actions/download-artifact@v4
|
|
|
|
with:
|
|
|
|
name: selfhost-core
|
|
|
|
path: ./packages/frontend/core/dist
|
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
- name: Install Node.js dependencies
|
2023-10-19 11:59:02 +03:00
|
|
|
run: |
|
2024-01-10 11:35:21 +03:00
|
|
|
yarn config set --json supportedArchitectures.cpu '["x64", "arm64", "arm"]'
|
|
|
|
yarn config set --json supportedArchitectures.libc '["glibc"]'
|
2023-10-19 11:59:02 +03:00
|
|
|
yarn workspaces focus @affine/server --production
|
2023-08-29 13:07:05 +03:00
|
|
|
|
|
|
|
- name: Generate Prisma client
|
|
|
|
run: yarn workspace @affine/server prisma generate
|
|
|
|
|
|
|
|
- name: Build graphql Dockerfile
|
2023-10-23 10:23:04 +03:00
|
|
|
uses: docker/build-push-action@v5
|
2023-08-29 13:07:05 +03:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
push: true
|
|
|
|
pull: true
|
2024-01-10 11:35:21 +03:00
|
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
2023-08-29 13:07:05 +03:00
|
|
|
provenance: true
|
|
|
|
file: .github/deployment/node/Dockerfile
|
2023-10-19 11:59:02 +03:00
|
|
|
tags: ghcr.io/toeverything/affine-graphql:${{env.RELEASE_FLAVOR}}-${{ env.GIT_SHORT_HASH }},ghcr.io/toeverything/affine-graphql:${{env.RELEASE_FLAVOR}}
|
2023-08-29 13:07:05 +03:00
|
|
|
|
|
|
|
deploy:
|
|
|
|
name: Deploy to cluster
|
2023-11-01 10:38:15 +03:00
|
|
|
if: ${{ github.event_name == 'workflow_dispatch' }}
|
2023-08-29 13:07:05 +03:00
|
|
|
environment: ${{ github.event.inputs.flavor }}
|
|
|
|
permissions:
|
|
|
|
contents: 'write'
|
|
|
|
id-token: 'write'
|
|
|
|
needs:
|
|
|
|
- build-docker
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-09-29 06:02:26 +03:00
|
|
|
- uses: actions/checkout@v4
|
2023-12-21 10:58:16 +03:00
|
|
|
- name: Setup Version
|
2023-12-21 13:00:12 +03:00
|
|
|
id: version
|
2023-12-21 10:58:16 +03:00
|
|
|
uses: ./.github/actions/setup-version
|
2023-11-28 09:59:48 +03:00
|
|
|
- name: Deploy to ${{ github.event.inputs.flavor }}
|
2023-08-29 13:07:05 +03:00
|
|
|
uses: ./.github/actions/deploy
|
|
|
|
with:
|
|
|
|
build-type: ${{ github.event.inputs.flavor }}
|
|
|
|
gcp-project-number: ${{ secrets.GCP_PROJECT_NUMBER }}
|
|
|
|
gcp-project-id: ${{ secrets.GCP_PROJECT_ID }}
|
|
|
|
service-account: ${{ secrets.GCP_HELM_DEPLOY_SERVICE_ACCOUNT }}
|
|
|
|
cluster-name: ${{ secrets.GCP_CLUSTER_NAME }}
|
|
|
|
cluster-location: ${{ secrets.GCP_CLUSTER_LOCATION }}
|
|
|
|
env:
|
2023-12-08 08:53:23 +03:00
|
|
|
APP_VERSION: ${{ steps.version.outputs.APP_VERSION }}
|
2023-08-29 13:07:05 +03:00
|
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
|
|
CANARY_DEPLOY_HOST: ${{ secrets.CANARY_DEPLOY_HOST }}
|
|
|
|
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
|
|
|
|
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
|
|
|
|
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
|
2023-10-18 11:06:07 +03:00
|
|
|
ENABLE_CAPTCHA: true
|
|
|
|
CAPTCHA_TURNSTILE_SECRET: ${{ secrets.CAPTCHA_TURNSTILE_SECRET }}
|
2024-02-19 17:37:08 +03:00
|
|
|
MAILER_SENDER: ${{ secrets.OAUTH_EMAIL_SENDER }}
|
|
|
|
MAILER_USER: ${{ secrets.OAUTH_EMAIL_LOGIN }}
|
|
|
|
MAILER_PASSWORD: ${{ secrets.OAUTH_EMAIL_PASSWORD }}
|
2023-08-29 13:07:05 +03:00
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
AFFINE_GOOGLE_CLIENT_ID: ${{ secrets.AFFINE_GOOGLE_CLIENT_ID }}
|
|
|
|
AFFINE_GOOGLE_CLIENT_SECRET: ${{ secrets.AFFINE_GOOGLE_CLIENT_SECRET }}
|
|
|
|
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
|
|
|
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }}
|
|
|
|
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
|
|
|
|
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
|
|
|
|
GCLOUD_CONNECTION_NAME: ${{ secrets.GCLOUD_CONNECTION_NAME }}
|
|
|
|
GCLOUD_CLOUD_SQL_INTERNAL_ENDPOINT: ${{ secrets.GCLOUD_CLOUD_SQL_INTERNAL_ENDPOINT }}
|
|
|
|
REDIS_HOST: ${{ secrets.REDIS_HOST }}
|
|
|
|
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
|
|
|
|
CLOUD_SQL_IAM_ACCOUNT: ${{ secrets.CLOUD_SQL_IAM_ACCOUNT }}
|
2023-10-30 19:12:17 +03:00
|
|
|
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
|
|
|
|
STRIPE_WEBHOOK_KEY: ${{ secrets.STRIPE_WEBHOOK_KEY }}
|
2023-12-15 16:28:12 +03:00
|
|
|
STATIC_IP_NAME: ${{ secrets.STATIC_IP_NAME }}
|