Skip to content

Commit

Permalink
feat: build container in deployment account store in ecr
Browse files Browse the repository at this point in the history
  • Loading branch information
marnixdessing committed Mar 28, 2023
1 parent 86b840b commit e13b079
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 28 deletions.
10 changes: 3 additions & 7 deletions .projen/deps.json

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

3 changes: 1 addition & 2 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const project = new GemeenteNijmegenCdkApp({
name: 'yivi-issue-server',
deps: [
'cdk-remote-stack',
'@aws-cdk/aws-apigatewayv2-alpha',
'@aws-cdk/aws-apigatewayv2-integrations-alpha',
'cdk-ecr-deployment',
],
// deps: [], /* Runtime dependencies of this module. */
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */
Expand Down
3 changes: 1 addition & 2 deletions package.json

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

42 changes: 42 additions & 0 deletions src/DeploymentStage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Stack, StackProps, Stage, StageProps } from 'aws-cdk-lib';
import { DockerImageAsset } from 'aws-cdk-lib/aws-ecr-assets';
import * as ecrdeploy from 'cdk-ecr-deployment';
import { Construct } from 'constructs';
import { Statics } from './Statics';


export class DeploymentStage extends Stage {
constructor(scope: Construct, id: string, props: StageProps) {
super(scope, id, props);
new ContainerStack(this, 'container-build-stack');
}
}

class ContainerStack extends Stack {

constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

// Details on how the images is published are hidden.
// See https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets-readme.html#publishing-images-to-ecr-repositories
const img = new DockerImageAsset(this, 'yivi-server-image', {
directory: './src/container',
buildArgs: {
BUILD_FOR_ENVIRONMENT: '', // TODO make configurable and use correct configuration in the docker file
},
});

// Construct the target ecr url
const account = Stack.of(this).account;
const region = Stack.of(this).region;
const imageName = `${Statics.projectName}:latest`;
const ecrTarget = `${account}.dkr.ecr.${region}.amazonaws.com/${imageName}`;

// Publish by deploying the image to ECR in this account
new ecrdeploy.ECRDeployment(this, 'deploy-yivi-server-image', {
src: new ecrdeploy.DockerImageName(img.imageUri),
dest: new ecrdeploy.DockerImageName(ecrTarget),
});

}
}
5 changes: 5 additions & 0 deletions src/PipelineStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as cdkpipelines from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
import { ApiStage } from './ApiStage';
import { Configuration } from './Configuration';
import { DeploymentStage } from './DeploymentStage';
import { Statics } from './Statics';

export interface PipelineStackProps extends core.StackProps {
Expand Down Expand Up @@ -38,6 +39,10 @@ export class PipelineStack extends core.Stack {
}),
});

pipeline.addStage(new DeploymentStage(this, 'yivi-issue-server-deployment', {

}));

if (!props.emptyPipeline) {
pipeline.addStage(new ApiStage(this, 'yivi-issue-server', {
...props.configuration,
Expand Down
Loading

0 comments on commit e13b079

Please sign in to comment.