Skip to content

Commit 974228f

Browse files
committed
able to get docker built on local mac m1 #2422
1 parent e4395da commit 974228f

2 files changed

Lines changed: 41 additions & 26 deletions

File tree

build-docker.sh

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,51 @@ mvn clean test -B -ntp -f examples/gatling/pom.xml
1212

1313
# copy only karate jars to a place where the docker image build can add from
1414
KARATE_REPO=karate-docker/karate-chrome/target/repository/io/karatelabs
15-
mkdir -p ${KARATE_REPO}
16-
cp -r ~/.m2/repository/io/karatelabs ${KARATE_REPO}
15+
mkdir -p "${KARATE_REPO}"
16+
cp -r ~/.m2/repository/io/karatelabs "${KARATE_REPO}"
1717

1818
# create / copy the karate fatjar so that the docker image build can add it
1919
mvn package -B -ntp -P fatjar -DskipTests -f karate-core/pom.xml
20-
cp karate-core/target/karate-${KARATE_VERSION}.jar karate-docker/karate-chrome/target/karate.jar
20+
cp "karate-core/target/karate-${KARATE_VERSION}.jar" karate-docker/karate-chrome/target/karate.jar
2121

22-
# setup multiplatform build
23-
docker buildx rm multiplatform-builder
22+
# setup multiplatform build (ignore error if builder doesn't exist)
23+
docker buildx rm multiplatform-builder || true
2424
docker buildx create --name multiplatform-builder
2525
docker buildx use multiplatform-builder
2626

2727
# build karate-chrome docker image that includes karate fatjar + maven jars for convenience
28-
# Only possible for linux/amd64 as chrome not available on linux/arm64
29-
docker buildx build --platform linux/amd64 --cache-from=type=local,src=./target/docker --cache-to=type=local,dest=./target/docker -t karatelabs/karate-chrome:${{ github.event.inputs.version }} -t karatelabs/karate-chrome:latest karate-docker/karate-chrome
30-
# build karate-chromium docker image that includes karate fatjar + maven jars for convenience
31-
# Both platform
32-
docker buildx build --platform linux/amd64,linux/arm64 --cache-from=type=local,src=./target/docker --cache-to=type=local,dest=./target/docker -t karatelabs/karate-chromium:${{ github.event.inputs.version }} -t karatelabs/karate-chromium:latest karate-docker/karate-chromium
28+
# Only linux/amd64 is supported because google-chrome-stable is amd64-only
29+
docker buildx build \
30+
--platform linux/amd64 \
31+
--cache-from=type=local,src=./target/docker \
32+
--cache-to=type=local,dest=./target/docker \
33+
-t karatelabs/karate-chrome:${{ github.event.inputs.version }} \
34+
-t karatelabs/karate-chrome:latest \
35+
karate-docker/karate-chrome
3336

34-
# Select image for test depending current OS
37+
# Decide platform for local "load" build
38+
PLATFORM_FLAG=""
3539
if [[ "$OSTYPE" == "darwin"* ]]; then
36-
# chromium only solution on Mac darwin
37-
IMAGE=chromium
38-
else
39-
IMAGE=chrome
40+
# On Mac (including M1), force linux/amd64 so Chrome is available
41+
PLATFORM_FLAG="--platform=linux/amd64"
4042
fi
41-
# Load image image for local
42-
docker buildx build --load --cache-from=type=local,src=./target/docker -t karate-$IMAGE karate-docker/karate-$IMAGE
43+
44+
# Build local image (for running tests) and load into Docker
45+
docker buildx build \
46+
--load \
47+
${PLATFORM_FLAG} \
48+
--cache-from=type=local,src=./target/docker \
49+
-t karate-chrome \
50+
karate-docker/karate-chrome
4351

4452
# just in case a previous run had hung (likely only in local dev)
4553
docker stop karate || true
4654

4755
# note that this command is run as a background process
48-
docker run --name karate --rm --cap-add=SYS_ADMIN -v "$PWD":/karate -v "$HOME"/.m2:/root/.m2 karate-$IMAGE &
56+
docker run --name karate --rm --cap-add=SYS_ADMIN \
57+
-v "$PWD":/karate \
58+
-v "$HOME/.m2":/root/.m2 \
59+
karate-chrome &
4960

5061
# just ensure that the docker container named "karate" exists after the above command
5162
# it does not have to have completed startup, the command / karate test below will wait
@@ -59,4 +70,3 @@ docker exec -w /karate karate mvn test -B -ntp -f karate-e2e-tests/pom.xml -Dtes
5970

6071
docker stop karate
6172
wait
62-

karate-docker/karate-chrome/Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ LABEL url="https://github.com/karatelabs/karate/tree/master/karate-docker/karate
55

66
RUN apt-get update && apt-get install -y --no-install-recommends \
77
wget \
8-
gnupg2
9-
10-
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
11-
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
12-
&& apt-get update && apt-get install -y --no-install-recommends \
13-
google-chrome-stable
8+
gnupg2 \
9+
ca-certificates
10+
11+
RUN mkdir -p /etc/apt/keyrings \
12+
&& wget -q -O - https://dl.google.com/linux/linux_signing_key.pub \
13+
| gpg --dearmor > /etc/apt/keyrings/google-linux-signing-key.gpg \
14+
&& echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/google-linux-signing-key.gpg] http://dl.google.com/linux/chrome/deb/ stable main" \
15+
> /etc/apt/sources.list.d/google-chrome.list \
16+
&& apt-get update \
17+
&& apt-get install -y --no-install-recommends \
18+
google-chrome-stable
1419

1520
RUN useradd chrome --shell /bin/bash --create-home \
1621
&& usermod -a -G sudo chrome \
@@ -20,7 +25,7 @@ RUN useradd chrome --shell /bin/bash --create-home \
2025
RUN apt-get install -y --no-install-recommends \
2126
xvfb \
2227
x11vnc \
23-
xterm \
28+
xterm \
2429
fluxbox \
2530
wmctrl \
2631
supervisor \

0 commit comments

Comments
 (0)