This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: boostrap, synthesize and parametrize (#3)
* WIP synthesize and parametrize * chore: add bootstrap code and documentation * chore: more changes * chore: revert naming
- Loading branch information
Showing
10 changed files
with
1,708 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
# Dev cluster on AWS via AWS CDK and Cloudformation | ||
|
||
## Steps to build and publish | ||
|
||
``` | ||
rm -rf cdk.out | ||
rm -rf cdk.out | ||
npx cdk synth | ||
AWS_REGION=eu-central-1 npx cdk-assets publish -p cdk.out/garden-dev-cluster.assets.json | ||
rain fmt cdk.out/garden-dev-cluster.template.json > test.yaml | ||
``` | ||
|
||
|
||
## Inputs | ||
|
||
* domain e.g. dev.marketplace.sys.garden | ||
* hosted zone id | ||
``` | ||
aws route53 list-hosted-zones-by-name --dns-name dev.marketplace.sys.garden | ||
``` | ||
* user arns or role arn to add to the aws-auth configmap | ||
* user arns or role arn to add to the aws-auth configmap | ||
|
||
|
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,2 @@ | ||
venv/ | ||
virtualenv/ |
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,25 @@ | ||
# About boostrap | ||
|
||
For the serverless functions and other assets, we need an S3 bucket in all regions to work around the limitation described here: | ||
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-s3bucket | ||
|
||
This creates a public S3 bucket named `garden-cfn-public-<region>` in every region. | ||
|
||
This only needs to be executed once. | ||
|
||
# Bucket directory structure | ||
|
||
- `garden-cfn-public-<region>/` | ||
- `dev-cluster/`: Files related to the dev-cluster CDK stack | ||
- `x.x.x/`: semver release directory | ||
- `<hash>.{json,zip}`: cdk asset created by synth | ||
- `dev-cluster-quickstart.yaml`: CloudFormation stack synthesized from CDK code | ||
|
||
# How to run | ||
|
||
``` | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip3 install boto3 | ||
python3 bootstrap.py | ||
``` |
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,46 @@ | ||
""" | ||
MIT Licensed | ||
Copyright (c) 2021 superwerker | ||
https://github.com/superwerker/superwerker/blob/078231a/cdk/cdk-bootstrap.py | ||
""" | ||
import boto3 | ||
from boto3.session import Session | ||
import subprocess | ||
import os | ||
|
||
class DeployError(Exception): | ||
pass | ||
|
||
cfn = boto3.client("cloudformation") | ||
s = Session() | ||
regions = [ | ||
"ap-northeast-1", | ||
"ap-northeast-2", | ||
"ap-south-1", | ||
"ap-southeast-1", | ||
"ap-southeast-2", | ||
"ca-central-1", | ||
"eu-central-1", | ||
"eu-north-1", | ||
"eu-west-1", | ||
"eu-west-2", | ||
"eu-west-3", | ||
"sa-east-1", | ||
"us-east-1", | ||
"us-east-2", | ||
"us-west-2" | ||
] | ||
|
||
template_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bootstrap.yaml") | ||
for region in regions: | ||
cmd = ["aws", "cloudformation", "deploy", | ||
"--stack-name", "garden-marketplace-assets-bootstrap", | ||
"--region", region, | ||
"--template-file", template_file, | ||
] | ||
print("Deploying to region={0} with cmd={1}".format(region, cmd)) | ||
p = subprocess.run(cmd, capture_output=True) | ||
if p.returncode != 0: | ||
raise DeployError(p.stderr) | ||
print(p.stdout) |
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,36 @@ | ||
# MIT Licensed | ||
# Copyright (c) 2021 superwerker | ||
# https://github.com/superwerker/superwerker/blob/b05f55e/cdk/cdk-bootstrap.yaml | ||
Resources: | ||
BootStrapBucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: !Sub 'garden-cfn-public-${AWS::Region}' | ||
PublicAccessBlockConfiguration: | ||
# Ignore ACLs as we do not need them. Do not fail if a tool sets ACLs. | ||
BlockPublicAcls: true | ||
IgnorePublicAcls: true | ||
# We want a public policy for GET requests (see below) | ||
BlockPublicPolicy: false | ||
RestrictPublicBuckets: false | ||
UpdateReplacePolicy: Retain | ||
DeletionPolicy: Retain | ||
BootStrapBucketPolicy: | ||
Type: AWS::S3::BucketPolicy | ||
Properties: | ||
Bucket: | ||
Ref: BootStrapBucket | ||
PolicyDocument: | ||
Statement: | ||
- Action: s3:GetObject | ||
Effect: Allow | ||
Principal: | ||
AWS: "*" | ||
Resource: | ||
Fn::Join: | ||
- "" | ||
- - Fn::GetAtt: | ||
- BootStrapBucket | ||
- Arn | ||
- /* | ||
Version: "2012-10-17" |
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 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,11 +1,27 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import { logger } from "@aws-quickstart/eks-blueprints/dist/utils"; | ||
import { HelmAddOn } from "@aws-quickstart/eks-blueprints"; | ||
import DevCluster from "./cluster"; | ||
import { DevClusterConstruct } from "./cluster"; | ||
|
||
const releaseVersion = process.env["CDK_RELEASE_VERSION"] | ||
|
||
let defaultStackSynthesizer: cdk.IReusableStackSynthesizer | undefined | ||
|
||
// if this is being synthesized during the release process, we want to use our public S3 buckets. | ||
// otherwise (by default) you can just use the CDK deploy command to test the stack, e.g. for testing | ||
if (releaseVersion) { | ||
defaultStackSynthesizer = new cdk.CliCredentialsStackSynthesizer({ | ||
// see also boostrap/README.md for more information about the nature of these S3 buckets | ||
fileAssetsBucketName: 'garden-cfn-public-${AWS::Region}', | ||
bucketPrefix: `dev-cluster/${releaseVersion}`, | ||
}) | ||
} | ||
|
||
const app = new cdk.App({ defaultStackSynthesizer }); | ||
|
||
const app = new cdk.App(); | ||
HelmAddOn.validateHelmVersions = false; | ||
|
||
new DevCluster().eksCluster(app, `dev-cluster`, {crossRegionReferences: true}).catch(() => { | ||
// main stack based on AWS EKS blueprints | ||
new DevClusterConstruct().eksCluster(app, `garden-dev-cluster`).catch(() => { | ||
logger.info("Error setting up dev cluster"); | ||
}); |
Oops, something went wrong.