diff --git a/Dockerfile b/Dockerfile index 8b8099e10..21e090db3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ARG BUILD_DEBIAN_VERSION=slim-stretch ARG RUNTIME_ALPINE_VERSION=3.11.5 ARG RUNTIME_DEBIAN_VERSION=stretch-20200414-slim -ARG BUILD_PLATFORM=alpine +ARG DISTRO=alpine FROM docker:${DOCKER_VERSION} AS docker-cli @@ -40,15 +40,14 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ openssl \ zlib1g-dev -FROM build-${BUILD_PLATFORM} AS build -COPY docker-compose-entrypoint.sh /usr/local/bin/ +FROM build-${DISTRO} AS build ENTRYPOINT ["sh", "/usr/local/bin/docker-compose-entrypoint.sh"] -COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker WORKDIR /code/ +COPY docker-compose-entrypoint.sh /usr/local/bin/ +COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker RUN pip install \ virtualenv==20.0.30 \ tox==3.19.0 - COPY requirements-dev.txt . COPY requirements-indirect.txt . COPY requirements.txt . @@ -64,9 +63,14 @@ ARG GIT_COMMIT=unknown ENV DOCKER_COMPOSE_GITSHA=$GIT_COMMIT RUN script/build/linux-entrypoint +FROM scratch AS bin +ARG TARGETARCH +ARG TARGETOS +COPY --from=build /usr/local/bin/docker-compose /docker-compose-${TARGETOS}-${TARGETARCH} + FROM alpine:${RUNTIME_ALPINE_VERSION} AS runtime-alpine FROM debian:${RUNTIME_DEBIAN_VERSION} AS runtime-debian -FROM runtime-${BUILD_PLATFORM} AS runtime +FROM runtime-${DISTRO} AS runtime COPY docker-compose-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["sh", "/usr/local/bin/docker-compose-entrypoint.sh"] COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker diff --git a/Jenkinsfile b/Jenkinsfile index 127a26c7f..4c7709103 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,9 @@ pipeline { timeout(time: 2, unit: 'HOURS') timestamps() } + environment { + DOCKER_BUILDKIT="1" + } stages { stage('Build test images') { @@ -69,7 +72,7 @@ def buildImage(baseImage) { ansiColor('xterm') { sh """docker build -t ${imageName} \\ --target build \\ - --build-arg BUILD_PLATFORM="${baseImage}" \\ + --build-arg DISTRO="${baseImage}" \\ --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT}" \\ .\\ """ diff --git a/Release.Jenkinsfile b/Release.Jenkinsfile index 1594d2f27..91cd89284 100644 --- a/Release.Jenkinsfile +++ b/Release.Jenkinsfile @@ -13,6 +13,9 @@ pipeline { timeout(time: 2, unit: 'HOURS') timestamps() } + environment { + DOCKER_BUILDKIT="1" + } stages { stage('Build test images') { @@ -229,7 +232,7 @@ def buildImage(baseImage) { ansiColor('xterm') { sh """docker build -t ${imageName} \\ --target build \\ - --build-arg BUILD_PLATFORM="${baseImage}" \\ + --build-arg DISTRO="${baseImage}" \\ --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT}" \\ .\\ """ @@ -276,7 +279,7 @@ def buildRuntimeImage(baseImage) { def imageName = "docker/compose:${baseImage}-${env.BRANCH_NAME}" ansiColor('xterm') { sh """docker build -t ${imageName} \\ - --build-arg BUILD_PLATFORM="${baseImage}" \\ + --build-arg DISTRO="${baseImage}" \\ --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT.take(7)}" \\ . """ diff --git a/script/build/linux b/script/build/linux index ca5620b85..2e56b625c 100755 --- a/script/build/linux +++ b/script/build/linux @@ -5,14 +5,12 @@ set -ex ./script/clean DOCKER_COMPOSE_GITSHA="$(script/build/write-git-sha)" -TAG="docker/compose:tmp-glibc-linux-binary-${DOCKER_COMPOSE_GITSHA}" -docker build -t "${TAG}" . \ - --build-arg BUILD_PLATFORM=debian \ - --build-arg GIT_COMMIT="${DOCKER_COMPOSE_GITSHA}" -TMP_CONTAINER=$(docker create "${TAG}") -mkdir -p dist +docker build . \ + --target bin \ + --build-arg DISTRO=debian \ + --build-arg GIT_COMMIT="${DOCKER_COMPOSE_GITSHA}" \ + --output dist/ ARCH=$(uname -m) -docker cp "${TMP_CONTAINER}":/usr/local/bin/docker-compose "dist/docker-compose-Linux-${ARCH}" -docker container rm -f "${TMP_CONTAINER}" -docker image rm -f "${TAG}" +# Ensure that we output the binary with the same name as we did before +mv dist/docker-compose-linux-amd64 "dist/docker-compose-Linux-${ARCH}" diff --git a/script/build/test-image b/script/build/test-image index 4964a5f9d..ddb8057d0 100755 --- a/script/build/test-image +++ b/script/build/test-image @@ -13,6 +13,6 @@ IMAGE="docker/compose-tests" DOCKER_COMPOSE_GITSHA="$(script/build/write-git-sha)" docker build -t "${IMAGE}:${TAG}" . \ --target build \ - --build-arg BUILD_PLATFORM="debian" \ + --build-arg DISTRO="debian" \ --build-arg GIT_COMMIT="${DOCKER_COMPOSE_GITSHA}" docker tag "${IMAGE}":"${TAG}" "${IMAGE}":latest