reconstruct dirs
This commit is contained in:
2
infra/.gitignore
vendored
Normal file
2
infra/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/bin/
|
||||
/node_modules/
|
10
infra/Pulumi.yaml
Normal file
10
infra/Pulumi.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: imbusy
|
||||
description: A task management app
|
||||
runtime:
|
||||
name: nodejs
|
||||
options:
|
||||
packagemanager: npm
|
||||
config:
|
||||
pulumi:tags:
|
||||
value:
|
||||
pulumi:template: typescript
|
15
infra/README.md
Normal file
15
infra/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
imbusy-infra
|
||||
====
|
||||
|
||||
pulumi infrastructure description in typescript
|
||||
|
||||
|
||||
## Commands
|
||||
|
||||
```bash
|
||||
# apply
|
||||
pulumi up
|
||||
|
||||
# destroy
|
||||
pulumi down
|
||||
```
|
8
infra/common.ts
Normal file
8
infra/common.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
|
||||
export const tags = {
|
||||
project: pulumi.getProject(),
|
||||
env: pulumi.getStack(),
|
||||
};
|
||||
|
||||
export const prefix = `${tags.project}-${tags.env}`;
|
83
infra/frontend.ts
Normal file
83
infra/frontend.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as aws from "@pulumi/aws";
|
||||
|
||||
import * as fg from "fast-glob";
|
||||
import * as fs from "fs/promises";
|
||||
import mime from "mime";
|
||||
|
||||
import * as common from "./common";
|
||||
|
||||
const tags = common.tags;
|
||||
const prefix = `${common.prefix}-frontend`;
|
||||
|
||||
// ---- infra resouces ----
|
||||
const bucket = new aws.s3.Bucket(`${prefix}-bucket`, {tags});
|
||||
|
||||
const oai = new aws.cloudfront.OriginAccessIdentity(`${prefix}-oai`);
|
||||
|
||||
const bucketPolicy = new aws.s3.BucketPolicy(`${prefix}-bucket-policy`, {
|
||||
bucket: bucket.bucket,
|
||||
policy: pulumi.all([oai.iamArn, bucket.bucket]).apply(([a, b]) => JSON.stringify({
|
||||
Version: "2012-10-17",
|
||||
Statement: [{
|
||||
Effect: "Allow",
|
||||
Principal: {
|
||||
AWS: a,
|
||||
},
|
||||
Action: ["s3:GetObject"],
|
||||
Resource: [`arn:aws:s3:::${b}/*`],
|
||||
}],
|
||||
})),
|
||||
});
|
||||
|
||||
export const cloudfront = new aws.cloudfront.Distribution(`${prefix}-cloudfront`, {
|
||||
tags,
|
||||
origins: [{
|
||||
domainName: bucket.bucketRegionalDomainName,
|
||||
originId: bucket.arn,
|
||||
s3OriginConfig: {
|
||||
originAccessIdentity: oai.cloudfrontAccessIdentityPath,
|
||||
},
|
||||
}],
|
||||
enabled: true,
|
||||
defaultRootObject: "index.html",
|
||||
defaultCacheBehavior: {
|
||||
targetOriginId: bucket.arn,
|
||||
viewerProtocolPolicy: "redirect-to-https",
|
||||
allowedMethods: ["GET", "HEAD", "OPTIONS"],
|
||||
cachedMethods: ["GET", "HEAD", "OPTIONS"],
|
||||
forwardedValues: {
|
||||
queryString: false,
|
||||
cookies: { forward: "none" },
|
||||
},
|
||||
},
|
||||
priceClass: "PriceClass_100",
|
||||
restrictions: {
|
||||
geoRestriction: {
|
||||
restrictionType: "none",
|
||||
},
|
||||
},
|
||||
viewerCertificate: {
|
||||
cloudfrontDefaultCertificate: true,
|
||||
},
|
||||
});
|
||||
|
||||
// ---- file uploads ----
|
||||
(async () => {
|
||||
const cwd = "../frontend/dist/";
|
||||
|
||||
const stats = await fs.stat(cwd);
|
||||
if (!stats.isDirectory()) {
|
||||
throw new Error("build the frontend firstly");
|
||||
}
|
||||
|
||||
const files = await fg("**/*", {cwd, dot: true});
|
||||
for (const file of files) {
|
||||
new aws.s3.BucketObject(file, {
|
||||
bucket: bucket,
|
||||
source: new pulumi.asset.FileAsset(cwd+file),
|
||||
contentType: mime.getType(file) || "application/octet-stream",
|
||||
key: file,
|
||||
});
|
||||
}
|
||||
})();
|
6
infra/index.ts
Normal file
6
infra/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as pulumi from "@pulumi/pulumi";
|
||||
import * as aws from "@pulumi/aws";
|
||||
|
||||
import * as frontend from "./frontend";
|
||||
|
||||
export const frontendDomain = frontend.cloudfront.domainName;
|
3662
infra/package-lock.json
generated
Normal file
3662
infra/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
infra/package.json
Normal file
14
infra/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "imbusy",
|
||||
"main": "index.ts",
|
||||
"devDependencies": {
|
||||
"@types/node": "^18",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pulumi/aws": "^6.82.2",
|
||||
"@pulumi/pulumi": "^3.113.0",
|
||||
"fast-glob": "^3.3.3",
|
||||
"mime": "^4.0.7"
|
||||
}
|
||||
}
|
18
infra/tsconfig.json
Normal file
18
infra/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"outDir": "bin",
|
||||
"target": "es2020",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"pretty": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user