Add docker multiplatform buildx contrib

This commit is contained in:
lepapareil 2023-09-05 18:42:25 +02:00 committed by hurl-bot
parent 7d8cc1edac
commit e3bc7a2c64
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
2 changed files with 73 additions and 2 deletions

View File

@ -1,13 +1,18 @@
FROM alpine:3.17 AS builder FROM --platform=$TARGETPLATFORM alpine:3.17 AS builder
ARG TARGETPLATFORM
WORKDIR /tmp/hurl-docker WORKDIR /tmp/hurl-docker
COPY . /tmp/hurl-docker COPY . /tmp/hurl-docker
# hadolint ignore=DL3018 # hadolint ignore=DL3018
RUN apk add --no-cache bash git && \ RUN apk add --no-cache bash git && \
if [ "${TARGETPLATFORM}" = "linux/arm64" ] ; then \
apk add --no-cache -y g++-aarch64-linux-gnu libc6-dev-arm64-cross ; \
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" ; \
fi ; \
bash -c bin/install_prerequisites_alpine.sh && \ bash -c bin/install_prerequisites_alpine.sh && \
bash -c bin/install_rust.sh && \ bash -c bin/install_rust.sh && \
bash -c ./bin/release/release.sh bash -c ./bin/release/release.sh
FROM alpine:3.17 AS runner FROM --platform=$TARGETPLATFORM alpine:3.17 AS runner
ARG docker_build_date ARG docker_build_date
ARG docker_build_tag ARG docker_build_tag
LABEL "org.opencontainers.image.source"="https://github.com/Orange-OpenSource/hurl" LABEL "org.opencontainers.image.source"="https://github.com/Orange-OpenSource/hurl"
@ -34,3 +39,4 @@ COPY --from=builder /usr/lib/libgcc_s.so.* /usr/lib/
COPY --from=builder /usr/lib/liblzma.so.* /usr/lib/ COPY --from=builder /usr/lib/liblzma.so.* /usr/lib/
COPY --from=builder /usr/lib/libidn2.so.* /usr/lib/ COPY --from=builder /usr/lib/libidn2.so.* /usr/lib/
ENTRYPOINT ["/usr/bin/hurl"] ENTRYPOINT ["/usr/bin/hurl"]

View File

@ -138,3 +138,68 @@ docker manifest create \
docker manifest push ghcr.io/"${organisation}"/hurl:"${docker_build_tag}" docker manifest push ghcr.io/"${organisation}"/hurl:"${docker_build_tag}"
docker manifest push ghcr.io/"${organisation}"/hurl:latest docker manifest push ghcr.io/"${organisation}"/hurl:latest
``` ```
# Build multiplatform amd64 and arm64 with buildx
## Clone desired tag
```
tag=<desired tag, ex: 4.0.0>
organisation=<desired organisation in lowercase, ex: orange-opensource>
git clone --depth 1 https://github.com/"${organisation}"/hurl.git --branch "${tag}" /tmp/hurl-"${tag}"
```
## Prepare docker build env
```
docker system prune -fa
docker buildx prune -fa
docker buildx rm mybuilder
export DOCKER_CLI_EXPERIMENTAL=enabled
sudo apt-get install -y qemu-user-static
ls -l /usr/bin/qemu-aarch64-static
qemu-aarch64-static --version
sudo apt-get install -y binfmt-support
update-binfmts --version
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap
docker buildx ls
```
## Connect to github container registry
```
echo <hurl-bot github token> | docker login ghcr.io --username hurl-bot --password-stdin
```
## Build and push
```
cd /tmp/hurl-"${tag}"
docker_build_tag=$(grep ^version packages/hurl/Cargo.toml | cut --delimiter '=' --field 2 | tr -d '" ')
echo "docker_build_tag=${docker_build_tag}"
docker_build_date=$(date "+%Y-%m-%d %H-%M-%S")
echo "docker_build_date=${docker_build_date}"
docker buildx build --platform linux/amd64,linux/arm64 --file contrib/docker/Dockerfile --build-arg docker_build_date="${docker_build_date}" --build-arg docker_build_tag="${docker_build_tag}" --tag ghcr.io/"${organisation}"/hurl:"${docker_build_tag}" --push .
```
## Get docker hurl version
```
docker run --rm ghcr.io/"${organisation}"/hurl:"${docker_build_tag}" --version
```
## Run docker hurl from STDIN
```
echo -e "GET https://hurl.dev\n\nHTTP 200" | docker run --rm -i ghcr.io/"${organisation}"/hurl:"${docker_build_tag}" --test --color --very-verbose
```
## Run docker hurl from FILE
```
echo -e "GET https://hurl.dev\n\nHTTP 200" > /tmp/test.hurl
docker run --rm -v /tmp/test.hurl:/tmp/test.hurl ghcr.io/"${organisation}"/hurl:"${docker_build_tag}" --test --color --very-verbose /tmp/test.hurl
```