Skip to content

Commit

Permalink
Merge pull request #972 from andrjohns/feature/fix-multiarch
Browse files Browse the repository at this point in the history
Fix multiarch stanc3 builds
  • Loading branch information
rok-cesnovar authored Sep 24, 2021
2 parents c320318 + c85c520 commit e24f003
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
28 changes: 14 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=\'\'"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion docker/multiarch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
```
6 changes: 6 additions & 0 deletions docker/static/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 2 additions & 10 deletions scripts/build_multiarch_stanc3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e24f003

Please sign in to comment.