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

Handle Build Args in ContainerImage.fromAsset() #1271

Closed
MrArnoldPalmer opened this issue Dec 2, 2018 · 5 comments · Fixed by #2604
Closed

Handle Build Args in ContainerImage.fromAsset() #1271

MrArnoldPalmer opened this issue Dec 2, 2018 · 5 comments · Fixed by #2604
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package feature-request A feature should be added or improved.

Comments

@MrArnoldPalmer
Copy link
Contributor

When building a docker container locally and deploying that image, it would be useful to be able to pass build args to the ecs.ContainerImage.fromAsset() constructor.

As far as I can tell this could go something like adding a "buildArgs" property to the DockerImageAssetProps interface which would be an object (key/val pairs). These would flow through to DockerImageAsset in @aws-cdk/assets-docker and be added to the asset metadata.

Then, when building containers during deployment in aws-cdk/lib/docker.js

    const commandArgs = Object.entries(asset.buildArgs) // Where buildArgs defaults to {}
      .map(([buildArgKey, buildArgVal]) => `--build-arg ${buildArgKey}=${buildArgVal}`);

    const command = ['docker',
      'build',
      ...commandArgs,
      '--quiet',
      asset.path];

There are other docker build CLI options that may be useful to handle similarly, looking through the list, maybe "target" to allow users to specify a specific stage to be built in a multi stage build.

Does this seem like something cdk should allow?

@rix0rrr
Copy link
Contributor

rix0rrr commented Dec 3, 2018

It could be, but I'm curious as to what the types of arguments are you would be wanting to pass. Could you tell us a little about your use case?

@rix0rrr rix0rrr added @aws-cdk/assets Related to the @aws-cdk/assets package feature-request A feature should be added or improved. labels Dec 3, 2018
@MrArnoldPalmer
Copy link
Contributor Author

Generally any build time configuration values. For me these are values that we need present during build steps. Stuff like the NODE_ENV environment variable for when we precompile static assets in the container.

Ours is a rails app, and unfortunately when running build steps in rails it expects all environment variables to be set. So we have a set of "build" environment variables that we need to pass in.

@jewelsjacobs
Copy link

I'm in the same boat. Needing to pass an NPM_TOKEN variable as an ARG to install node modules from a private repo.

@jogold
Copy link
Contributor

jogold commented May 17, 2019

Another use case is to pass a port to EXPOSE via build args so that we can have the port defined only once somewhere in the stack/construct code.

@jogold
Copy link
Contributor

jogold commented May 20, 2019

@rix0rrr would you accept a PR for this?

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 feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants