Skip to content

Commit d4aa846

Browse files
authored
Merge pull request #426 from flashcatcloud/feat/ai-sre
Feat/ai sre
2 parents 7f3abde + e0f1994 commit d4aa846

4 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎.github/workflows/upload.yml‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
# MEILI_ENDPOINT - Meilisearch instance URL
1313
# MEILI_API_KEY - API key with documents read/write permission
1414
# MEILI_INDEX - Target index name
15-
# Repository secrets for the tarball: CDN_ACCESS_KEY, CDN_SECRET_KEY,
16-
# CDN_BUCKET, CDN_REGION, CDN_ENDPOINT.
15+
# Branch mapping for the Meilisearch sync: main -> production,
16+
# test -> development.
1717
#
18-
# Branch mapping: main -> production (https://docs-cdn.flashcat.cloud/docs/),
19-
# test -> development (https://docs-cdn.flashcat.cloud/test/docs/)
18+
# The tarball is published from main only, to the Flashduty static
19+
# distribution: https://static.flashcat.cloud/flashduty-docs/flashduty-docs.tar.gz
20+
# (OSS bucket flashduty-public). Every deployment reads that one copy.
21+
# Repository secrets for it: STATIC_ACCESS_KEY, STATIC_SECRET_KEY (an AK allowed
22+
# to put objects under flashduty-public/flashduty-docs/).
2023

2124
name: Publish docs for AI search
2225

@@ -74,12 +77,12 @@ jobs:
7477
bash ./scripts/upload.sh
7578
7679
bundle:
80+
if: github.ref == 'refs/heads/main'
7781
runs-on: ubuntu-latest
78-
environment: ${{ github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'development') }}
7982
# Every run uploads the whole tarball, so a newer run supersedes an older
8083
# one; cancelling the older keeps it from finishing last with stale docs.
8184
concurrency:
82-
group: docs-bundle-${{ github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'development') }}
85+
group: docs-bundle
8386
cancel-in-progress: true
8487
steps:
8588
- name: Checkout
@@ -101,11 +104,11 @@ jobs:
101104
- name: Build and upload docs bundle
102105
working-directory: integration-docs
103106
env:
104-
CDN_ACCESS_KEY: ${{ secrets.CDN_ACCESS_KEY }}
105-
CDN_SECRET_KEY: ${{ secrets.CDN_SECRET_KEY }}
106-
CDN_BUCKET: ${{ secrets.CDN_BUCKET }}
107-
CDN_REGION: ${{ secrets.CDN_REGION }}
108-
CDN_ENDPOINT: ${{ secrets.CDN_ENDPOINT }}
109-
CDN_URL: 'https://docs-cdn.flashcat.cloud'
110-
CDN_DIR: ${{ (github.event.inputs.environment || (github.ref == 'refs/heads/main' && 'production' || 'development')) == 'production' && '/docs' || '/test/docs' }}
107+
CDN_ACCESS_KEY: ${{ secrets.STATIC_ACCESS_KEY }}
108+
CDN_SECRET_KEY: ${{ secrets.STATIC_SECRET_KEY }}
109+
CDN_BUCKET: 'flashduty-public'
110+
CDN_REGION: 'oss-cn-beijing'
111+
CDN_ENDPOINT: 'oss-cn-beijing.aliyuncs.com'
112+
CDN_URL: 'https://static.flashcat.cloud'
113+
CDN_DIR: '/flashduty-docs'
111114
run: npm run upload:docs-bundle

‎integration-docs/scripts/oss-cdn.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Shared OSS upload + CDN refresh helpers for the docs-cdn publishing scripts
1+
// Shared OSS upload + CDN refresh helpers for the publishing scripts
22
// (upload-openapi.mjs, upload-docs-bundle.mjs). All of them read the same
3-
// CDN_* secrets and publish under CDN_URL + CDN_DIR.
3+
// CDN_* env vars, publish under CDN_URL + CDN_DIR and refresh the CDN copy of
4+
// what they upload.
45

56
export const requiredEnv = [
67
'CDN_ACCESS_KEY',

‎integration-docs/scripts/upload-docs-bundle.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export function buildOssFilePath(cdnDir) {
2525
// ~3 MB tarball has taken 5.5 minutes to reach OSS (~9 KB/s).
2626
const TAR_UPLOAD_TIMEOUT_MS = 30 * 60 * 1000;
2727

28+
// The static CDN caches by its own path TTL, not this Cache-Control, so
29+
// uploadDocsBundle refreshes the tarball URL after every upload.
2830
function buildTarUploadOptions() {
2931
return {
3032
timeout: TAR_UPLOAD_TIMEOUT_MS,

‎integration-docs/scripts/upload-docs-bundle.test.mjs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ test('uploadDocsBundle uploads the tarball with gzip headers and refreshes the C
4343
const env = {
4444
CDN_ACCESS_KEY: 'access-key',
4545
CDN_SECRET_KEY: 'secret-key',
46-
CDN_BUCKET: 'bucket',
47-
CDN_REGION: 'oss-cn-hangzhou',
48-
CDN_ENDPOINT: 'bucket.oss-cn-hangzhou.aliyuncs.com',
49-
CDN_URL: 'https://docs-cdn.flashcat.cloud',
50-
CDN_DIR: '/docs'
46+
CDN_BUCKET: 'flashduty-public',
47+
CDN_REGION: 'oss-cn-beijing',
48+
CDN_ENDPOINT: 'oss-cn-beijing.aliyuncs.com',
49+
CDN_URL: 'https://static.flashcat.cloud',
50+
CDN_DIR: '/flashduty-docs'
5151
};
5252

5353
const uploaded = [];
5454
const refreshed = [];
5555
const ossClient = {
5656
async put(ossFilePath, localFilePath, options) {
5757
uploaded.push({ ossFilePath, localFilePath, options });
58-
return { url: `https://bucket.oss-cn-hangzhou.aliyuncs.com${ossFilePath}` };
58+
return { url: `https://flashduty-public.oss-cn-beijing.aliyuncs.com${ossFilePath}` };
5959
}
6060
};
6161
const cdnRuntime = {
@@ -69,11 +69,11 @@ test('uploadDocsBundle uploads the tarball with gzip headers and refreshes the C
6969

7070
const cdnUrl = await uploadDocsBundle({ tarPath, env, ossClient, cdnRuntime });
7171

72-
assert.equal(cdnUrl, 'https://docs-cdn.flashcat.cloud/docs/flashduty-docs.tar.gz');
73-
assert.deepEqual(uploaded.map((item) => item.ossFilePath), ['/docs/flashduty-docs.tar.gz']);
72+
assert.equal(cdnUrl, 'https://static.flashcat.cloud/flashduty-docs/flashduty-docs.tar.gz');
73+
assert.deepEqual(uploaded.map((item) => item.ossFilePath), ['/flashduty-docs/flashduty-docs.tar.gz']);
7474
assert.equal(uploaded[0].localFilePath, tarPath);
7575
assert.equal(uploaded[0].options.headers['Content-Type'], 'application/gzip');
7676
assert.equal(uploaded[0].options.headers['Cache-Control'], 'public, max-age=300');
7777
assert.equal(uploaded[0].options.timeout, 30 * 60 * 1000);
78-
assert.deepEqual(refreshed, ['https://docs-cdn.flashcat.cloud/docs/flashduty-docs.tar.gz']);
78+
assert.deepEqual(refreshed, ['https://static.flashcat.cloud/flashduty-docs/flashduty-docs.tar.gz']);
7979
});

0 commit comments

Comments
 (0)