Skip to content

(aws-ecr-assets): cannot build image correctly without docker option --network host #15516

@jsnowacki

Description

@jsnowacki

On our setup on AWS EKS runners I try to build image as follows

const image = new ecrAssets.DockerImageAsset(this, `${imageBaseName}-image`, {
      directory: dockerfileDir,
      file: dockerfileName,
    });

The problem is our CICD runners on EKS require option --network host on a building step to work correctly to install dependencies, e.g.:

docker build --network host -t $CI_PROJECT_NAME:latest .

But it seems that ecrAssets.DockerImageAsset doesn't have any way to pass other docker arguments than the listed in https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecr-assets.DockerImageAsset.html#construct-props

Reproduction Steps

Try to build any image that requires some dependencies installed from the internet e.g.

const image = new ecrAssets.DockerImageAsset(this, `${imageBaseName}-image`, {
      directory: dockerfileDir,
      file: dockerfileName,
    });

on a runner that requires --network host e.g. on a AWS EKS pod with docker image running.

What did you expect to happen?

There is some argument e.g. string to pass extra command line options to docker build command.

What actually happened?

When docker during build tries to install some dependencies, we get errors e.g.

Cannot find a valid baseurl for repo: amzn-main/latest
Could not retrieve mirrorlist http://repo.us-west-2.amazonaws.com/latest/main/mirror.list error was
14: curl#6 - "Could not resolve host: repo.us-west-2.amazonaws.com"

Environment

  • CDK CLI Version : 1.106.1
  • Framework Version: 1.106.1
  • Node.js Version: 14
  • OS : Ubuntu 20.04
  • Language (Version): TypeScript (~3.9.7)

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/assetsRelated to the @aws-cdk/assets package@aws-cdk/aws-ecr-assetsRelated to AWS CDK Docker Image AssetsbugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions