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

ci: Fix building disabled containers #44346

Closed
wants to merge 1 commit into from

Conversation

kallisti5
Copy link
Contributor

Working on a new CI platform and noticed building disabled containers is broken. (looking at the shell script, it appears being able to build disabled containers is desired)

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@arielb1
Copy link
Contributor

arielb1 commented Sep 5, 2017

r? @aidanhs (I think)

@arielb1 arielb1 assigned aidanhs and unassigned nikomatsakis Sep 5, 2017
@arielb1 arielb1 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 5, 2017
@aidanhs
Copy link
Member

aidanhs commented Sep 5, 2017

Unfortunately this isn't right. A lot of these dockerfiles reference things in scripts when copying:

rust/src/ci/docker/disabled $ grep -r ^COPY * | head -n3
aarch64-gnu/Dockerfile:COPY disabled/aarch64-gnu/config /build/.config
aarch64-gnu/Dockerfile:COPY scripts/qemu-bare-bones-rcS rootfs/etc/init.d/rcS
aarch64-gnu/Dockerfile:COPY scripts/qemu-bare-bones-addentropy.c /tmp/addentropy.c

But scripts is not present in the disabled directory, so we need to sent the whole src/ci/docker context to the docker daemon. Instead, you should explicitly reference the disabled directory, as shown in the first line of the grep above (I realise this is a little annoying).

@kallisti5
Copy link
Contributor Author

That's all kind of silly. Would you support adjusting all the disabled Dockerfiles to properly have context within the disabled directory? That would make them portable between disabled and the normal path.

@aidanhs
Copy link
Member

aidanhs commented Sep 6, 2017

Sure. I think you'd just be able to generate a 'unified tar' combining both directories on the fly, unless you have something else in mind?

@kallisti5
Copy link
Contributor Author

Couldn't the rest of the Dockerfiles in disabled omit "disabled" from the source COPY path?

@kallisti5
Copy link
Contributor Author

aka, see latest changeset :-) Only two of the containers even specified disabled... the rest omit it. Now you can copy containers into the disabled directory, but still test them locally outside of travis.

@kallisti5
Copy link
Contributor Author

kallisti5 commented Sep 7, 2017

Hm. Some of the containers use the common scripts though which don't exist within the disabled context. I've put in a solution to this by git ignoring scripts within the disabled directory and copying the common set over during the container build, then removing them again post-build (only when building disabled containers). Not the cleanest, but I don't know of a way to add multiple contexts.

@aidanhs
Copy link
Member

aidanhs commented Sep 7, 2017

Ah so my suggestion is to generate the context by merging the directories on the fly with tar. For example:

$ ls *
a

disabled:
b
$ tar --transform 's/^disabled\///' -c * | tar t
a
disabled/
b

i.e. the transform option has moved everything upwards out of the disabled directory. You can pipe a tar to the stdin of docker build and it'll accept it as a context.

@kallisti5
Copy link
Contributor Author

Ah. I understand now. So I started in on these changes, but docker doesn't seem too happy about it:

:) $ ./run.sh dist-x86_64-redox
+++ dirname ./run.sh
++ cd .
++ pwd
++ basename ./run.sh
+ script=/home/kallisti5/Code/rust/src/ci/docker/run.sh
+ image=dist-x86_64-redox
++ dirname /home/kallisti5/Code/rust/src/ci/docker/run.sh
+ docker_dir=/home/kallisti5/Code/rust/src/ci/docker
++ dirname /home/kallisti5/Code/rust/src/ci/docker
+ ci_dir=/home/kallisti5/Code/rust/src/ci
++ dirname /home/kallisti5/Code/rust/src/ci
+ src_dir=/home/kallisti5/Code/rust/src
++ dirname /home/kallisti5/Code/rust/src
+ root_dir=/home/kallisti5/Code/rust
+ source /home/kallisti5/Code/rust/src/ci/shared.sh
++ declare -F travis_fold
++ '[' false = true ']'
+ travis_fold start build_docker
+ return 0
+ travis_time_start
+ return 0
+ '[' -f /home/kallisti5/Code/rust/src/ci/docker/dist-x86_64-redox/Dockerfile ']'
+ '[' -f /home/kallisti5/Code/rust/src/ci/docker/disabled/dist-x86_64-redox/Dockerfile ']'
+ '[' -n '' ']'
+ retry tar --transform 's/^\.\/disabled\//.\//' -C /home/kallisti5/Code/rust/src/ci/docker -c .
+ echo 'Attempting with retry:' tar --transform 's/^\.\/disabled\//.\//' -C /home/kallisti5/Code/rust/src/ci/docker -c .
+ docker build --rm -t rust-ci -f /home/kallisti5/Code/rust/src/ci/docker/disabled/dist-x86_64-redox/Dockerfile -
+ local n=1
+ local max=5
+ true
+ tar --transform 's/^\.\/disabled\//.\//' -C /home/kallisti5/Code/rust/src/ci/docker -c .
+ break
Sending build context to Docker daemon 503.8 kB
Error response from daemon: Unknown instruction: ATTEMPTING
$ tar --transform 's/^\.\/disabled\//.\//' -C /home/kallisti5/Code/rust/src/ci/docker -c . | tar t
./
./README.md
./arm-android/
./arm-android/Dockerfile
./armhf-gnu/
./armhf-gnu/vexpress_config
./armhf-gnu/Dockerfile
./asmjs/
./asmjs/Dockerfile
./cross/
./cross/build-arm-musl.sh
./cross/build-rumprun.sh
./cross/install-mips-musl.sh
./cross/install-mipsel-musl.sh
./cross/install-x86_64-redox.sh
./cross/Dockerfile
./disabled/
./aarch64-gnu/
./aarch64-gnu/config
./aarch64-gnu/Dockerfile
./dist-aarch64-android/
./dist-aarch64-android/Dockerfile
./dist-armv7-android/
./dist-armv7-android/Dockerfile
./dist-i686-android/
./dist-i686-android/Dockerfile
./dist-x86_64-android/
./dist-x86_64-android/Dockerfile
./dist-x86_64-redox/
./dist-x86_64-redox/Dockerfile
./wasm32-exp/
./wasm32-exp/node.sh
./wasm32-exp/Dockerfile
./wasm32/
./wasm32/Dockerfile
./scripts/
./scripts/android-base-apt-get.sh
./scripts/android-ndk.sh
./scripts/android-sdk.sh
./scripts/android-start-emulator.sh
./scripts/cross-apt-packages.sh
./scripts/crosstool-ng.sh
./scripts/emscripten.sh
./scripts/emscripten-wasm.sh
./scripts/make3.sh
./scripts/qemu-bare-bones-addentropy.c
./scripts/qemu-bare-bones-rcS
./scripts/rustbuild-setup.sh
./scripts/sccache.sh
./.gitignore
./dist-aarch64-linux/
./dist-aarch64-linux/aarch64-linux-gnu.config
./dist-aarch64-linux/build-toolchains.sh
./dist-aarch64-linux/Dockerfile
./dist-android/
./dist-android/Dockerfile
./dist-arm-linux/
./dist-arm-linux/arm-linux-gnueabi.config
./dist-arm-linux/build-toolchains.sh
./dist-arm-linux/Dockerfile
./dist-armhf-linux/
./dist-armhf-linux/arm-linux-gnueabihf.config
./dist-armhf-linux/build-toolchains.sh
./dist-armhf-linux/Dockerfile
./dist-armv7-linux/
./dist-armv7-linux/armv7-linux-gnueabihf.config
./dist-armv7-linux/build-toolchains.sh
./dist-armv7-linux/Dockerfile
./dist-fuchsia/
./dist-fuchsia/build-toolchain.sh
./dist-fuchsia/compiler-rt-dso-handle.patch
./dist-fuchsia/shared.sh
./dist-fuchsia/Dockerfile
./dist-i586-gnu-i686-musl/
./dist-i586-gnu-i686-musl/build-musl.sh
./dist-i586-gnu-i686-musl/musl-libunwind-patch.patch
./dist-i586-gnu-i686-musl/Dockerfile
./dist-i686-freebsd/
./dist-i686-freebsd/build-toolchain.sh
./dist-i686-freebsd/Dockerfile
./dist-i686-linux/
./dist-i686-linux/build-binutils.sh
./dist-i686-linux/build-cmake.sh
./dist-i686-linux/build-curl.sh
./dist-i686-linux/build-gcc.sh
./dist-i686-linux/build-git.sh
./dist-i686-linux/build-headers.sh
./dist-i686-linux/build-openssl.sh
./dist-i686-linux/build-python.sh
./dist-i686-linux/shared.sh
./dist-i686-linux/Dockerfile
./dist-mips-linux/
./dist-mips-linux/Dockerfile
./dist-mips64-linux/
./dist-mips64-linux/Dockerfile
./dist-mips64el-linux/
./dist-mips64el-linux/Dockerfile
./dist-mipsel-linux/
./dist-mipsel-linux/Dockerfile
./dist-powerpc-linux/
./dist-powerpc-linux/build-powerpc-toolchain.sh
./dist-powerpc-linux/patches/
./dist-powerpc-linux/patches/glibc/
./dist-powerpc-linux/patches/glibc/2.12.2/
./dist-powerpc-linux/patches/glibc/2.12.2/001-PowerPC-Remove-unnecessary-mnew-mnemonics.patch
./dist-powerpc-linux/powerpc-linux-gnu.config
./dist-powerpc-linux/Dockerfile
./dist-powerpc64-linux/
./dist-powerpc64-linux/build-powerpc64-toolchain.sh
./dist-powerpc64-linux/patches/
./dist-powerpc64-linux/patches/glibc/
./dist-powerpc64-linux/patches/glibc/2.12.2/
./dist-powerpc64-linux/patches/glibc/2.12.2/001-PowerPC-Remove-unnecessary-mnew-mnemonics.patch
./dist-powerpc64-linux/patches/glibc/2.12.2/002-Prevent-inlining-in-PPC64-initfini.s.patch
./dist-powerpc64-linux/powerpc64-linux-gnu.config
./dist-powerpc64-linux/shared.sh
./dist-powerpc64-linux/Dockerfile
./dist-powerpc64le-linux/
./dist-powerpc64le-linux/build-powerpc64le-toolchain.sh
./dist-powerpc64le-linux/shared.sh
./dist-powerpc64le-linux/Dockerfile
./dist-s390x-linux/
./dist-s390x-linux/build-s390x-toolchain.sh
./dist-s390x-linux/patches/
./dist-s390x-linux/patches/glibc/
./dist-s390x-linux/patches/glibc/2.12.2/
./dist-s390x-linux/patches/glibc/2.12.2/001-Use-.machine-to-prevent-AS-from-complaining-about-z9.patch
./dist-s390x-linux/s390x-linux-gnu.config
./dist-s390x-linux/Dockerfile
./dist-x86_64-freebsd/
./dist-x86_64-freebsd/build-toolchain.sh
./dist-x86_64-freebsd/Dockerfile
./dist-x86_64-linux/
./dist-x86_64-linux/build-binutils.sh
./dist-x86_64-linux/build-cmake.sh
./dist-x86_64-linux/build-curl.sh
./dist-x86_64-linux/build-gcc.sh
./dist-x86_64-linux/build-git.sh
./dist-x86_64-linux/build-headers.sh
./dist-x86_64-linux/build-openssl.sh
./dist-x86_64-linux/build-python.sh
./dist-x86_64-linux/shared.sh
./dist-x86_64-linux/Dockerfile
./dist-x86_64-musl/
./dist-x86_64-musl/build-musl.sh
./dist-x86_64-musl/Dockerfile
./dist-x86_64-netbsd/
./dist-x86_64-netbsd/build-netbsd-toolchain.sh
./dist-x86_64-netbsd/Dockerfile
./i686-gnu-nopt/
./i686-gnu-nopt/Dockerfile
./i686-gnu/
./i686-gnu/Dockerfile
./scripts/
./scripts/android-base-apt-get.sh
./scripts/android-ndk.sh
./scripts/android-sdk.sh
./scripts/android-start-emulator.sh
./scripts/cross-apt-packages.sh
./scripts/crosstool-ng.sh
./scripts/emscripten-wasm.sh
./scripts/emscripten.sh
./scripts/make3.sh
./scripts/qemu-bare-bones-addentropy.c
./scripts/qemu-bare-bones-rcS
./scripts/rustbuild-setup.sh
./scripts/sccache.sh
./x86_64-gnu-aux/
./x86_64-gnu-aux/Dockerfile
./x86_64-gnu-debug/
./x86_64-gnu-debug/Dockerfile
./x86_64-gnu-distcheck/
./x86_64-gnu-distcheck/Dockerfile
./x86_64-gnu-full-bootstrap/
./x86_64-gnu-full-bootstrap/Dockerfile
./x86_64-gnu-incremental/
./x86_64-gnu-incremental/Dockerfile
./x86_64-gnu-llvm-3.7/
./x86_64-gnu-llvm-3.7/Dockerfile
./x86_64-gnu-nopt/
./x86_64-gnu-nopt/Dockerfile
./x86_64-gnu/
./x86_64-gnu/Dockerfile
./run.sh
if [ -f "$docker_dir/$image/Dockerfile" ]; then
    retry docker \
      build \
      --rm \
      -t rust-ci \
      -f "$docker_dir/$image/Dockerfile" \
      "$docker_dir"
elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then
    if [ -n "$TRAVIS_OS_NAME" ]; then
        echo Cannot run disabled images on travis!
        exit 1
    fi
    retry tar --transform 's/^\.\/disabled\//.\//' -C $docker_dir -c . | docker \
      build \
      --rm \
      -t rust-ci \
      -f "$docker_dir/disabled/$image/Dockerfile" \
      -
else
    echo Invalid image: $image
    exit 1
fi

@aidanhs
Copy link
Member

aidanhs commented Sep 11, 2017

Ok, the problem is that the retry shell function is printing to stdout and interfering with the stdout from tar. It doesn't make sense to retry just the tar anyway, you need to retry the whole sequence.

You could fix it to work with retry (with bash -c), but it'd be ugly and these will all be run manually anyway so let's just remove retry and add a comment explicitly noting there's no retry because this isn't run in CI.

* Change the context into the disabled directory. Now you can test
  containers which are disabled.
@kallisti5
Copy link
Contributor Author

Latest PR works great. Good idea on the tar transform.

@@ -36,12 +36,13 @@ elif [ -f "$docker_dir/disabled/$image/Dockerfile" ]; then
echo Cannot run disabled images on travis!
exit 1
fi
retry docker \
# retry messes with the pipe from tar to docker. Not needed on non-travis
tar --transform 's/^\.\/disabled\//.\//' -C $docker_dir -c . | docker \
Copy link
Member

@aidanhs aidanhs Sep 13, 2017

Choose a reason for hiding this comment

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

The transform looks right, but it generates a very strange path for the dockerfile for me if you pipe it to tar t - .\\/Dockerfile. All of the backslashes are a bit crazy anyway, can you make # the escape character? i.e. s#^\./a/#./#'

Additionally, can you add a brief description line of what we're doing here? E.g. something like "The tar transform below makes the images in the disabled directory look like they're in the main images directory to docker build."

@carols10cents carols10cents added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 18, 2017
@alexcrichton
Copy link
Member

ping @kallisti5, just want to make sure this doesn't fall off your radar!

@alexcrichton
Copy link
Member

Ok I'm going to close this out of inactivity, but feel free to resubmit @kallisti5!

@kallisti5
Copy link
Contributor Author

kallisti5 commented Sep 28, 2017

I'm super confused on this one. So all that needs to be changed is

  1. the "normal \ escape character needs modified to a non-standard # character?"
  2. add a comment explaining the need for tar.

2 is fine
1 is a bit silly. Why would using a non-standard escape character make the regex "more readable"?

@kallisti5
Copy link
Contributor Author

Resubmitted in #44903 Just getting frustrated that i've refined these 6 lines so many times across so many PR's :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants