Skip to content

Commit

Permalink
force an ECS update on every push to service construct by introducing…
Browse files Browse the repository at this point in the history
… a random token
  • Loading branch information
3p3r committed Apr 7, 2020
1 parent 49006fa commit 0b4ce2a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/resources/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import _ from 'lodash';
import { Container } from './container';
import { Network } from './network';
import { Storage } from './storage';
import { config } from '../config';

enum ServiceProvider {
Fargate = 'fargate',
Expand Down Expand Up @@ -68,6 +69,8 @@ export class Service extends cdk.Construct {
assert.ok(_.isObject(this.props.network));

const imageUri = this.props.container.getImageUri(this);
// a unique container to force an ECS cluster update to pull down changes
const containerName = `container-${config.opts.git.commit}-${Date.now()}`;
const ecrPullPolicy = new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
Expand All @@ -89,6 +92,8 @@ export class Service extends cdk.Construct {
cluster: this.props.network.cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry(imageUri),
environment: { MUTATO_CONTAINER_NAME: containerName },
containerName,
},
...(this.props
.config as ecsPatterns.ApplicationLoadBalancedFargateServiceProps),
Expand All @@ -103,6 +108,8 @@ export class Service extends cdk.Construct {
cluster: this.props.network.cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry(imageUri),
environment: { MUTATO_CONTAINER_NAME: containerName },
containerName,
},
...(this.props
.config as ecsPatterns.ApplicationLoadBalancedEc2ServiceProps),
Expand All @@ -118,6 +125,7 @@ export class Service extends cdk.Construct {
cluster: this.props.network.cluster,
scheduledFargateTaskImageOptions: {
image: ecs.ContainerImage.fromRegistry(imageUri),
environment: { MUTATO_CONTAINER_NAME: containerName },
},
schedule: appAutoScaling.Schedule.expression(
this.props.rate as string,
Expand All @@ -132,6 +140,7 @@ export class Service extends cdk.Construct {
cluster: this.props.network.cluster,
scheduledEc2TaskImageOptions: {
image: ecs.ContainerImage.fromRegistry(imageUri),
environment: { MUTATO_CONTAINER_NAME: containerName },
},
schedule: appAutoScaling.Schedule.expression(
this.props.rate as string,
Expand All @@ -147,6 +156,7 @@ export class Service extends cdk.Construct {
'FargateQueue',
{
image: ecs.ContainerImage.fromRegistry(imageUri),
environment: { MUTATO_CONTAINER_NAME: containerName },
queue: this.props.storage?.resource as sqs.Queue,
cluster: this.props.network.cluster,
...(this.props
Expand All @@ -162,6 +172,7 @@ export class Service extends cdk.Construct {
'ClassicQueue',
{
image: ecs.ContainerImage.fromRegistry(imageUri),
environment: { MUTATO_CONTAINER_NAME: containerName },
queue: this.props.storage?.resource as sqs.Queue,
cluster: this.props.network.cluster,
...(this.props
Expand Down

0 comments on commit 0b4ce2a

Please sign in to comment.