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

ecr-assets: can't use docker build options like --ssh/--secret available when BUILDKIT is enabled #14910

Closed
2 tasks
hizvi opened this issue May 28, 2021 · 12 comments · Fixed by #23778
Closed
2 tasks
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@hizvi
Copy link

hizvi commented May 28, 2021

docker build options --ssh / --secret can not be used with aws-ecs.AssetImage or aws-ecr-assets.DockerImageAsset

these options are available with docker build when DOCKER_BUILDKIT=1 is enabled.

Use Case

Docker image builds may require access to private resources that require ssh keys and/or secrets. Docker BuildKit allows mounting them safely.

Proposed Solution

The docker utility in cdk already has options for build args and such. the --ssh and --secret options can be implemented similarly.

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@hizvi hizvi added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 28, 2021
@peterwoodworth peterwoodworth added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jun 1, 2021
@SoManyHs SoManyHs added the @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets label Jun 1, 2021
@SoManyHs SoManyHs changed the title (@aws-cdk/aws-ecs): can't use docker build options like --ssh/--secret available when BUILDKIT is enabled (@aws-cdk/aws-ecr-assets): can't use docker build options like --ssh/--secret available when BUILDKIT is enabled Jun 1, 2021
@SoManyHs SoManyHs removed the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jun 1, 2021
@github-actions github-actions bot added the @aws-cdk/assets Related to the @aws-cdk/assets package label Jun 1, 2021
@peterwoodworth peterwoodworth removed the @aws-cdk/assets Related to the @aws-cdk/assets package label Jun 2, 2021
@peterwoodworth
Copy link
Contributor

@SoManyHs can you comment on why this is an ecr-assets issue?

@eladb eladb added effort/small Small work item – less than a day of effort p1 labels Jun 18, 2021
@eladb
Copy link
Contributor

eladb commented Jun 18, 2021

Seems like a useful addition, contributions are welcome.

@eladb eladb removed their assignment Jun 18, 2021
@eladb eladb changed the title (@aws-cdk/aws-ecr-assets): can't use docker build options like --ssh/--secret available when BUILDKIT is enabled ecr-assets: can't use docker build options like --ssh/--secret available when BUILDKIT is enabled Jun 18, 2021
@github-actions github-actions bot added the @aws-cdk/assets Related to the @aws-cdk/assets package label Jun 18, 2021
@eladb eladb removed the needs-triage This issue or PR still needs to be triaged. label Jun 30, 2021
@eladb eladb removed their assignment Jun 30, 2021
@rob3c
Copy link

rob3c commented Sep 30, 2021

Lack of support for BuildKit options like --secret and --ssh is a problem everywhere in the codebase where a docker build command is created:

  • packages/@aws-cdk/core/lib/bundling.ts
  • packages/cdk-assets/lib/private/docker.ts
  • maybe elsewhere

None of the modern docker args like those for BuildKit are explicitly supported via options params, and there's no mechanism for decorating any CDK-created docker commands with additional args to allow for CLI updates that haven't been coded for yet in the CDK.

In the meantime, I've posted a placeholder solution for my use cases to this gist:

https://gist.github.com/rob3c/8bf845918bc5270c5e22da0674081f90

It has functions assetCodeFromDockerBuildKitBuild() and dockerImageFromBuildKitBuild().

Here's sample usage showing lambda code built using BuildKit --secret and --ssh args along with an extra Docker --progress arg:

new aws_lambda.Function(this, 'MyLambda', {
  runtime: aws_lambda.Runtime.DOTNET_CORE_3_1,
  code: assetCodeFromDockerBuildKitBuild(buildContextDir, {
    buildArgs: { CONFIG: 'Release' },
    secrets: { nuget_config: 'NuGetPrivateFeed.Config' },
    additionalArgs: {
      '--progress': 'plain',
      '--ssh': 'myserver=$HOME/.ssh/myserver_rsa',
    },
  }),
  handler: 'MyAssembly::MyNamespace.MyHandlerClass::MyHandlerMethod',
});

@hxy1991
Copy link

hxy1991 commented Jan 5, 2022

@peterwoodworth @eladb
Hello, is this feature being implemented?

How can I achieve the same effect as "DOCKER_BUILDKIT=1 docker build --secret id=aws,src=$HOME/.aws/credentials --progress=plain" through awscdk/awsecrassets

asset := awsecrassets.NewDockerImageAsset(stack, jsii.String("dockerImage"), &awsecrassets.DockerImageAssetProps{
	Directory: jsii.String(path.Join(dir, "./app")),
})

I really need to pass aws/credentials when building the docker image, because I want to import another aws codecommit (golang project) as a module.

package main

import (
	"git-codecommit.eu-central-1.amazonaws.com/v1/repos/xxx.git/service/xxx"
)

@rob3c
Copy link

rob3c commented Jan 5, 2022

How can I achieve the same effect as "DOCKER_BUILDKIT=1 docker build --secret id=aws,src=$HOME/.aws/credentials --progress=plain" through awscdk/awsecrassets

@hxy1991 See my message and the gist I posted a link to. There are functions that produce DockerImage and AssetCode CDK instances. Just add the single source file to a CDK v2 project and you can use the functions for arbitrary Docker BuildKit builds with the CDK. Otherwise, you'll be stuck waiting for this issue to be addressed that's been open for 7 months and counting now. It doesn't seem to be a priority.

@RichiCoder1
Copy link
Contributor

@eladb as a simple half step to adding all the new BuildKit args, would a generic additionalArgs escape hatch be acceptable?

@danw-mpl
Copy link

@rob3c Would you know how to use your code with an ecs.ContainerImage.fromAsset(...)?

@lox
Copy link

lox commented Sep 10, 2022

Buildkit is now the default in Docker for Mac. This means pretty much any of the docker build integrations currently across cdk won't work.

#21990

@newit-manhp
Copy link

It seem currently cdk not support with ssh/secret option.
To build docker image with private git repo access, I can workaround with this: https://vsupalov.com/build-docker-image-clone-private-repo-ssh-key/
Using ARG + multiple stage + buildArg to build the image

@simonloach
Copy link

Please work on this, this is a blocker for my team

@mergify mergify bot closed this as completed in #23778 Feb 10, 2023
mergify bot pushed a commit that referenced this issue Feb 10, 2023
Partially closes #14910 and #14395
----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@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.

@rcraigfiedorek
Copy link

@hizvi could this issue be reopened? It has only been partially solved: the --secret option is now available but --ssh still is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package @aws-cdk/aws-ecr-assets Related to AWS CDK Docker Image Assets effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.