Skip to content

hack: update test dockerfiles to buildkit #666

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

Merged
merged 2 commits into from
Oct 11, 2018

Conversation

tonistiigi
Copy link
Member

Signed-off-by: Tonis Tiigi [email protected]

@tonistiigi
Copy link
Member Author

The main issue atm is that although the new dockerfile allows getting fast incremental builds, multi-platform releases of everything and integration test image very quickly there is no way to quickly run that image with privileges like the tests require. Only docker currently can do that, but docker does not have support for releasing the multi-arch release images needed in CI.

The options are:
a) load the integration test-integration image into Docker in CI. It is slow but ok for ci as it only happens once. For local development, we can use moby+buildkit by default.
b) Add more one-off execution features to buildkit. I think this is needed/useful for lots of things but don't have a specific plan yet.
c) Wait/carry #570 and execute in Dockerfile (or b)
d) Integrate with containerd in CI and try to use ctr. Probably complicated for local cases.
e) Build some stages twice in CI. Only release is done with buildctl.

Tend to think a is the best option atm.

@AkihiroSuda @tiborvass


# Rootless mode.
# Still requires `--privileged`.
FROM tonistiigi/buildkit:rootless-base AS rootless
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the rootless-base stage that built for all platforms so we can use cross-compilation on top of it. I can add a build arg to switch between this image and direct stage. eg. https://github.com/tonistiigi/copy/blob/master/Dockerfile#L3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, rootlesskit multi-platform is currently blocked with moby/datakit#638

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, didn't notice rootlesskit was vendoring datakit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the copy binary for rootless?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if node can run apk an all platforms. What travis can't. The difference is that tonistiigi/buildkit:rootless-base is already multi-platform so any node can add the missing binaries on top of that.

Also, FROM --platform=$TARGETPLATFORM alpine AS rootless-base is the same as FROM alpine AS rootless-base.

 # docker run --rm mplatform/mquery tonistiigi/buildkit:rootless-base
Image: tonistiigi/buildkit:rootless-base
 * Manifest List: Yes
 * Supported platforms:
   - linux/amd64
   - linux/arm/v6
   - linux/arm/v7
   - linux/arm64/undefined
   - linux/ppc64le
   - linux/s390x

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What travis can't.

Doesn't qemu-user binfmt work on Travis?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emulation is not that stable that we could trust it in here. Especially on power/s390x. Also, I'd expect this script to run anywhere, without requiring special setup or a new kernel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(haven't really tested if emultaion works at all on travis)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the following stuff to the comment lines of the Dockerfile:

  • image digest for reproducibility
  • how you built the image
  • background (can be just a link to this GitHub issue thread)

RUN apk add --no-cache git

# xgo is a helper for golang cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:golang AS xgo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's dockerfile for xx?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# available targets: buildkitd, buildkitd.oci_only, buildkitd.containerd_only
ARG BUILDKIT_TARGET=buildkitd
ARG REGISTRY_VERSION=2.6
ARG ROOTLESSKIT_VERSION=20b0fc24b305b031a61ef1a1ca456aadafaf5e77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d843aadf00d72082fd7a31572ef018d1e792535f

FROM git AS runc-src
ARG RUNC_VERSION
WORKDIR /usr/src
RUN git clone git://github.com/opencontainers/runc.git runc \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we experiment ADD git:// source op?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe FROM git:// ?

@AkihiroSuda
Copy link
Member

a) load the integration test-integration image into Docker in CI. It is slow but ok for ci as it only happens once. For local development, we can use moby+buildkit by default.

does nightly dind work?
https://hub.docker.com/r/tianon/docker-master/
https://github.com/tianon/dockerfiles/tree/master/docker-master

@tonistiigi
Copy link
Member Author

@AkihiroSuda With option a we can use any version of Docker. We would use buildctl to build everything and Docker only for running the test-integration image. For the opposite case, no version of moby currently supports building multi-platform images and it probably will not land before the containerd storage is integrated.

COPY --from=binaries / /usr/bin/
COPY . .

FROM rootless
Copy link
Member Author

@tonistiigi tonistiigi Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this stage (duplicate)

@tonistiigi tonistiigi force-pushed the dockerfile-update branch 5 times, most recently from 6186adb to 9487c77 Compare October 9, 2018 00:40
@tonistiigi tonistiigi force-pushed the dockerfile-update branch 3 times, most recently from 2e1ee93 to b59fa55 Compare October 9, 2018 06:33
@tonistiigi tonistiigi force-pushed the dockerfile-update branch 4 times, most recently from ef186c1 to 714ca48 Compare October 9, 2018 23:13
@tonistiigi
Copy link
Member Author

@AkihiroSuda Something really strange going on with rootless worker here that maybe you can look into. The new integration test image is based on stretch and it seems impossible to get it to pass before a timeout is reached. The oci-rootless tests are ~20x slower than before and I can reproduce locally with single tests. As soon as I switch the test stage to alpine the problem goes away and tests are fast again. Added a separate commit that patches alpine, to test the slow version just remove that commit.

data in https://gist.github.com/tonistiigi/a6f95f2527c8f284c3efa61bc8b4a972

@AkihiroSuda
Copy link
Member

This is because of

case <-time.After(20 * time.Second):
, but not sure why SIGTERM does not work here..

@AkihiroSuda
Copy link
Member

Could be some weird difference across Alpine sudo and Debian sudo

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AkihiroSuda
Copy link
Member

Mergeable?

@tonistiigi
Copy link
Member Author

@AkihiroSuda No, I'll still try to get rid of the alpine commit so we don't need to have two stacks of go.

@tonistiigi
Copy link
Member Author

@AkihiroSuda @tiborvass Ready now

case ${1:-} in
'')
. $(dirname $0)/util
gogo_version=$(awk '$1 == "github.com/gogo/protobuf" { print $2 }' vendor.conf)
case $buildmode in
"buildkit")
buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --frontend-opt build-arg:GOGO_VERSION=$gogo_version --frontend-opt filename=./hack/dockerfiles/generated-files.buildkit.Dockerfile
buildctl build $progressFlag --frontend=dockerfile.v0 --local context=. --local dockerfile=. --frontend-opt build-arg:GOGO_VERSION=$gogo_version --frontend-opt filename=./hack/dockerfiles/generated-files.buildkit.Dockerfile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$progressFlag should also go to docker build

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONTINUOUS_INTEGRATION is only set with buildctl

rm $tmpfile
;;
*)
case $buildmode in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this case $buildmode within the *) of a case $buildmode. Bad refactoring or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the * case is longer than inner switch

ARG ROOTLESS_BASE_MODE=external

# available targets: buildkitd, buildkitd.oci_only, buildkitd.containerd_only
ARG BUILDKIT_TARGET=buildkitd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

hack/binaries Outdated
if [ "$CONTINUOUS_INTEGRATION" == "true" ]; then progressFlag="--progress=plain"; fi

binariesLegacy() {
mkdir -p bin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation seems broken.

I'm not sure whether there is gofmt-equivalent for bash, but emacs can indent shell scripts with C-x h M-x indent.

@@ -154,7 +155,8 @@ FROM buildkit-buildkitd AS rootless
RUN apk add --no-cache shadow shadow-uidmap \
&& useradd --create-home --home-dir /home/user --uid 1000 user \
&& mkdir -p /run/user/1000 /home/user/.local/tmp /home/user/.local/share/buildkit \
&& chown -R user /run/user/1000 /home/user
&& chown -R user /run/user/1000 /home/user \
&& rm /bin/su && ln -s /bin/busybox /bin/su
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

3 participants