-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QoL update: pulumi + readme + harbor
- Loading branch information
1 parent
864564d
commit 68c6246
Showing
8 changed files
with
219 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
{ | ||
"name": "@project-templates/cloud", | ||
"version": "2023.6.8", | ||
"version": "1.0.0", | ||
"main": "src/index.ts", | ||
"eslintConfig": { | ||
"extends": "@bn-digital/eslint-config/typescript" | ||
}, | ||
"scripts": { | ||
"pulumi": "pulumi", | ||
"test": "pulumi up --policy-pack=tests", | ||
"provision": "yarn pulumi up --yes" | ||
"provision": "pulumi up --non-interactive --stack=production --yes" | ||
}, | ||
"dependencies": { | ||
"@bn-digital/pulumi": "1.7.51", | ||
"@pulumi/pulumi": "3.69.x" | ||
"@pulumi/digitalocean": "^4.17.0", | ||
"@pulumi/kubernetes": "^3.23.1", | ||
"@pulumi/pulumi": "^3.62.0", | ||
"@pulumi/vault": "^5.8.0", | ||
"dotenv": "^16.0.3" | ||
}, | ||
"devDependencies": { | ||
"@bn-digital/typescript-config": "^1.3.6", | ||
"@pulumi/policy": "^1.5.0" | ||
"@bn-digital/typescript-config": "^1.3.1", | ||
"@types/node": "^18.15.11", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { | ||
Cdn, | ||
Certificate, | ||
DnsRecord, | ||
Domain, | ||
DropletSlug, | ||
KubernetesCluster, | ||
Project, | ||
Region, | ||
SpacesBucket, | ||
SpacesBucketPolicy, | ||
getKubernetesVersions, | ||
CdnArgs, | ||
DnsRecordArgs, | ||
DomainArgs, | ||
KubernetesClusterArgs, | ||
ProjectArgs, | ||
SpacesBucketArgs, | ||
} from "@pulumi/digitalocean" | ||
import { Config, Input, Output } from "@pulumi/pulumi" | ||
|
||
const config = new Config() | ||
const name = config.name | ||
const { | ||
region, | ||
domain: dns = "", | ||
cdn = false, | ||
} = config.requireObject<{ region: Region; cdn?: boolean; domain?: string }>("digitalocean") | ||
const environment = "production" | ||
const tags = ["provisioner:pulumi", `environment:${environment}`, `app:${name}`] | ||
|
||
type ResourceID = "provider" | "cluster" | "storage" | "cdn" | "dns" | "project" | "certificate" | "policy" | ||
|
||
function urn(resource: ResourceID, ...tags: string[]) { | ||
return [["bn", name, environment].join(":"), [resource as string].concat(tags).filter(Boolean).join(":")].join("/") | ||
} | ||
|
||
function getCmsPolicy(bucket: string | Input<string>) { | ||
return { | ||
Version: "2012-10-17", | ||
Statement: [ | ||
{ | ||
Sid: "CmsPublicAccess", | ||
Effect: "Allow", | ||
Action: ["s3:PutObject", "s3:GetObject", "s3:ListBucket", "s3:DeleteObject", "s3:PutObjectAcl"], | ||
Resource: [`arn:aws:s3:::${bucket}`, `arn:aws:s3:::${bucket}/*`], | ||
}, | ||
], | ||
} | ||
} | ||
|
||
/** | ||
* Create a DigitalOcean Spaces bucket required for CMS uploads and assets | ||
* @param {Domain} domain | ||
*/ | ||
function createBucket(domain?: string): SpacesBucket { | ||
const bucket = new SpacesBucket( | ||
urn("storage", "cms"), | ||
{ | ||
acl: "public-read", | ||
name: `${name}-cms`, | ||
region, | ||
versioning: { enabled: false }, | ||
forceDestroy: true, | ||
}, | ||
{ ignoreChanges: ["name", "region"] as (keyof SpacesBucketArgs)[] } | ||
) | ||
new SpacesBucketPolicy( | ||
urn("storage", "cms", "policy"), | ||
{ policy: JSON.stringify(getCmsPolicy(`${name}-cms`)), region, bucket: `${name}-cms` }, | ||
{ | ||
dependsOn: [bucket], | ||
} | ||
) | ||
if (cdn) { | ||
const cdnRecord = new DnsRecord( | ||
urn("storage", "cms", "cdn", "dns"), | ||
{ type: "CNAME", name: "cdn", value: bucket.bucketDomainName.apply(fqdn => `${fqdn}.`), domain: dns }, | ||
{ | ||
ignoreChanges: [] as (keyof DnsRecordArgs)[], | ||
} | ||
) | ||
const certificate = new Certificate( | ||
urn("storage", "cms", "cdn", "certificate"), | ||
{ | ||
domains: [`cdn.${dns}`], | ||
name, | ||
type: "lets_encrypt", | ||
}, | ||
{ ignoreChanges: ["name"] as (keyof DomainArgs)[], dependsOn: [cdnRecord] } | ||
) | ||
new Cdn( | ||
urn("storage", "cms", "cdn"), | ||
{ | ||
origin: bucket.bucketDomainName, | ||
customDomain: cdnRecord.fqdn, | ||
certificateName: certificate.name, | ||
}, | ||
{ ignoreChanges: [] as (keyof CdnArgs)[], dependsOn: [certificate, cdnRecord, bucket] } | ||
) | ||
} | ||
|
||
return bucket | ||
} | ||
|
||
function createDomain(name: string): Domain { | ||
return new Domain(urn("dns"), { | ||
name, | ||
}) | ||
} | ||
|
||
/** | ||
* @param name | ||
* @param version | ||
*/ | ||
function createCluster(name: string, version: string): KubernetesCluster { | ||
return new KubernetesCluster( | ||
urn("cluster"), | ||
{ | ||
ha: false, | ||
surgeUpgrade: true, | ||
autoUpgrade: false, | ||
name, | ||
nodePool: { | ||
name: "production", | ||
size: DropletSlug.DropletS2VCPU4GB_INTEL, | ||
minNodes: 1, | ||
maxNodes: 2, | ||
autoScale: true, | ||
}, | ||
region, | ||
version, | ||
tags, | ||
}, | ||
{ ignoreChanges: ["name", "version", "region"] as (keyof KubernetesClusterArgs)[] } | ||
) | ||
} | ||
|
||
function createProject(resources: Output<string>[]): Project { | ||
return new Project( | ||
urn("project"), | ||
{ | ||
environment, | ||
name, | ||
purpose: "Web Application", | ||
resources, | ||
}, | ||
{ ignoreChanges: [] as (keyof ProjectArgs)[] } | ||
) | ||
} | ||
|
||
export async function run() { | ||
const name = config.name | ||
const version = await getKubernetesVersions().then(versions => versions.latestVersion) | ||
const cluster = createCluster(name, version) | ||
const resources = [cluster.clusterUrn] | ||
let domain = undefined | ||
if (dns) { | ||
domain = createDomain(dns) | ||
resources.push(domain.domainUrn) | ||
} | ||
const bucket = domain?.name.apply(createBucket) || createBucket() | ||
resources.push(bucket.bucketUrn) | ||
return createProject(resources) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { configure, providers, stacks } from "@bn-digital/pulumi" | ||
import { Config } from "@pulumi/pulumi" | ||
import "./types" | ||
import { config } from "dotenv" | ||
|
||
const spec = new Config("project").requireObject<ConfigSpec>("spec") | ||
import { run } from "./digitalocean" | ||
|
||
configure(spec).cloud(stacks.digitalocean.CloudNativeWebApp).deploy(providers.helm.WebAppDeployment).release() | ||
config() | ||
|
||
run().then() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ declare global { | |
type ConfigSpec = stacks.InfrastructureConfig & providers.helm.AppConfig | ||
} | ||
|
||
export {} | ||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
{ | ||
"extends": "@bn-digital/typescript-config/pulumi", | ||
"extends": "@bn-digital/typescript-config/pulumi.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "bin", | ||
"lib": ["esnext", "dom"] | ||
"esModuleInterop": true, | ||
"outDir": "build", | ||
"noEmit": true, | ||
"target": "ESNext", | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["./src", "./package.json"] | ||
"include": ["src", "./package.json"] | ||
} |