-
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.
- Loading branch information
Showing
26 changed files
with
8,124 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
cdk* |
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,4 @@ | ||
.envrc | ||
.venv | ||
__pycache__ | ||
*.egg-info |
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,5 @@ | ||
tap "aljohri/-" | ||
brew 'awscli' | ||
brew 'awslogs' | ||
brew 'AlJohri/-/kar' | ||
cask 'docker' unless File.directory?('/Applications/Docker.app') |
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,8 @@ | ||
FROM python:3.9 | ||
WORKDIR /app | ||
COPY setup.py . | ||
COPY lib/__init__.py lib/__init__.py | ||
COPY requirements.txt /app | ||
RUN pip install -r requirements.txt | ||
COPY . . | ||
CMD ["uwsgi", "--http", "0.0.0.0:5000", "--module", "app:app"] |
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,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
PORT=5000 | ||
REPOSITORY=article-rec-api | ||
DOCKER_OPTS=$(cat <<END_HEREDOC | ||
-v $HOME/.aws/credentials:/root/.aws/credentials:ro \ | ||
-v $(pwd):/app \ | ||
-p $PORT:$PORT \ | ||
-e STAGE=local \ | ||
-it $REPOSITORY | ||
END_HEREDOC | ||
) | ||
|
||
#@cdk | ||
#+Run cdk. | ||
task-cdk() { | ||
(cd cdk && npx cdk $@) | ||
} | ||
|
||
#@build | ||
#+Build docker image. | ||
task-build() { | ||
docker build . -t $REPOSITORY | ||
} | ||
|
||
#@run | ||
#+Run docker container. | ||
task-run() { | ||
docker run $DOCKER_OPTS "$@" | ||
} | ||
|
||
#@flask | ||
#+Run flask development server with automatic reloading. | ||
task-flask() { | ||
# See: https://flask.palletsprojects.com/en/1.1.x/server/#server | ||
task-run flask run --host 0.0.0.0 --port $PORT --reload --debugger | ||
} |
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,10 @@ | ||
from flask import Flask | ||
|
||
from lib.config import config | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def hello_world(): | ||
return config.get('HELLO') | ||
|
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,11 @@ | ||
*.js | ||
!jest.config.js | ||
*.d.ts | ||
node_modules | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
|
||
# Parcel default cache directory | ||
.parcel-cache |
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,6 @@ | ||
*.ts | ||
!*.d.ts | ||
|
||
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out |
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,14 @@ | ||
# Welcome to your CDK TypeScript project! | ||
|
||
This is a blank project for TypeScript development with CDK. | ||
|
||
The `cdk.json` file tells the CDK Toolkit how to execute your app. | ||
|
||
## Useful commands | ||
|
||
* `npm run build` compile typescript to js | ||
* `npm run watch` watch for changes and compile | ||
* `npm run test` perform the jest unit tests | ||
* `cdk deploy` deploy this stack to your default AWS account/region | ||
* `cdk diff` compare deployed stack with current state | ||
* `cdk synth` emits the synthesized CloudFormation template |
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,28 @@ | ||
#!/usr/bin/env node | ||
import 'source-map-support/register'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { AppStack } from "../lib/app-stack"; | ||
import { PipelineStack } from "../lib/pipeline-stack"; | ||
import { STAGE } from "../lib/helpers"; | ||
|
||
const app = new cdk.App(); | ||
const env = { account: "348955818350", region: "us-east-1" }; | ||
const repoName = "article-rec-api"; | ||
const appStackName = "ArticleRecAPI"; | ||
|
||
|
||
new AppStack(app, appStackName, { | ||
env, | ||
stage: STAGE.PRODUCTION, | ||
}); | ||
|
||
new PipelineStack(app, `${appStackName}Pipeline`, { | ||
...env, | ||
repo: { name: repoName }, | ||
appStackName: appStackName, | ||
}); | ||
|
||
new AppStack(app, `Dev${appStackName}`, { | ||
env, | ||
stage: STAGE.DEVELOPMENT, | ||
}); |
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,56 @@ | ||
{ | ||
"hosted-zone:account=348955818350:domainName=localnewslab.io:region=us-east-1": { | ||
"Id": "/hostedzone/Z06424402K2SWPDXBYBCA", | ||
"Name": "localnewslab.io." | ||
}, | ||
"vpc-provider:account=348955818350:filter.tag:Name=infrastructure/ProdPublicVPC:region=us-east-1:returnAsymmetricSubnets=true": { | ||
"vpcId": "vpc-0c9addda957e4ab38", | ||
"vpcCidrBlock": "10.0.64.0/18", | ||
"availabilityZones": [], | ||
"subnetGroups": [ | ||
{ | ||
"name": "Public", | ||
"type": "Public", | ||
"subnets": [ | ||
{ | ||
"subnetId": "subnet-02509308fad8fd1f0", | ||
"cidr": "10.0.64.0/24", | ||
"availabilityZone": "us-east-1a", | ||
"routeTableId": "rtb-0e40161f67598b786" | ||
}, | ||
{ | ||
"subnetId": "subnet-05f107b7911c1fe05", | ||
"cidr": "10.0.65.0/24", | ||
"availabilityZone": "us-east-1b", | ||
"routeTableId": "rtb-02406fece9d47b70f" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"vpc-provider:account=348955818350:filter.tag:Name=infrastructure/DevPublicVPC:region=us-east-1:returnAsymmetricSubnets=true": { | ||
"vpcId": "vpc-05bb341a31d17245e", | ||
"vpcCidrBlock": "10.0.0.0/18", | ||
"availabilityZones": [], | ||
"subnetGroups": [ | ||
{ | ||
"name": "Public", | ||
"type": "Public", | ||
"subnets": [ | ||
{ | ||
"subnetId": "subnet-0d7f763ef3d6dc898", | ||
"cidr": "10.0.0.0/24", | ||
"availabilityZone": "us-east-1a", | ||
"routeTableId": "rtb-047dab8a3584bc3f9" | ||
}, | ||
{ | ||
"subnetId": "subnet-00ff7ea5781b2dffc", | ||
"cidr": "10.0.1.0/24", | ||
"availabilityZone": "us-east-1b", | ||
"routeTableId": "rtb-0c0edaf1fa6e038a0" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
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,8 @@ | ||
{ | ||
"app": "npx ts-node bin/cdk.ts", | ||
"context": { | ||
"@aws-cdk/core:enableStackNameDuplicates": "true", | ||
"aws-cdk:enableDiffNoFail": "true", | ||
"@aws-cdk/core:stackRelativeExports": "true" | ||
} | ||
} |
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,7 @@ | ||
module.exports = { | ||
roots: ['<rootDir>/test'], | ||
testMatch: ['**/*.test.ts'], | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest' | ||
} | ||
}; |
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,73 @@ | ||
import * as cdk from "@aws-cdk/core"; | ||
import * as ecs from "@aws-cdk/aws-ecs"; | ||
import * as ec2 from "@aws-cdk/aws-ec2"; | ||
import * as iam from "@aws-cdk/aws-iam"; | ||
import * as acm from "@aws-cdk/aws-certificatemanager"; | ||
import * as route53 from "@aws-cdk/aws-route53"; | ||
import * as helpers from "./helpers"; | ||
import { ApplicationLoadBalancedEc2Service } from "@aws-cdk/aws-ecs-patterns"; | ||
|
||
// TODO this needs to be propagated to the tags | ||
export interface AppStackProps extends cdk.StackProps { | ||
stage: helpers.STAGE; | ||
} | ||
|
||
export class AppStack extends cdk.Stack { | ||
constructor(scope: cdk.Construct, id: string, props: AppStackProps) { | ||
super(scope, id, props); | ||
|
||
const taskRole = new iam.Role(this, `${id}Role`, { | ||
assumedBy: new iam.ServicePrincipal("ecs-tasks.amazonaws.com"), | ||
inlinePolicies: { | ||
SSMAccess: new iam.PolicyDocument({ | ||
statements: [ | ||
new iam.PolicyStatement({ | ||
sid: `SSMAccess`, | ||
actions: ["ssm:*"], | ||
resources: ["*"], | ||
}), | ||
], | ||
}), | ||
}, | ||
}); | ||
|
||
// const bucketName = helpers.makeBucketName("change-this-bucket-name", props.stage); | ||
// const bucket = helpers.makeBucket(this, bucketName, taskRole, props.stage); | ||
|
||
const { cluster } = helpers.getECSCluster(this, props.stage); | ||
|
||
const image = ecs.ContainerImage.fromAsset("../", { | ||
extraHash: Date.now().toString(), | ||
}); | ||
|
||
const domainZone = route53.HostedZone.fromLookup(this, `${id}HostedZone`, { | ||
domainName: 'localnewslab.io' | ||
}); | ||
|
||
let domainName = "article-rec-api"; | ||
if (props.stage == helpers.STAGE.DEVELOPMENT) { | ||
domainName = 'dev-' + domainName; | ||
} | ||
|
||
const certificate = acm.Certificate.fromCertificateArn(this, `${id}Certificate`, cdk.Fn.importValue("LocalNewsLab-certificate-arn")); | ||
|
||
new ApplicationLoadBalancedEc2Service(this, `${id}Service`, { | ||
cluster, | ||
cpu: 128, | ||
memoryLimitMiB: 128, | ||
desiredCount: 1, | ||
domainName, | ||
domainZone, | ||
certificate, | ||
taskImageOptions: { | ||
image, | ||
containerPort: 5000, | ||
taskRole, | ||
environment: { | ||
STAGE: props.stage, | ||
} | ||
} | ||
}) | ||
|
||
} | ||
} |
Oops, something went wrong.