Skip to content

Commit 8ee9757

Browse files
authored
v2: cleanup deployment to Cloudflare (#2937)
1 parent 946a463 commit 8ee9757

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

.github/composite/deploy-cloudflare/action.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ inputs:
1010
environment:
1111
description: 'Environment to deploy to'
1212
required: true
13+
deploy:
14+
description: 'Deploy as main version for all traffic instead of uploading versions'
15+
required: true
1316
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY:
1417
description: 'Next server actions encryption key'
1518
required: true
1619
GITBOOK_URL:
1720
description: 'GitBook URL'
1821
required: true
22+
GITBOOK_SECRET:
23+
description: 'GitBook secret'
24+
required: true
1925
GITBOOK_APP_URL:
2026
description: 'GitBook app URL'
2127
required: false
@@ -60,6 +66,7 @@ runs:
6066
env:
6167
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ inputs.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
6268
GITBOOK_URL: ${{ inputs.GITBOOK_URL }}
69+
GITBOOK_SECRET: ${{ inputs.GITBOOK_SECRET }}
6370
GITBOOK_APP_URL: ${{ inputs.GITBOOK_APP_URL }}
6471
GITBOOK_API_URL: ${{ inputs.GITBOOK_API_URL }}
6572
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.GITBOOK_INTEGRATIONS_HOST }}
@@ -77,7 +84,7 @@ runs:
7784
workingDirectory: ./
7885
wranglerVersion: '3.112.0'
7986
environment: ${{ inputs.environment }}
80-
command: ${{ inputs.environment == 'production' && 'deploy' || 'versions upload' }} --config ./packages/gitbook-v2/wrangler.toml
87+
command: ${{ inputs.deploy && 'deploy' || 'versions upload' }} --config ./packages/gitbook-v2/wrangler.toml
8188
- name: Outputs
8289
shell: bash
8390
env:

.github/workflows/deploy-preview.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
uses: ./.github/composite/deploy-cloudflare
104104
with:
105105
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
106+
deploy: ${{ github.ref == 'refs/heads/main' }}
106107
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
107108
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
108109
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
@@ -111,13 +112,14 @@ jobs:
111112
GITBOOK_IMAGE_RESIZE_URL: ${{ vars.GITBOOK_IMAGE_RESIZE_URL }}
112113
GITBOOK_ICONS_URL: ${{ vars.GITBOOK_ICONS_URL }}
113114
GITBOOK_ICONS_TOKEN: ${{ vars.GITBOOK_ICONS_TOKEN }}
115+
GITBOOK_SECRET: ${{ github.ref == 'refs/heads/main' && secrets.PRODUCTION_GITBOOK_SECRET|| '' }}
114116
- name: Outputs
115117
run: |
116118
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
117119
comment-deployments:
118120
runs-on: ubuntu-latest
119121
name: Comment Deployments (preview)
120-
if: always()
122+
if: always() && !startsWith(github.ref, 'refs/heads/main')
121123
needs:
122124
- deploy-v1-cloudflare
123125
- deploy-v2-vercel

.github/workflows/deploy-staging.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ jobs:
3535
uses: ./.github/composite/deploy-cloudflare
3636
with:
3737
environment: staging
38+
deploy: true
3839
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
3940
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
4041
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
4142
GITBOOK_URL: ${{ vars.STAGING_2C_GITBOOK_URL }}
43+
GITBOOK_SECRET: ${{ secrets.STAGING_GITBOOK_SECRET }}
4244
GITBOOK_APP_URL: https://app.gitbook-staging.com
4345
GITBOOK_API_URL: https://api.gitbook-staging.com
4446
GITBOOK_INTEGRATIONS_HOST: https://integrations.gitbook-staging.com

packages/gitbook-v2/next.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ const nextConfig = {
1111
env: {
1212
BUILD_VERSION: (process.env.GITHUB_SHA ?? '').slice(0, 7),
1313
GITBOOK_URL: process.env.GITBOOK_URL,
14+
GITBOOK_SECRET: process.env.GITBOOK_SECRET,
15+
GITBOOK_API_URL: process.env.GITBOOK_API_URL,
16+
GITBOOK_APP_URL: process.env.GITBOOK_APP_URL,
17+
GITBOOK_INTEGRATIONS_HOST: process.env.GITBOOK_INTEGRATIONS_HOST,
18+
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
19+
GITBOOK_IMAGE_RESIZE_URL: process.env.GITBOOK_IMAGE_RESIZE_URL,
1420
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
1521
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
1622
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,

packages/gitbook-v2/wrangler.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ d1_databases = [
1414
]
1515

1616
[env.staging]
17+
routes = [
18+
{ pattern = "open-2c.gitbook-staging.com/*", zone_name = "gitbook-staging.com" },
19+
{ pattern = "static-2c.gitbook-staging.com/*", zone_name = "gitbook-staging.com" }
20+
]
1721
kv_namespaces = [
1822
{ binding = "NEXT_CACHE_WORKERS_KV", id = "a446e25f12b741afb185f1e5b4474f0a" } # gitbook-open-v2-cache-staging
1923
]
@@ -22,6 +26,10 @@ d1_databases = [
2226
]
2327

2428
[env.production]
29+
routes = [
30+
{ pattern = "open-2c.gitbook.com/*", zone_name = "gitbook.com" },
31+
{ pattern = "static-2c.gitbook.com/*", zone_name = "gitbook.com" }
32+
]
2533
kv_namespaces = [
2634
{ binding = "NEXT_CACHE_WORKERS_KV", id = "72379746280d4e79acf24440eea950dc" } # gitbook-open-v2-cache-production
2735
]

0 commit comments

Comments
 (0)