diff --git a/Jenkinsfile b/Jenkinsfile index 84bc6d9103..28a69b9c98 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -298,8 +298,8 @@ pipeline { } stage("Build & test a static Linux binary") { agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\'" } @@ -322,8 +322,8 @@ pipeline { stage("Build & test a static Linux mips64el binary") { when { anyOf { buildingTag(); branch 'master' } } agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\' -v /var/run/docker.sock:/var/run/docker.sock" } @@ -347,8 +347,8 @@ pipeline { stage("Build & test a static Linux ppc64el binary") { when { anyOf { buildingTag(); branch 'master' } } agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\' -v /var/run/docker.sock:/var/run/docker.sock" } @@ -372,8 +372,8 @@ pipeline { stage("Build & test a static Linux s390x binary") { when { anyOf { buildingTag(); branch 'master' } } agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\' -v /var/run/docker.sock:/var/run/docker.sock" } @@ -396,8 +396,8 @@ pipeline { stage("Build & test a static Linux arm64 binary") { agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\' -v /var/run/docker.sock:/var/run/docker.sock" } @@ -421,8 +421,8 @@ pipeline { stage("Build & test a static Linux armhf binary") { when { anyOf { buildingTag(); branch 'master' } } agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\' -v /var/run/docker.sock:/var/run/docker.sock" } @@ -446,8 +446,8 @@ pipeline { stage("Build & test a static Linux armel binary") { when { anyOf { buildingTag(); branch 'master' } } agent { - dockerfile { - filename 'docker/static/Dockerfile' + docker { + image 'andrjohns/stanc3-building:static' //Forces image to ignore entrypoint args "-u 1000 --entrypoint=\'\' -v /var/run/docker.sock:/var/run/docker.sock" } diff --git a/docker/multiarch/README.md b/docker/multiarch/README.md index 51e5e8deec..b7030b22d8 100644 --- a/docker/multiarch/README.md +++ b/docker/multiarch/README.md @@ -44,5 +44,5 @@ Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, Call `buildx` with the list of target architectures and target repository (note this requires calling `docker login` first) ``` -docker buildx build -t andrjohns/stanc3-building:latest --platform linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/mips64le,linux/s390x --push . +docker buildx build -t andrjohns/stanc3-building:multiarch --platform linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/mips64le,linux/s390x --push . ``` \ No newline at end of file diff --git a/docker/static/Dockerfile b/docker/static/Dockerfile index 144776d2ca..840635cd39 100644 --- a/docker/static/Dockerfile +++ b/docker/static/Dockerfile @@ -21,6 +21,12 @@ LABEL distro_style="apk" #Install os dependencies RUN apk update && apk add build-base bzip2 git tar curl ca-certificates openssl m4 bash +# Add a recent version of the Skopeo package, which is used for looking up the correct multiarch docker image +RUN curl https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/x86_64/containers-common-0.38.11-r0.apk -o cont.apk && \ + curl https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/x86_64/skopeo-1.3.1-r1.apk -o skopeo.apk && \ + apk add cont.apk && \ + apk add skopeo.apk + #Switch back to the normal user USER opam diff --git a/scripts/build_multiarch_stanc3.sh b/scripts/build_multiarch_stanc3.sh index 4d210018f8..a3de36d949 100644 --- a/scripts/build_multiarch_stanc3.sh +++ b/scripts/build_multiarch_stanc3.sh @@ -19,22 +19,14 @@ elif [ $1 = "s390x" ]; then export DOCK_VARIANT="" fi -# Need to use the sha256 tag to force docker to download an architecture that differs from the host -# We'll use the skopeo package to lookup the most recent tag, but need to manually install a more recent version -curl https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/x86_64/containers-common-0.38.11-r0.apk -o cont.apk -curl https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/x86_64/skopeo-1.3.1-r0.apk -o skopeo.apk - -apk add cont.apk -apk add skopeo.apk - # Lookup the sha256 hash for the specified architecture and variant (e.g., v7 for armhf) and strip the enclosing quotations -SHA=$(skopeo inspect --raw docker://andrjohns/stanc3-building:latest | jq '.manifests | .[] | select(.platform.architecture==env.DOCK_ARCH and .platform.variant==(if env.DOCK_VARIANT == "" then null else env.DOCK_VARIANT end)).digest' | tr -d '"') +SHA=$(skopeo inspect --raw docker://andrjohns/stanc3-building:multiarch | jq '.manifests | .[] | select(.platform.architecture==env.DOCK_ARCH and .platform.variant==(if env.DOCK_VARIANT == "" then null else env.DOCK_VARIANT end)).digest' | tr -d '"') # Register QEMU translation binaries docker run --rm --privileged multiarch/qemu-user-static --reset # Run docker, inheriting mounted volumes from sibling container (including stanc3 directory), and build stanc3 -docker run --volumes-from=$(docker ps -q):rw andrjohns/stanc3-building:latest@$SHA /bin/bash -c "cd $(pwd) && eval \$(opam env) && dune build @install --profile static" +docker run --volumes-from=$(docker ps -q):rw andrjohns/stanc3-building:multiarch@$SHA /bin/bash -c "cd $(pwd) && eval \$(opam env) && dune build @install --profile static" # Update ownership of build folders chown -R opam: _build