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

Issue with building within a container #771

Closed
darewreck54 opened this issue Nov 26, 2019 · 10 comments · Fixed by #782
Closed

Issue with building within a container #771

darewreck54 opened this issue Nov 26, 2019 · 10 comments · Fixed by #782

Comments

@darewreck54
Copy link

darewreck54 commented Nov 26, 2019

I'm trying to build the skopeo within a container with the following docker file.

Dockerfile

FROM golang

# Install Skopeo
RUN apt-get update && apt-get install -y \
    git libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev \
    && apt-get clean

RUN git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo \
    && cd $GOPATH/src/github.com/containers/skopeo && make binary-local-static BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub' \
    && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo

This use to work a couple months ago, but it doesn't work anymore. Did something change?

Error:

$ docker build -t container/skopeo:latest .
Sending build context to Docker daemon  4.608kB
Step 1/4 : FROM golang
 ---> 52b59e9ead8e
Step 2/4 : RUN apt-get update && apt-get install -y     git libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev     && apt-get clean
 ---> Using cache
 ---> 9d6e37aa3d97
Step 3/4 : RUN git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo     && cd $GOPATH/src/github.com/containers/skopeo && make binary-local-static BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub'     && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo
 ---> Running in 6282f54d622d
Cloning into '/go/src/github.com/containers/skopeo'...
GO111MODULE=on go build -mod=vendor -ldflags "-extldflags \"-static\" -X main.gitCommit=ce6ec7720e33b6fac1d7e7a8c4c9af3099bfc3f9" -gcflags "" -tags "containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub" -o skopeo ./cmd/skopeo
build github.com/containers/skopeo/cmd/skopeo: cannot load github.com/containers/image/v5/storage: no Go source files
make: *** [Makefile:107: binary-local-static] Error 1
The command '/bin/sh -c git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo     && cd $GOPATH/src/github.com/containers/skopeo && make binary-local-static BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub'     && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo' returned a non-zero code: 2

looks like it's complaining

github.com/containers/skopeo/cmd/skopeo: cannot load github.com/containers/image/v5/storage: no Go source files
make: *** [Makefile:107: binary-local-static] Error 1

Strange thou tat I don't have any issue building this locally on a mac, but issue with building it within the container.

Thanks

@darewreck54 darewreck54 changed the title Issue with building Issue with building within a container Nov 26, 2019
@TomSweeneyRedHat
Copy link
Member

@darewreck54 I think this is due to this PR that recently merged: #748. I think the containers/images package on your machine needs to be updated, it went from v4 to v5, but I'm not sure how that would happen in ubuntu.

@lsm5 @rhatdan @vrothberg any ideas on how to make that happen?

FWIW, I dropped the static build part of your Dockerfile (see below) and that worked for me.

FROM golang

# Install Skopeo
RUN apt-get update && apt-get install -y \
    git libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev \
    && apt-get clean

RUN git clone https://github.com/containers/skopeo $GOPATH/src/github.com/containers/skopeo \
    && cd $GOPATH/src/github.com/containers/skopeo && make binary-local \
    && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo

@darewreck54
Copy link
Author

darewreck54 commented Nov 27, 2019 via email

@vrothberg
Copy link
Member

Thanks for opening the issue, @darewreck54. We actually want to drop the static builds (see #755) but didn't do the cleanup work yet. Please use make binary-local instead of make binary-local-static, which will resolve the issue.

@darewreck54
Copy link
Author

darewreck54 commented Nov 27, 2019

@vrothberg what’s the implication with dropping the static builds?

https://github.com/containers/image

image

Does this mean that i have to install

gpgme-devel libassuan-devel ostree-devel

as a replacement for the build tags?

I'm guessing

image

covers it except for ostree

@TomSweeneyRedHat
Copy link
Member

I'm going to reopen this issue given the discussion.

@vrothberg
Copy link
Member

@vrothberg what’s the implication with dropping the static builds?

The binary will be dynamically linked and will won't suffer from the restrictions of static binary (see #670 for background).

Does this mean that i have to install [...] as a replacement for the build tags?

You're already installing libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev, so no changes are needed. The Makefile will take care of setting the build tags if needed. containers_image_openpgp and containers_image_ostree can be manually set (BUILDTASGS="..." make ...) if desired

@darewreck54
Copy link
Author

darewreck54 commented Nov 29, 2019

@vrothberg

when you say manually set build stags, do you refer to

FROM golang:1.13.4

ARG SKOPEO_COMMIT=be6146b0a8471b02e776134119a2c37dfb70d414
ARG DOCKER_CREDENTAIL_GCR_VERSION=v2.0.0

# Install Skopeo
RUN apt-get update && apt-get install -y \
  git libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev ostree\
  && apt-get clean

RUN git clone https://github.com/containers/skopeo/  $GOPATH/src/github.com/containers/skopeo \
  && cd $GOPATH/src/github.com/containers/skopeo && git checkout ${SKOPEO_COMMIT} &&  make binary-local BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub' \
  && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo

This will result in the same error

$ docker build -t container/skopeo:latest .
Sending build context to Docker daemon  4.608kB
Step 1/6 : FROM golang:1.13.4
 ---> a2e245db8bd3
Step 2/6 : ARG SKOPEO_COMMIT=be6146b0a8471b02e776134119a2c37dfb70d414
 ---> Using cache
 ---> 1aee940d5b64
Step 3/6 : ARG DOCKER_CREDENTAIL_GCR_VERSION=v2.0.0
 ---> Using cache
 ---> d109d8256dc5
Step 4/6 : RUN apt-get update && apt-get install -y   git libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev ostree  && apt-get clean
 ---> Using cache
 ---> 2370b231b67f
Step 5/6 : RUN git clone https://github.com/containers/skopeo/  $GOPATH/src/github.com/containers/skopeo   && cd $GOPATH/src/github.com/containers/skopeo && git checkout ${SKOPEO_COMMIT} &&  make binary-local BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub'   && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo
 ---> Running in 053daebcfc44
Cloning into '/go/src/github.com/containers/skopeo'...
Note: checking out 'be6146b0a8471b02e776134119a2c37dfb70d414'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at be6146b0 release skopeo v0.1.40
GO111MODULE=on go build -mod=vendor "-buildmode=pie" -ldflags "-X main.gitCommit=be6146b0a8471b02e776134119a2c37dfb70d414" -gcflags "" -tags "containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub" -o skopeo ./cmd/skopeo
build github.com/containers/skopeo/cmd/skopeo: cannot load github.com/containers/image/v5/storage: no Go source files
make: *** [Makefile:104: binary-local] Error 1
The command '/bin/sh -c git clone https://github.com/containers/skopeo/  $GOPATH/src/github.com/containers/skopeo   && cd $GOPATH/src/github.com/containers/skopeo && git checkout ${SKOPEO_COMMIT} &&  make binary-local BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub'   && cp $GOPATH/src/github.com/containers/skopeo/skopeo /usr/bin/skopeo' returned a non-zero code: 2
C

How would the build tags be needed if the make file will dynamically handle it for you?

@vrothberg
Copy link
Member

How would the build tags be needed if the make file will dynamically handle it for you?

Some are not dynamically set (e.g., containers_image_openpgp).

build github.com/containers/skopeo/cmd/skopeo: cannot load github.com/containers/image/v5/storage: no Go source files

Curious, this error only occurs when "containers_image_ostree_stub" is specified twice in the build tags. It should work when removing the redundant tag from the Dockerfile. I can't tell you why go behaves this way; never seen it before.

Does that fix your issue?

@darewreck54
Copy link
Author

darewreck54 commented Dec 7, 2019

@vrothberg How is "containers_image_ostree_stub" specified twice in the build tags?

BUILDTAGS='containers_image_openpgp containers_image_ostree_stub containers_image_storage_stub'

I'm seeing three different build tags? It's also strange because this worked before unless it suddenly became non dynamic?

Also if I don't include those build tags, would the functionality be the same if it's already installed into the system?

@vrothberg
Copy link
Member

@darewreck54, thanks for double checking. You're absolutely correct!

The build fails because containers_image_storage_stub is set, and skopeo has direct reference on c/image/v5/storage. I'll prepare a fix for it.

vrothberg added a commit to vrothberg/skopeo that referenced this issue Dec 9, 2019
Remove a direct reference on c/image/v5/storage which breaks the build
when using the `containers_image_storage_stub`.  The reference is only
used to get the storage tranport string, which is now hard-coded; this
is fine as the transport will not change for backwards compat.

Fixes: containers#771
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
vrothberg added a commit to vrothberg/skopeo that referenced this issue Dec 9, 2019
Remove a direct reference on c/image/v5/storage which breaks the build
when using the `containers_image_storage_stub`.  The reference is only
used to get the storage tranport string, which is now hard-coded; this
is fine as the transport will not change for backwards compat.

Fixes: containers#771
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
vrothberg added a commit to vrothberg/skopeo that referenced this issue Dec 9, 2019
Remove a direct reference on c/image/v5/storage which breaks the build
when using the `containers_image_storage_stub`.  The reference is only
used to get the storage tranport string, which is now hard-coded; this
is fine as the transport will not change for backwards compat.

Fixes: containers#771
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
vrothberg added a commit that referenced this issue Dec 9, 2019
Remove a direct reference on c/image/v5/storage which breaks the build
when using the `containers_image_storage_stub`.  The reference is only
used to get the storage tranport string, which is now hard-coded; this
is fine as the transport will not change for backwards compat.

Fixes: #771
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants