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

Support multi-stage build targets #1331

Closed
jahsome opened this issue Aug 27, 2020 · 3 comments · Fixed by #1555
Closed

Support multi-stage build targets #1331

jahsome opened this issue Aug 27, 2020 · 3 comments · Fixed by #1555
Labels
type/feature Issues that are new feature requests. type/request Issues that are created by customers.

Comments

@jahsome
Copy link

jahsome commented Aug 27, 2020

I may be going about this wrong, but I have a container which needs asset dependencies installed and compiled for a production build but not local/development builds. Specifically, I need to install npm dependencies and run gulp.

I couldn't think of a way to accomplish this, other than to create a multi-stage build in the Dockerfile and attempt to reference the specific stage but I don't see a way to do that with the init command.

If I have missed something or am attempting some grave sin by attempting this, I welcome any feedback.

Cheers!

@efekarakus efekarakus added the guidance Issue requesting guidance or information about usage label Aug 27, 2020
@efekarakus
Copy link
Contributor

😄 Heya @jake-harris !
Would modifying the build section of the manifest for your service help in this situation? https://github.com/aws/copilot-cli/wiki/Services#build
Under build there is an args property that map to the --build-args flag while building your container image. So I wonder if that can be used to refer to a specific stage.

If this helps, you can modify the manifest before deploying to the "test" environment and the image should build properly before pushing to the ECR repository.

@jahsome
Copy link
Author

jahsome commented Aug 27, 2020

Thanks for the response!

Modifying the manifest with args would probably get me there, but would require some rethinking of my Dockerfile, and potentially eliminate the multi-stage build. Unfortunately I have other workflows dependent upon some of the stages so I don't think that's an option for me particularly.

Ideally, in the manifest, there would be a

image:
  build:
    dockerfile: path/to/dockerfile
    context: context/dir
    args:
      key: value
    target: my-build-stage

Which would output to:

docker build --file path/to/dockerfile --build-arg key=value context/dir --target=my-build-stage

@efekarakus efekarakus added type/feature Issues that are new feature requests. type/request Issues that are created by customers. and removed guidance Issue requesting guidance or information about usage labels Aug 27, 2020
@efekarakus
Copy link
Contributor

Thanks yeah that totally makes sense, I've updated the issue with a feature request label for us to prioritize in our sprints!
As we make progress on the task, this issue will get updated.

@mergify mergify bot closed this as completed in #1555 Oct 26, 2020
mergify bot pushed a commit that referenced this issue Oct 26, 2020
This PR allows to specify the `--target` and `--cache-from` docker build options with a [docker-compose](https://docs.docker.com/compose/compose-file/#cache_from) like syntaxe

```yaml
image:
  build:
    dockerfile: path/to/dockerfile
    context: context/dir
    target: build-stage
    cache_from:
      - image:tag
    args:
      key: value
```

The `cache_from` option allows to pull a previously built image and use it as cache layers, and the `target` option allows... well, to use a multi-stages Dockerfile.

Resolves #1331


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
thrau pushed a commit to localstack/copilot-cli-local that referenced this issue Dec 9, 2022
This PR allows to specify the `--target` and `--cache-from` docker build options with a [docker-compose](https://docs.docker.com/compose/compose-file/#cache_from) like syntaxe

```yaml
image:
  build:
    dockerfile: path/to/dockerfile
    context: context/dir
    target: build-stage
    cache_from:
      - image:tag
    args:
      key: value
```

The `cache_from` option allows to pull a previously built image and use it as cache layers, and the `target` option allows... well, to use a multi-stages Dockerfile.

Resolves aws#1331


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Issues that are new feature requests. type/request Issues that are created by customers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants