Skip to content

Commit 803699e

Browse files
authored
Merge pull request #14767 from milzi234/master
Publish Docs to Netlify and AWS
2 parents 374a7d3 + 24dae30 commit 803699e

23 files changed

+10063
-42
lines changed

.github/actions/spell-check/expect.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ Darron
263263
dataformat
264264
datatracker
265265
Daugaard
266+
davidmillerskt
266267
Davids
268+
davidtmiller
267269
Dayneko
268270
dbfile
269271
dblacka
@@ -481,6 +483,7 @@ geobackend
481483
geoipbackend
482484
geolocated
483485
Georgeto
486+
getbootstrap
484487
Gergely
485488
Gerritsen
486489
Gervai
@@ -608,6 +611,7 @@ ipencrypt
608611
ipfilter
609612
IPSECKEY
610613
iputils
614+
ironsummitmedia
611615
isane
612616
ismaster
613617
isoc
@@ -777,6 +781,7 @@ mbed
777781
mbedtls
778782
MBOXFW
779783
mbytes
784+
mdo
780785
Meerwald
781786
Mekking
782787
melpa
@@ -1309,6 +1314,7 @@ sshfp
13091314
ssi
13101315
SSQ
13111316
stacksize
1317+
startbootstrap
13121318
starttransaction
13131319
Stasic
13141320
statbag
@@ -1388,6 +1394,7 @@ Thessalonikefs
13881394
Thiago
13891395
thinko
13901396
Thomassen
1397+
Thorton
13911398
threadmessage
13921399
throttlemap
13931400
thrysoee

.github/actions/spell-check/patterns.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,6 @@ DoH
183183

184184
# scrypt / argon
185185
\$(?:scrypt|argon\d+[di]*)\$\S+
186+
187+
# Twitter status
188+
\btwitter\.com/[^/\s"')]*(?:/status/\d+(?:\?[-_0-9a-zA-Z&=]*|)|)

.github/scripts/publish.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
2+
const { CloudFrontClient, CreateInvalidationCommand } = require("@aws-sdk/client-cloudfront");
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
// Configure AWS SDK
7+
const s3Client = new S3Client({ region: process.env.AWS_REGION });
8+
const cloudFrontClient = new CloudFrontClient({ region: process.env.AWS_REGION });
9+
10+
async function uploadToS3(bucketName, sourceDir, destDir = '') {
11+
const files = fs.readdirSync(sourceDir);
12+
13+
for (const file of files) {
14+
const filePath = path.join(sourceDir, file);
15+
const key = path.join(destDir, file);
16+
17+
if (fs.statSync(filePath).isDirectory()) {
18+
await uploadToS3(bucketName, filePath, key);
19+
} else {
20+
const fileContent = fs.readFileSync(filePath);
21+
const command = new PutObjectCommand({
22+
Bucket: bucketName,
23+
Key: key,
24+
Body: fileContent,
25+
ContentType: getContentType(file),
26+
});
27+
await s3Client.send(command);
28+
}
29+
}
30+
}
31+
32+
function getContentType(filename) {
33+
const ext = path.extname(filename).toLowerCase();
34+
switch (ext) {
35+
case '.html': return 'text/html';
36+
case '.css': return 'text/css';
37+
case '.js': return 'application/javascript';
38+
case '.json': return 'application/json';
39+
case '.png': return 'image/png';
40+
case '.jpg': case '.jpeg': return 'image/jpeg';
41+
default: return 'application/octet-stream';
42+
}
43+
}
44+
45+
async function invalidateCloudFront(distributionId, paths) {
46+
const command = new CreateInvalidationCommand({
47+
DistributionId: distributionId,
48+
InvalidationBatch: {
49+
CallerReference: Date.now().toString(),
50+
Paths: {
51+
Quantity: paths.length,
52+
Items: paths,
53+
},
54+
},
55+
});
56+
await cloudFrontClient.send(command);
57+
}
58+
59+
async function publishToSite(site, sourceDir, targetDir = '') {
60+
const bucketName = process.env.AWS_S3_BUCKET_DOCS;
61+
let distributionId, siteDir;
62+
63+
if (site === 'dnsdist.org') {
64+
distributionId = process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID_DNSDIST;
65+
siteDir = 'dnsdist.org';
66+
} else if (site === 'docs.powerdns.com') {
67+
distributionId = process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID_DOCS;
68+
siteDir = 'docs.powerdns.com';
69+
} else {
70+
throw new Error('Invalid site specified');
71+
}
72+
73+
const fullTargetDir = path.join(siteDir, targetDir);
74+
await uploadToS3(bucketName, sourceDir, fullTargetDir);
75+
76+
// Invalidate CloudFront cache
77+
await invalidateCloudFront(distributionId, ['/*']);
78+
79+
console.log(`Published from ${sourceDir} to ${site}${targetDir ? '/' + targetDir : ''}`);
80+
}
81+
82+
async function main() {
83+
const args = process.argv.slice(2);
84+
if (args[0] === 'publish') {
85+
if (args.length < 3 || args.length > 4) {
86+
console.log('Usage: node publish.js publish <SITE> <SOURCE_DIR> [TARGET_DIR]');
87+
return;
88+
}
89+
const [, site, sourceDir, targetDir] = args;
90+
await publishToSite(site, sourceDir, targetDir);
91+
} else {
92+
console.log('Usage: node publish.js publish <SITE> <SOURCE_DIR> [TARGET_DIR]');
93+
}
94+
}
95+
96+
main().catch(console.error);

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,4 @@ jobs:
279279
uses: actions/checkout@v4
280280
with:
281281
fetch-depth: 2
282-
- run: if [[ "$(file -i --dereference $(git diff --name-only HEAD^..HEAD -- . :^fuzzing/corpus) | grep binary | grep -v 'image/' | grep -v 'inode/x-empty' | grep -v 'inode/directory' | grep -v '^modules/tinydnsbackend/data.cdb' | tee /dev/stderr)" != "" ]]; then exit 1; fi
282+
- run: if [[ "$(file -i --dereference $(git diff --name-only HEAD^..HEAD -- . :^fuzzing/corpus) | grep binary | grep -v 'image/' | grep -v 'inode/x-empty' | grep -v 'inode/directory' | grep -v '^website/docs.powerdns.com/website/fonts/' | grep -v '^website/docs.powerdns.com/website/img/' | grep -v '^modules/tinydnsbackend/data.cdb' | tee /dev/stderr)" != "" ]]; then exit 1; fi

0 commit comments

Comments
 (0)