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

Add support for additional_contexts in build service config #10369

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

laurazard
Copy link
Member

@laurazard laurazard commented Mar 13, 2023

What I did

Implement support for additional_contexts as per compose-spec/compose-spec#307 and compose-spec/compose-go#354.

Related issue

closes #9461
closes #9961

(not mandatory) A picture of a cute animal, if possible in relation to what you did

image

@laurazard laurazard requested review from a team, nicksieger, ndeloof, StefanScherer, ulyssessouza, glours and milas and removed request for a team March 13, 2023 15:44
go.mod Outdated Show resolved Hide resolved
pkg/compose/build.go Outdated Show resolved Hide resolved
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Patch coverage: 7.69% and project coverage change: -0.02 ⚠️

Comparison is base (e0aaccf) 53.37% compared to head (e53bc57) 53.36%.

Additional details and impacted files
@@            Coverage Diff             @@
##               v2   #10369      +/-   ##
==========================================
- Coverage   53.37%   53.36%   -0.02%     
==========================================
  Files         104      104              
  Lines        8927     8939      +12     
==========================================
+ Hits         4765     4770       +5     
- Misses       3642     3648       +6     
- Partials      520      521       +1     
Impacted Files Coverage Δ
pkg/compose/build.go 76.28% <0.00%> (-2.02%) ⬇️
pkg/compose/build_classic.go 52.91% <25.00%> (-0.86%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@laurazard
Copy link
Member Author

@glours PTAL :)

@ndeloof
Copy link
Contributor

ndeloof commented Mar 15, 2023

looks like we don't have coverage report for cucumber tests

@ndeloof ndeloof merged commit 200f47e into docker:v2 Mar 15, 2023
@laurazard
Copy link
Member Author

Yup, I was just realizing that. We probably need to do the -cover dance for those too?

@ndeloof
Copy link
Contributor

ndeloof commented Mar 15, 2023

yes we probably need GOCOVERDIR set somehow

@EronWright
Copy link

Heads-up, I hit upon an issue related to additional_contexts and relative paths.
#10448

Assumedly this is because the context is being passed uninterpreted by compose to buildx.

@ndeloof
Copy link
Contributor

ndeloof commented Apr 7, 2023

@EronWright according to the spec
https://github.com/compose-spec/compose-spec/blob/master/build.md

Validation beyond that is the responsibility of the image builder

but indeed, it would make sense we detect and expand relative paths. I'll investigate if this is feasible

@TeKa-Dev
Copy link

TeKa-Dev commented Jul 19, 2023

I have a problem with additional_contexts and directory paths containing a dot at the beginning:

additional_contexts:
  foo: /home/user/.bar/foo

it just comes out empty when COPY,
but it works on buildx:
docker buildx build . --build-context foo=/home/user/.bar/foo

@laurazard
Copy link
Member Author

Hiya @TeKa-Dev,

I can't seem to reproduce this:

$ ls /home/laurabrehm/.config/nvim/
init.lua  lazy-lock.json  LICENSE  lua  README.md  stylua.toml
services:
  a:
    build:
        context: .
        additional_contexts:
          - dep=/home/laurabrehm/.config/nvim/
# syntax=docker/dockerfile:1
FROM alpine:latest
COPY --from=dep init.lua /
$ docker compose build
...
$ docker run --rm -it build-a sh
/ ls
...
init.lua

We might be able to help you if you provide a more complete reproduction scenario however.

@TeKa-Dev
Copy link

TeKa-Dev commented Jul 21, 2023

Hi, I was not accurate, not all directories with a dot cause the error, but .m2/repository/

$ docker buildx build . --build-context m2repository=/home/teka/.m2/repository/
[+] Building 1.1s (12/12) FINISHED
 => [internal] load build definition from Dockerfile                                                 0.0s
 => => transferring dockerfile: 994B                                                                 0.0s
 => [internal] load .dockerignore                                                                    0.0s
 => => transferring context: 34B                                                                     0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4                                         0.9s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbf  0.0s
 => [internal] load build definition from Dockerfile                                                 0.0s
 => [internal] load .dockerignore                                                                    0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                     0.0s
 => [context m2repository] load .dockerignore                                                        0.0s
 => => transferring m2repository: 102B                                                               0.0s
 => [context m2repository] load from client                                                          0.0s
 => => transferring m2repository: 406.09kB                                                           0.0s
 => CACHED [stage-0 1/2] FROM docker.io/library/alpine:latest                                        0.0s
 => [stage-0 2/2] COPY --from=m2repository org /                                                     0.0s
 => exporting to image                                                                               0.0s
 => => exporting layers                                                                              0.0s
 => => writing image sha256:c9a3f6a8e9a2f369d8cb5332c0f4652d44e35c52e622d2fc899851a3b30c87ac         0.0s
services:
  alpine:
    build:
      context: .
      additional_contexts:
        - m2repository=/home/teka/.m2/repository/
$ docker-compose build
[+] Building 2.1s (11/11) FINISHED
 => [internal] load build definition from Dockerfile                                                 0.0s
 => => transferring dockerfile: 994B                                                                 0.0s
 => [internal] load .dockerignore                                                                    0.0s
 => => transferring context: 34B                                                                     0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4                                         1.9s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbf  0.0s
 => [internal] load build definition from Dockerfile                                                 0.0s
 => [internal] load .dockerignore                                                                    0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                     0.0s
 => [context m2repository] load .dockerignore                                                        0.0s
 => => transferring m2repository: 2B                                                                 0.0s
 => [context m2repository] load from client                                                          0.0s
 => => transferring m2repository: 2B                                                                 0.0s
 => [stage-0 1/2] FROM docker.io/library/alpine:latest                                               0.0s
 => ERROR [stage-0 2/2] COPY --from=m2repository org /                                               0.0s
------
 > [stage-0 2/2] COPY --from=m2repository org /:
------
failed to solve: failed to compute cache key: "/org" not found: not found

I don't know if this is related but it doesn't work for me

$ docker compose build
services.alpine.build Additional property additional_contexts is not allowed

I use

$ docker -v
Docker version 20.10.23, build 7155243
$ docker-compose -v
Docker Compose version v2.17.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for additional build contexts Support multiple build contexts
4 participants