-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathinfra.ngs
executable file
·62 lines (54 loc) · 3.2 KB
/
infra.ngs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ngs
{
# Due to incomplete AWS2 implementation, this script fails. Just run it again.
AWS = AWS2
DOMAIN = ENV.get('NGS_DOMAIN', 'ngs-lang.org')
BUCKET_NAME = "01.${DOMAIN}"
zone = AWS::Zone(Name=DOMAIN).converge()
cert = AWS::Certificate(DomainName=DOMAIN).converge().the_one()
dvo = cert.DomainValidationOptions.the_one()
assert(dvo.ValidationMethod == 'DNS')
rec = dvo.ResourceRecord
AWS::RecordSet(ZoneName=DOMAIN + '.', Name=rec.Name, Type=rec.Type).converge(ResourceRecords=[{"Value": rec.Value}], TTL=600)
bucket = AWS::Bucket(Name=BUCKET_NAME).converge()
if not($(ok:[0, 255] aws s3api get-bucket-website --bucket ${BUCKET_NAME})) {
bucket.resources[0].run("Setting website", %(aws s3 website "s3://${BUCKET_NAME}/" --index-document index.html --error-document error.html), false)
}
# $(top_level:: aws s3 sync --exclude '*.swp' --acl public-read ./ "s3://${BUCKET_NAME}/")
# not implemented # dist = AWS::Distribution(Tags={'Name': 'ngs-site'}).converge()
# aws cloudfront create-distribution --origin-domain-name s3.amazonaws.com
# Manual steps:
# * Create CloudFront distribution with origin s3.amazonaws.com/${BUCKET_NAME}
# * Create DNS alias for @
# * Create S3 buckets for REDIRECTS
REDIRECTS= [{id: "discord", host: "discord.gg", path: "6VqgcpM"},
{id: "videos", host: "m.youtube.com", path: "channel/UC6CL2J6syrV1mfFpxQd89gQ"},
{id: "source", host: "github.com", path: "ngs-lang/ngs"},
{id: "wiki", host: "github.com", path: "ngs-lang/ngs/wiki"},
{id: "ipython", host: "github.com", path: "ngs-lang/ngs-ipython-extension"},
{id: "docker", host: "hub.docker.com", path: "r/ngslang/ngs"},
{id: "brew", host: "formulae.brew.sh", path: "formula/ngs"}
{id: "snap", host: "snapcraft.io", path: "ngs"},
{id: "action", host: "github.com", path: "marketplace/actions/setup-ngs"},
{id: "manual", host: "ngs-lang.org", path: "doc/latest/index.html"},
{id: "ref", host: "ngs-lang.org", path: "doc/latest/generated/index.html"}]
REDIRECTS.each({
bucketName = "${A.id}.${DOMAIN}"
tmpbucket = AWS::Bucket(Name=bucketName).converge()
if not($(ok:[0, 255] aws s3api get-bucket-website --bucket ${bucketName})) {
tmpbucket.resources[0].run("Setting website", %(aws s3 website "s3://${bucketName}/" --index-document index.html --error-document error.html ), false)
}
})
# Manual steps:
# * Edit each S3 bucket that was created in the previous step and add `Redirection rules – optional` as
# [
# {
# "Redirect": {
# "HostName": "${REDIRECTS.host}",
# "ReplaceKeyPrefixWith": "${REDIRECTS.path}"
# }
# }
# ]
# * Create CloudFront distribution pointing to each s3 public address, with alternate domain name (cname) `${REDIRECTS.id}.${REDIRECTS.host}`, use only North America and Europe, with redirect http to http, create ssl cert, TLSv1.2_2018, HTTP/2, no Default root object
# * Create DNS alias for all addresses that points to each cloudfront address
}