Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Docs to Netlify and AWS #14767

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ Darron
dataformat
datatracker
Daugaard
davidmillerskt
Davids
davidtmiller
Dayneko
dbfile
dblacka
Expand Down Expand Up @@ -481,6 +483,7 @@ geobackend
geoipbackend
geolocated
Georgeto
getbootstrap
Gergely
Gerritsen
Gervai
Expand Down Expand Up @@ -608,6 +611,7 @@ ipencrypt
ipfilter
IPSECKEY
iputils
ironsummitmedia
isane
ismaster
isoc
Expand Down Expand Up @@ -777,6 +781,7 @@ mbed
mbedtls
MBOXFW
mbytes
mdo
Meerwald
Mekking
melpa
Expand Down Expand Up @@ -1308,6 +1313,7 @@ sshfp
ssi
SSQ
stacksize
startbootstrap
starttransaction
Stasic
statbag
Expand Down Expand Up @@ -1387,6 +1393,7 @@ Thessalonikefs
Thiago
thinko
Thomassen
Thorton
threadmessage
throttlemap
thrysoee
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/spell-check/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,6 @@ DoH

# scrypt / argon
\$(?:scrypt|argon\d+[di]*)\$\S+

# Twitter status
\btwitter\.com/[^/\s"')]*(?:/status/\d+(?:\?[-_0-9a-zA-Z&=]*|)|)
96 changes: 96 additions & 0 deletions .github/scripts/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const { CloudFrontClient, CreateInvalidationCommand } = require("@aws-sdk/client-cloudfront");
const fs = require('fs');
const path = require('path');

// Configure AWS SDK
const s3Client = new S3Client({ region: process.env.AWS_REGION });
const cloudFrontClient = new CloudFrontClient({ region: process.env.AWS_REGION });

async function uploadToS3(bucketName, sourceDir, destDir = '') {
const files = fs.readdirSync(sourceDir);

for (const file of files) {
const filePath = path.join(sourceDir, file);
const key = path.join(destDir, file);

if (fs.statSync(filePath).isDirectory()) {
await uploadToS3(bucketName, filePath, key);
} else {
const fileContent = fs.readFileSync(filePath);
const command = new PutObjectCommand({
Bucket: bucketName,
Key: key,
Body: fileContent,
ContentType: getContentType(file),
});
await s3Client.send(command);
}
}
}

function getContentType(filename) {
const ext = path.extname(filename).toLowerCase();
switch (ext) {
case '.html': return 'text/html';
case '.css': return 'text/css';
case '.js': return 'application/javascript';
case '.json': return 'application/json';
case '.png': return 'image/png';
case '.jpg': case '.jpeg': return 'image/jpeg';
default: return 'application/octet-stream';
}
}

async function invalidateCloudFront(distributionId, paths) {
const command = new CreateInvalidationCommand({
DistributionId: distributionId,
InvalidationBatch: {
CallerReference: Date.now().toString(),
Paths: {
Quantity: paths.length,
Items: paths,
},
},
});
await cloudFrontClient.send(command);
}

async function publishToSite(site, sourceDir, targetDir = '') {
const bucketName = process.env.AWS_S3_BUCKET_DOCS;
let distributionId, siteDir;

if (site === 'dnsdist.org') {
distributionId = process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID_DNSDIST;
siteDir = 'dnsdist.org';
} else if (site === 'docs.powerdns.com') {
distributionId = process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID_DOCS;
siteDir = 'docs.powerdns.com';
} else {
throw new Error('Invalid site specified');
}

const fullTargetDir = path.join(siteDir, targetDir);
await uploadToS3(bucketName, sourceDir, fullTargetDir);

// Invalidate CloudFront cache
await invalidateCloudFront(distributionId, ['/*']);

console.log(`Published from ${sourceDir} to ${site}${targetDir ? '/' + targetDir : ''}`);
}

async function main() {
const args = process.argv.slice(2);
if (args[0] === 'publish') {
if (args.length < 3 || args.length > 4) {
console.log('Usage: node publish.js publish <SITE> <SOURCE_DIR> [TARGET_DIR]');
return;
}
const [, site, sourceDir, targetDir] = args;
await publishToSite(site, sourceDir, targetDir);
} else {
console.log('Usage: node publish.js publish <SITE> <SOURCE_DIR> [TARGET_DIR]');
}
}

main().catch(console.error);
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 2
- 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
- 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
Loading