mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
8fb6d7465f
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
138 lines
6.0 KiB
YAML
138 lines
6.0 KiB
YAML
name: 'Deploy cloudflare'
|
|
description: 'Deploy GitBook to Cloudflare'
|
|
inputs:
|
|
opItem:
|
|
description: '1Password item to load secrets from'
|
|
required: true
|
|
opServiceAccount:
|
|
description: '1Password service account token'
|
|
required: true
|
|
apiToken:
|
|
description: 'Cloudflare API token'
|
|
required: true
|
|
accountId:
|
|
description: 'Cloudflare account ID'
|
|
required: true
|
|
environment:
|
|
description: 'Cloudflare environment to deploy to (staging, production, preview)'
|
|
required: true
|
|
deploy:
|
|
description: 'Deploy as main version for all traffic instead of uploading versions'
|
|
required: true
|
|
commitTag:
|
|
description: 'Commit branch to associate with the deployment'
|
|
required: true
|
|
commitMessage:
|
|
description: 'Commit message to associate with the deployment'
|
|
required: true
|
|
outputs:
|
|
deployment-url:
|
|
description: "Deployment URL"
|
|
value: ${{ steps.upload_middleware.outputs.deployment-url }}
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
shell: bash
|
|
env:
|
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
|
- name: Load secret
|
|
uses: 1password/load-secrets-action@v2
|
|
env:
|
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ inputs.opServiceAccount }}
|
|
GITBOOK_URL: ${{ inputs.opItem }}/GITBOOK_URL
|
|
GITBOOK_ICONS_URL: ${{ inputs.opItem }}/GITBOOK_ICONS_URL
|
|
GITBOOK_ICONS_TOKEN: ${{ inputs.opItem }}/GITBOOK_ICONS_TOKEN
|
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ inputs.opItem }}/NEXT_SERVER_ACTIONS_ENCRYPTION_KEY
|
|
GITBOOK_SECRET: ${{ inputs.opItem }}/GITBOOK_SECRET
|
|
GITBOOK_APP_URL: ${{ inputs.opItem }}/GITBOOK_APP_URL
|
|
GITBOOK_API_URL: ${{ inputs.opItem }}/GITBOOK_API_URL
|
|
GITBOOK_API_PUBLIC_URL: ${{ inputs.opItem }}/GITBOOK_API_PUBLIC_URL
|
|
GITBOOK_API_TOKEN: ${{ inputs.opItem }}/GITBOOK_API_TOKEN
|
|
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
|
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
|
GITBOOK_IMAGE_RESIZE_MODE: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_MODE
|
|
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
|
GITBOOK_FONTS_URL: ${{ inputs.opItem }}/GITBOOK_FONTS_URL
|
|
- name: Build worker
|
|
run: bun run turbo build:cloudflare
|
|
env:
|
|
GITBOOK_RUNTIME: cloudflare
|
|
shell: bash
|
|
|
|
- name: Upload the DO worker
|
|
uses: cloudflare/wrangler-action@v3.14.0
|
|
with:
|
|
apiToken: ${{ inputs.apiToken }}
|
|
accountId: ${{ inputs.accountId }}
|
|
workingDirectory: ./
|
|
wranglerVersion: '4.10.0'
|
|
environment: ${{ inputs.environment }}
|
|
command: deploy --config ./packages/gitbook/openNext/customWorkers/doWrangler.jsonc
|
|
|
|
- id: upload_server
|
|
name: Upload server to Cloudflare
|
|
uses: cloudflare/wrangler-action@v3.14.0
|
|
with:
|
|
apiToken: ${{ inputs.apiToken }}
|
|
accountId: ${{ inputs.accountId }}
|
|
workingDirectory: ./
|
|
wranglerVersion: '4.10.0'
|
|
environment: ${{ inputs.environment }}
|
|
command: ${{ format('versions upload --tag {0} --message "{1}"', inputs.commitTag, inputs.commitMessage) }} --config ./packages/gitbook/openNext/customWorkers/defaultWrangler.jsonc
|
|
|
|
- name: Extract server version worker ID
|
|
shell: bash
|
|
id: extract_server_version_id
|
|
run: |
|
|
version_id=$(echo '${{ steps.upload_server.outputs.command-output }}' | grep "Worker Version ID" | awk '{print $4}')
|
|
echo "version_id=$version_id" >> $GITHUB_OUTPUT
|
|
|
|
- name: Run updateWrangler scripts
|
|
shell: bash
|
|
run: |
|
|
bun run ./packages/gitbook/openNext/customWorkers/script/updateWrangler.ts ${{ steps.extract_server_version_id.outputs.version_id }}
|
|
|
|
- id: upload_middleware
|
|
name: Upload middleware to Cloudflare
|
|
uses: cloudflare/wrangler-action@v3.14.0
|
|
with:
|
|
apiToken: ${{ inputs.apiToken }}
|
|
accountId: ${{ inputs.accountId }}
|
|
workingDirectory: ./
|
|
wranglerVersion: '4.10.0'
|
|
environment: ${{ inputs.environment }}
|
|
command: ${{ format('versions upload --tag {0} --message "{1}"', inputs.commitTag, inputs.commitMessage) }} --config ./packages/gitbook/openNext/customWorkers/middlewareWrangler.jsonc
|
|
|
|
- name: Extract middleware version worker ID
|
|
shell: bash
|
|
id: extract_middleware_version_id
|
|
run: |
|
|
version_id=$(echo '${{ steps.upload_middleware.outputs.command-output }}' | grep "Worker Version ID" | awk '{print $4}')
|
|
echo "version_id=$version_id" >> $GITHUB_OUTPUT
|
|
|
|
- name: Deploy server and middleware to Cloudflare
|
|
if: ${{ inputs.deploy == 'true' }}
|
|
uses: ./.github/actions/gradual-deploy-cloudflare
|
|
with:
|
|
apiToken: ${{ inputs.apiToken }}
|
|
accountId: ${{ inputs.accountId }}
|
|
opServiceAccount: ${{ inputs.opServiceAccount }}
|
|
opItem: ${{ inputs.opItem }}
|
|
environment: ${{ inputs.environment }}
|
|
serverVersionId: ${{ steps.extract_server_version_id.outputs.version_id }}
|
|
middlewareVersionId: ${{ steps.extract_middleware_version_id.outputs.version_id }}
|
|
deploy: ${{ inputs.deploy }}
|
|
|
|
|
|
- name: Outputs
|
|
shell: bash
|
|
env:
|
|
DEPLOYMENT_URL: ${{ steps.upload_middleware.outputs.deployment-url }}
|
|
run: |
|
|
echo "URL: ${{ steps.upload_middleware.outputs.deployment-url }}"
|
|
echo "Output server: ${{ steps.upload_server.outputs.command-output }}" |