Skip to content

Commit

Permalink
chore: some minor fix (#1)
Browse files Browse the repository at this point in the history
Fixes #
  • Loading branch information
pahud authored Jun 29, 2021
1 parent 0d284af commit 71c448f
Show file tree
Hide file tree
Showing 9 changed files with 783 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const project = new AwsCdkTypeScriptApp({
// projenVersion: '^0.24.12',
cdkDependencies: [
/* Which AWS CDK modules (those that start with "@aws-cdk/") this app uses. */
'@aws-cdk/aws-ec2',
'@aws-cdk/aws-ecs',
'@aws-cdk/aws-ecs-patterns',
],
Expand Down
1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM node:14-slim as builder

RUN mkdir /app && \
chown node /app

USER node

WORKDIR /app
Expand All @@ -15,6 +18,9 @@ RUN yarn build

FROM node:14-slim

RUN mkdir /app && \
chown node /app

USER node

WORKDIR /app
Expand All @@ -30,6 +36,6 @@ RUN yarn --production \

COPY --from=builder /app/lib /app/lib

EXPOSE 80
EXPOSE 8080

CMD ["node_modules/.bin/pm2-runtime", "/app/lib/index.js"]
2 changes: 1 addition & 1 deletion src/app/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
port: 80,
port: 8080,
};
20 changes: 18 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as ecsPatterns from '@aws-cdk/aws-ecs-patterns';
import { App, Construct, Stack, StackProps } from '@aws-cdk/core';
Expand All @@ -8,12 +9,18 @@ export class ImageHandlerStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);

const cluster = new ecs.Cluster(this, 'Cluster', {
vpc: getOrCreateVpc(this),
});

const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
memoryLimitMiB: 1024,
cpu: 512,
cluster,
desiredCount: 2,
taskImageOptions: {
image: ecs.ContainerImage.fromAsset(path.join(__dirname, 'app')),
containerPort: 8080,
},
});

Expand All @@ -25,11 +32,20 @@ export class ImageHandlerStack extends Stack {

const env = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: 'us-west-2',
region: process.env.CDK_DEFAULT_REGION || 'us-west-2',
};

const app = new App();

new ImageHandlerStack(app, 'cdk-image-handler', { env });

app.synth();
app.synth();

function getOrCreateVpc(scope: Construct): ec2.IVpc {
// use an existing vpc or create a new one
return scope.node.tryGetContext('use_default_vpc') === '1'
|| process.env.CDK_USE_DEFAULT_VPC === '1' ? ec2.Vpc.fromLookup(scope, 'Vpc', { isDefault: true }) :
scope.node.tryGetContext('use_vpc_id') ?
ec2.Vpc.fromLookup(scope, 'Vpc', { vpcId: scope.node.tryGetContext('use_vpc_id') }) :
new ec2.Vpc(scope, 'Vpc', { maxAzs: 3, natGateways: 1 });
}
Loading

0 comments on commit 71c448f

Please sign in to comment.