Skip to content

Commit 5b853cf

Browse files
authored
build and push e2e images as multiarch (#229)
* build and push e2e images as multiarch Signed-off-by: Jan Wozniak <wozniak.jan@gmail.com> * k6-runner fix Signed-off-by: Jan Wozniak <wozniak.jan@gmail.com> --------- Signed-off-by: Jan Wozniak <wozniak.jan@gmail.com>
1 parent 8f3801e commit 5b853cf

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,11 @@ jobs:
2929
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
3030
run: echo $DOCKER_HUB_ACCESS_TOKEN | docker login -u $DOCKER_HUB_USERNAME --password-stdin
3131

32+
- name: Set up QEMU
33+
uses: docker/setup-qemu-action@v2
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v2
37+
3238
- name: e2e-images
3339
run: make e2e-images

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ build-e2e-images:
2020
IMAGE_TAG=$(IMAGE_TAG) ./e2e/images/build.sh
2121

2222
push-e2e-images:
23-
IMAGE_TAG=$(IMAGE_TAG) ./e2e/images/build.sh --push
23+
IMAGE_TAG=$(IMAGE_TAG) ./e2e/images/build.sh --push --platform ${BUILD_PLATFORMS}
2424

2525
##################################################
2626
# tools image #

e2e/images/apache-ab/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine
1+
FROM --platform=${BUILDPLATFORM} alpine
22

33
ENV TERM linux
44
RUN apk --no-cache add apache2-utils

e2e/images/build.sh

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
11
#! /bin/bash
2-
set -e
2+
set -euo pipefail
3+
4+
# not all images can be built as multiarch at the moment
5+
# here is a list of images that must be multiarch for e2e tests to pass
6+
declare -A build_as_multiarch=(
7+
["apache-ab"]=true
8+
["websockets"]=true
9+
)
310

411
DIR=$(dirname "$0")
512

6-
if [ -z "$IMAGE_TAG" ]
7-
then
13+
if [[ -z "${IMAGE_TAG:-}" ]]; then
814
IMAGE_TAG=latest
915
fi
1016

17+
options=$(getopt -l "push,platform:" -o "p,x:" -- "$@")
18+
eval set -- "$options"
19+
20+
PUSH=false
21+
PLATFORM=""
22+
while true; do
23+
case "$1" in
24+
-p|--push) PUSH=true; shift ;;
25+
-x|--platform) PLATFORM="$2"; shift 2 ;;
26+
--) shift; break ;;
27+
*) echo "Invalid option: $1" >&2; exit 1 ;;
28+
esac
29+
done
30+
1131
cd $DIR
1232

13-
if [ "$1" == "--push" ]
14-
then
15-
for IMAGE_NAME in $(find * -name Dockerfile -exec dirname {} \; | tr '/' '-')
16-
do
17-
docker image push -a ghcr.io/kedacore/tests-$IMAGE_NAME
33+
if [[ "$PUSH" == true ]]; then
34+
for IMAGE in $(find * -name Dockerfile); do
35+
IMAGE_NAME=$(dirname $IMAGE | tr '/' '-')
36+
if [[ "$PLATFORM" != "" && "${build_as_multiarch[$IMAGE_NAME]:-false}" == true ]]; then
37+
echo "building and pushing $IMAGE_NAME from $IMAGE for $PLATFORM"
38+
docker buildx build --push --platform "$PLATFORM" -t "ghcr.io/kedacore/tests-$IMAGE_NAME" ./$IMAGE
39+
else
40+
echo "building and pushing $IMAGE_NAME"
41+
docker image push -a ghcr.io/kedacore/tests-$IMAGE_NAME
42+
fi
1843
done
1944
else
20-
for IMAGE in $(find * -name Dockerfile)
21-
do
45+
for IMAGE in $(find * -name Dockerfile); do
2246
IMAGE_NAME=$(dirname $IMAGE | tr '/' '-')
2347
pushd $(dirname $IMAGE)
2448
docker build --label "org.opencontainers.image.source=https://github.com/kedacore/test-tools" -t ghcr.io/kedacore/tests-$IMAGE_NAME:$IMAGE_TAG -t ghcr.io/kedacore/tests-$IMAGE_NAME:latest .

e2e/images/websockets/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:22.12.0
1+
FROM --platform=${BUILDPLATFORM} node:22.12.0
22

33
WORKDIR /usr/src/app
44

k6-runner/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
FROM --platform=${BUILDPLATFORM} golang:1.23-alpine3.19 as builder
1+
FROM --platform=${BUILDPLATFORM} golang:1.24-alpine3.22 AS builder
22
WORKDIR $GOPATH/src/go.k6.io/k6
33
RUN apk --no-cache add git
44

55
ARG TARGETOS
66
ARG TARGETARCH
77
ARG K6_VERSION
88
RUN go install go.k6.io/xk6/cmd/xk6@latest
9-
RUN GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" xk6 build "${K6_VERSION}" \
9+
RUN GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" xk6 build \
10+
--k6-version "${K6_VERSION}" \
1011
--output /tmp/k6 \
1112
--with github.com/grafana/xk6-kubernetes@latest \
1213
--with github.com/grafana/xk6-disruptor@latest \

0 commit comments

Comments
 (0)