Skip to content

Commit

Permalink
Add monorepo context to cdk docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Mar 15, 2023
1 parent 164cb40 commit 93cadbb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion infrastructure/cdk/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
testTimeout: 20000,
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
},
verbose: true
}
14 changes: 12 additions & 2 deletions infrastructure/cdk/src/providers/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 { UsersStackProps } from '../interfaces/StackProps'
Expand All @@ -11,8 +12,10 @@ import { Config } from './config'
export class UsersStack extends cdk.Stack {
/** Stack name */
public readonly name = 'users'
/** Path to monorepo root */
public readonly contextPath = '../..'
/** Path to stack build assets or Dockerfile */
public readonly assetPath = '../../services/users'
public readonly assetPath = 'services/users/Dockerfile'

constructor(scope: Construct, id: string, props: UsersStackProps) {
super(scope, id, props)
Expand All @@ -21,6 +24,13 @@ export class UsersStack extends cdk.Stack {
const { project, stage, rootDomain, subdomains } = config
const { certificate, cluster, hostedZone } = props

/** Create Docker image asset */
const imageAsset = new ecrAssets.DockerImageAsset(this, config.getFullStackResourceName(this.name, 'image'), {
directory: this.contextPath,
file: this.assetPath,
platform: ecrAssets.Platform.LINUX_AMD64
})

/** Create a load-balanced service for the users express API */
const usersService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, config.getFullStackResourceName(this.name, 'fargate'), {
assignPublicIp: true,
Expand All @@ -30,7 +40,7 @@ export class UsersStack extends cdk.Stack {
domainZone: hostedZone,
taskImageOptions: {
containerPort: 4000,
image: ecs.ContainerImage.fromAsset(this.assetPath),
image: ecs.ContainerImage.fromDockerImageAsset(imageAsset),
environment: {
PROJECT: project,
STAGE: stage
Expand Down
7 changes: 0 additions & 7 deletions services/users/docker-compose.yaml

This file was deleted.

0 comments on commit 93cadbb

Please sign in to comment.