-
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.
- Loading branch information
1 parent
3f59db9
commit 44568ae
Showing
11 changed files
with
131 additions
and
100 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 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Construct } from 'constructs' | ||
import * as cdk from 'aws-cdk-lib' | ||
import * as ecrAssets from 'aws-cdk-lib/aws-ecr-assets' | ||
import * as ecs from 'aws-cdk-lib/aws-ecs' | ||
import * as ecsPatterns from 'aws-cdk-lib/aws-ecs-patterns' | ||
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager' | ||
import { BlogStackProps } from '../interfaces/StackProps' | ||
import { Config } from './config' | ||
import { kebabCase } from '@casimir/format' | ||
|
||
/** | ||
* Blog service stack | ||
*/ | ||
export class BlogStack extends cdk.Stack { | ||
public readonly name = 'blog' | ||
public readonly assetPath = 'services/blog/Dockerfile' | ||
public readonly contextPath = '../../' | ||
|
||
constructor(scope: Construct, id: string, props: BlogStackProps) { | ||
super(scope, id, props) | ||
|
||
const config = new Config() | ||
const { project, stage, rootDomain, subdomains } = config | ||
const { certificate, hostedZone, vpc } = props | ||
|
||
const imageAsset = new ecrAssets.DockerImageAsset(this, config.getFullStackResourceName(this.name, 'image'), { | ||
directory: this.contextPath, | ||
file: this.assetPath, | ||
platform: ecrAssets.Platform.LINUX_AMD64, | ||
ignoreMode: cdk.IgnoreMode.GIT | ||
}) | ||
|
||
const hackmdToken = ecs.Secret.fromSecretsManager( | ||
secretsmanager.Secret.fromSecretNameV2(this, config.getFullStackResourceName(this.name, 'hackmd-token'), kebabCase(config.getFullStackResourceName(this.name, 'hackmd-token'))) | ||
) | ||
const fargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, config.getFullStackResourceName(this.name, 'fargate'), { | ||
assignPublicIp: true, | ||
certificate, | ||
domainName: `${subdomains.blog}.${rootDomain}`, // e.g. blog.casimir.co or blog.dev.casimir.co | ||
domainZone: hostedZone, | ||
taskImageOptions: { | ||
containerPort: 4000, | ||
image: ecs.ContainerImage.fromDockerImageAsset(imageAsset), | ||
environment: { | ||
PROJECT: project, | ||
STAGE: stage | ||
}, | ||
secrets: { | ||
HACKMD_TOKEN: hackmdToken | ||
} | ||
}, | ||
vpc | ||
}) | ||
|
||
fargateService.targetGroup.configureHealthCheck({ | ||
path: '/health' | ||
}) | ||
} | ||
} |
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
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 @@ | ||
# Note: This Dockerfile assumes context is set to the git root (../../) | ||
|
||
# Use Node 18 Alpine as the base image | ||
FROM node:18-alpine | ||
|
||
# Install git | ||
RUN apk add --no-cache git | ||
|
||
# Copy all files to /tmp | ||
COPY . . | ||
|
||
# Install dependencies | ||
RUN npm install --ignore-scripts | ||
|
||
# Build the blog service | ||
RUN npm run build --workspace @casimir/blog | ||
|
||
# Move the blog service build assets to /app | ||
RUN mv services/blog/dist /app | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Expose port 4001 | ||
EXPOSE 4001 | ||
|
||
# Run the app when the container launches | ||
CMD ["node", "index.js"] |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"strict": true, | ||
"preserveConstEnums": true, | ||
"noEmit": true, | ||
"sourceMap": false, | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"build.js" | ||
], | ||
"include": [ | ||
"./src/*" | ||
] | ||
} |
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
"build.js" | ||
], | ||
"include": [ | ||
"./src/*", | ||
"env.d.ts" | ||
"./src/*" | ||
] | ||
} |