Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DockerImageAsset: it fails to deploy to 2 regions #25962

Open
danielpid opened this issue Jun 13, 2023 · 6 comments
Open

DockerImageAsset: it fails to deploy to 2 regions #25962

danielpid opened this issue Jun 13, 2023 · 6 comments
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. documentation This is a problem with documentation. effort/medium Medium work item – several days of effort p2

Comments

@danielpid
Copy link

danielpid commented Jun 13, 2023

Describe the bug

I have a CDK stack with DockerImageAsset that I use to deploy to 2 different regions.
The instance of the second stack is not pushed to ECR

Expected Behavior

The image is present in the ECR of both regions

Current Behavior

Only the first stack is correctly pushing the image to ECR

Reproduction Steps

sample-cdk-stack.ts

import * as cdk from "aws-cdk-lib";
import { DockerImageAsset } from "aws-cdk-lib/aws-ecr-assets";
import { Construct } from "constructs";
import path = require("path");
export class SampleCdkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const { env } = props!;

    const image = new DockerImageAsset(
      this,
      `MultiRegionImage-${env?.region}`,
      {
        directory: path.join(__dirname, ".."),
      }
    );

    new cdk.CfnOutput(this, "ImageUri", {
      value: image.imageUri,
    });
  }
}

sample-cdk.ts

#!/usr/bin/env node
import "source-map-support/register";
import * as cdk from "aws-cdk-lib";
import { SampleCdkStack } from "../lib/sample-cdk-stack";

const app = new cdk.App();

new SampleCdkStack(app, "SampleCdkStackFrankfurt", {
  env: { account: "***", region: "eu-central-1" },
});

new SampleCdkStack(app, "SampleCdkStackLondon", {
  env: { account: "***", region: "eu-west-2" },
});

The DcokerImage can be a simple express application

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.83.1

Framework Version

No response

Node.js Version

v16.15.1

OS

macOS Monterey 12.4

Language

Typescript

Language Version

~5.0.4

Other information

No response

@danielpid danielpid added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 13, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ecr Related to Amazon Elastic Container Registry label Jun 13, 2023
@pahud
Copy link
Contributor

pahud commented Jun 14, 2023

Have you tried extraHash?

    const region = props.env!.region

    const image = new ecrassets.DockerImageAsset(this, `MultiRegionImage-${region}`, {
        directory: path.join(__dirname, "../docker.d"),
        extraHash: region,
    });

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 14, 2023
@peterwoodworth
Copy link
Contributor

@pahud if this is required to deploy to multiple regions, we should add this to the readme.

@peterwoodworth peterwoodworth added the documentation This is a problem with documentation. label Jun 14, 2023
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 15, 2023
@danielpid
Copy link
Author

Hi @pahud, @peterwoodworth,
Thanks for your response, I confirm that by adding that parameter the issue is gone.
If you ask me, apart from updating the documentation, I'd throw some error or at least a warning when the image was not successfully pushed to ECR using that class.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@tmokmss
Copy link
Contributor

tmokmss commented Jun 29, 2023

I confirmed this issue was introduced on v2.80.0. Maybe related with #25536. Can you check this? @rix0rrr @kaizencc

@tmokmss
Copy link
Contributor

tmokmss commented Jul 12, 2023

The root cause for this issue is that a tag for imageUri is only added on build phase, which runs only once per asset hash, where it is actually required for each region.

await dockerForBuilding.tag(localTagName, initOnce.imageUri);

We may want to move this tagging process to the publish phase. We have to somehow pass the localTagName (especially for an image built by buildExternalAsset).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecr Related to Amazon Elastic Container Registry bug This issue is a bug. documentation This is a problem with documentation. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

4 participants