Skip to content

Commit e4fb40f

Browse files
Zack Chasecnunciato
andauthored
Initial docs infrastructure (#42)
* Initial docs infrastructure * Use S3 website template instead * Remove infrastructure folder * Adjust pathing to use /sdk * Fix up baseURL, don't use the cache for docs * Bump deps, minor other things * Refactor to use Nx, fix Ruby formatter, run format * Add the docs:publish command to the README * Add a preview task * Actually add the project file * Publish to /docs/sdk/* --------- Co-authored-by: Christian Nunciato <chris@nunciato.org>
1 parent de33cba commit e4fb40f

23 files changed

+6940
-556
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ npm run format
195195
# Publish to npm, PyPi pkg.go.dev, and RubyGems.
196196
npm run publish
197197

198+
# Publish the docs to AWS.
199+
npm run docs:publish
200+
198201
# Clear away build and test artifacts.
199202
npm run clean
200203
```

infra/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/node_modules/

infra/Pulumi.dev.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
encryptionsalt: v1:e6xIDh3VRh0=:v1:uvEcWD8QmlguUQx4:o48Ij5bVvOeod2zeE+PyurjYXzd9lA==
2+
config:
3+
aws:region: us-west-2
4+
infra:errorDocument: error.html
5+
infra:indexDocument: index.html
6+
infra:path: ../dist/docs/publish

infra/Pulumi.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: infra
2+
description: A TypeScript program to deploy a static website on AWS
3+
runtime:
4+
name: nodejs
5+
options:
6+
packagemanager: npm
7+
config:
8+
pulumi:tags:
9+
value:
10+
pulumi:template: static-website-aws-typescript

infra/index.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import * as pulumi from "@pulumi/pulumi";
2+
import * as aws from "@pulumi/aws";
3+
import * as synced from "@pulumi/synced-folder";
4+
5+
const config = new pulumi.Config();
6+
const path = config.require("path");
7+
const indexDocument = config.require("indexDocument");
8+
const errorDocument = config.require("errorDocument");
9+
10+
// Create an S3 bucket to hold the docs.
11+
const bucket = new aws.s3.BucketV2("bucket");
12+
const bucketWebsite = new aws.s3.BucketWebsiteConfigurationV2(
13+
"bucket-website",
14+
{
15+
bucket: bucket.bucket,
16+
indexDocument: { suffix: indexDocument },
17+
errorDocument: { key: errorDocument },
18+
}
19+
);
20+
21+
// Configure ownership controls for the bucket.
22+
const ownershipControls = new aws.s3.BucketOwnershipControls(
23+
"ownership-controls",
24+
{
25+
bucket: bucket.bucket,
26+
rule: {
27+
objectOwnership: "ObjectWriter",
28+
},
29+
}
30+
);
31+
32+
// Configure a public access block for the bucket.
33+
const publicAccessBlock = new aws.s3.BucketPublicAccessBlock(
34+
"public-access-block",
35+
{
36+
bucket: bucket.bucket,
37+
blockPublicAcls: false,
38+
}
39+
);
40+
41+
// Use a synced folder to manage the files of the website.
42+
new synced.S3BucketFolder(
43+
"bucket-folder",
44+
{
45+
path: path,
46+
bucketName: bucket.bucket,
47+
acl: "public-read",
48+
managedObjects: false,
49+
},
50+
{ dependsOn: [ownershipControls, publicAccessBlock] }
51+
);
52+
53+
// Create a CloudFront CDN to distribute and cache the website.
54+
const tenMinutes = 60 * 10;
55+
const cdn = new aws.cloudfront.Distribution("cdn", {
56+
enabled: true,
57+
origins: [
58+
{
59+
originId: bucket.arn,
60+
domainName: bucketWebsite.websiteEndpoint,
61+
customOriginConfig: {
62+
originProtocolPolicy: "http-only",
63+
httpPort: 80,
64+
httpsPort: 443,
65+
originSslProtocols: ["TLSv1.2"],
66+
},
67+
},
68+
],
69+
defaultCacheBehavior: {
70+
targetOriginId: bucket.arn,
71+
viewerProtocolPolicy: "redirect-to-https",
72+
allowedMethods: ["GET", "HEAD", "OPTIONS"],
73+
cachedMethods: ["GET", "HEAD", "OPTIONS"],
74+
defaultTtl: tenMinutes,
75+
maxTtl: tenMinutes,
76+
minTtl: tenMinutes,
77+
forwardedValues: {
78+
queryString: false,
79+
cookies: {
80+
forward: "none",
81+
},
82+
},
83+
},
84+
customErrorResponses: [
85+
{
86+
errorCode: 404,
87+
responseCode: 404,
88+
responsePagePath: `/${errorDocument}`,
89+
},
90+
],
91+
restrictions: {
92+
geoRestriction: {
93+
restrictionType: "none",
94+
},
95+
},
96+
viewerCertificate: {
97+
cloudfrontDefaultCertificate: true,
98+
},
99+
});
100+
101+
// Export relevant URLs and hostnames.
102+
export const bucketName = bucket.bucket;
103+
export const bucketURI = pulumi.interpolate`s3://${bucket.bucket}`;
104+
export const originURL = pulumi.interpolate`http://${bucketWebsite.websiteEndpoint}`;
105+
export const originHostname = bucketWebsite.websiteEndpoint;
106+
export const cdnURL = pulumi.interpolate`https://${cdn.domainName}`;
107+
export const cdnHostname = cdn.domainName;
108+
export const typescriptDocsURL = pulumi.interpolate`https://${cdn.domainName}/docs/sdk/typescript`;
109+
export const pythonDocsURL = pulumi.interpolate`https://${cdn.domainName}/docs/sdk/python`;
110+
export const rubyDocsURL = pulumi.interpolate`https://${cdn.domainName}/docs/sdk/ruby`;

0 commit comments

Comments
 (0)