Skip to content

Commit

Permalink
Merge pull request #2424 from jandry/2422-arm64-support
Browse files Browse the repository at this point in the history
#2422 Add support of arm64 for image karatelabs/karate-chrome
  • Loading branch information
ptrthomas authored Jun 6, 2024
2 parents 233190b + 5384f7f commit a6a5da8
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 10 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
- name: docker push
if: ( github.event.inputs.docker == 'enabled' )
run: |
docker tag karate-chrome karatelabs/karate-chrome:${{ github.event.inputs.version }}
docker tag karate-chrome karatelabs/karate-chrome:latest
docker push karatelabs/karate-chrome:${{ github.event.inputs.version }}
docker push karatelabs/karate-chrome:latest
run: |
docker buildx build --push --platform linux/amd64 --cache-from=type=local,src=./target/docker -t karate-chrome -t karatelabs/karate-chrome:latest -t karatelabs/karate-chrome:${{ github.event.inputs.version }} karate-docker/karate-chrome
docker buildx build --push --platform linux/amd64,linux/arm64 --cache-from=type=local,src=./target/docker -t karate-chromium -t karatelabs/karate-chromium:latest -t karatelabs/karate-chromium:${{ github.event.inputs.version }} karate-docker/karate-chromium
- name: maven deploy to central
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_TOKEN_USER }}
Expand Down
27 changes: 22 additions & 5 deletions build-docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -x -e
#set -x -e

# assume that karate jars are installed in maven local repo
# mvn clean install -DskipTests -P pre-release
Expand All @@ -19,17 +19,33 @@ cp -r ~/.m2/repository/io/karatelabs ${KARATE_REPO}
mvn package -B -ntp -P fatjar -DskipTests -f karate-core/pom.xml
cp karate-core/target/karate-${KARATE_VERSION}.jar karate-docker/karate-chrome/target/karate.jar

# hack for apple silicon
# export DOCKER_DEFAULT_PLATFORM=linux/amd64
# setup multiplatform build
docker buildx rm multiplatform-builder
docker buildx create --name multiplatform-builder
docker buildx use multiplatform-builder

# build karate-chrome docker image that includes karate fatjar + maven jars for convenience
docker build -t karate-chrome karate-docker/karate-chrome
# Only possible for linux/amd64 as chrome not available on linux/arm64
docker buildx build --platform linux/amd64 --cache-from=type=local,src=./target/docker --cache-to=type=local,dest=./target/docker -t karate-chrome -t karate-chrome:latest karate-docker/karate-chrome
# build karate-chromium docker image that includes karate fatjar + maven jars for convenience
# Both platform
docker buildx build --platform linux/amd64,linux/arm64 --cache-from=type=local,src=./target/docker --cache-to=type=local,dest=./target/docker -t karate-chromium karate-docker/karate-chromium

# Select image for test depending current OS
if [[ "$OSTYPE" == "darwin"* ]]; then
# chromium only solution on Mac darwin
IMAGE=chromium
else
IMAGE=chrome
fi
# Load image image for local
docker buildx build --load --cache-from=type=local,src=./target/docker -t karate-$IMAGE karate-docker/karate-$IMAGE

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

# note that this command is run as a background process
docker run --name karate --rm --cap-add=SYS_ADMIN -v "$PWD":/karate -v "$HOME"/.m2:/root/.m2 karate-chrome &
docker run --name karate --rm --cap-add=SYS_ADMIN -v "$PWD":/karate -v "$HOME"/.m2:/root/.m2 karate-$IMAGE &

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

docker stop karate
wait

49 changes: 49 additions & 0 deletions karate-docker/karate-chromium/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM maven:3-amazoncorretto-17-debian

LABEL maintainer="Peter Thomas"
LABEL url="https://github.com/karatelabs/karate/tree/master/karate-docker/karate-chromium"

RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
gnupg2

RUN apt-get update && apt-get install -y --no-install-recommends \
chromium

RUN useradd chrome --shell /bin/bash --create-home \
&& usermod -a -G sudo chrome \
&& echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
&& echo 'chrome:karate' | chpasswd

RUN apt-get install -y --no-install-recommends \
xvfb \
x11vnc \
xterm \
fluxbox \
wmctrl \
supervisor \
socat \
ffmpeg \
locales \
locales-all

ENV LANG en_US.UTF-8

RUN apt-get clean \
&& rm -rf /var/cache/* /var/log/apt/* /var/lib/apt/lists/* /tmp/* \
&& mkdir ~/.vnc \
&& x11vnc -storepasswd karate ~/.vnc/passwd \
&& locale-gen ${LANG} \
&& dpkg-reconfigure --frontend noninteractive locales \
&& update-locale LANG=${LANG}

COPY supervisord.conf /etc
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

EXPOSE 5900 9222

ADD target/karate.jar /
ADD target/repository /usr/share/maven/ref/repository

CMD ["/bin/bash", "/entrypoint.sh"]
21 changes: 21 additions & 0 deletions karate-docker/karate-chromium/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x -e
if [ -z "$KARATE_JOBURL" ]
then
export KARATE_OPTIONS="-h"
export KARATE_START="false"
else
export KARATE_START="true"
export KARATE_OPTIONS="-j $KARATE_JOBURL"
fi
if [ -z "$KARATE_SOCAT_START" ]
then
export KARATE_SOCAT_START="false"
export KARATE_CHROME_PORT="9222"
else
export KARATE_SOCAT_START="true"
export KARATE_CHROME_PORT="9223"
fi
[ -z "$KARATE_WIDTH" ] && export KARATE_WIDTH="1280"
[ -z "$KARATE_HEIGHT" ] && export KARATE_HEIGHT="720"
exec /usr/bin/supervisord -c /etc/supervisord.conf
77 changes: 77 additions & 0 deletions karate-docker/karate-chromium/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[supervisord]
user=root
nodaemon=true

[unix_http_server]
file=/tmp/supervisor.sock
username=dummy
password=dummy

[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
username=dummy
password=dummy

[program:xvfb]
command=/usr/bin/Xvfb :1 -screen 0 %(ENV_KARATE_WIDTH)sx%(ENV_KARATE_HEIGHT)sx24 +extension RANDR
autorestart=true
priority=100

[program:fluxbox]
environment=DISPLAY=":1"
command=/usr/bin/fluxbox -display :1
autorestart=true
priority=200

[program:x11vnc]
command=/usr/bin/x11vnc -display :1 -usepw -shared -forever -xrandr
autorestart=true
priority=300

[program:chrome]
user=chrome
environment=HOME="/home/chrome",USER="chrome",DISPLAY=":1",DBUS_SESSION_BUS_ADDRESS="unix:path=/dev/null"
command=/usr/bin/chromium
--user-data-dir=/home/chrome
--no-first-run
--disable-translate
--disable-notifications
--disable-popup-blocking
--disable-infobars
--disable-gpu
--mute-audio
--dbus-stub
--disable-dev-shm-usage
--enable-logging=stderr
--log-level=0
--window-position=0,0
--window-size=%(ENV_KARATE_WIDTH)s,%(ENV_KARATE_HEIGHT)s
--force-device-scale-factor=1
--remote-allow-origins=*
--remote-debugging-port=%(ENV_KARATE_CHROME_PORT)s
autorestart=true
priority=400

[program:socat]
command=/usr/bin/socat tcp-listen:9222,fork tcp:localhost:9223
autorestart=true
autostart=%(ENV_KARATE_SOCAT_START)s
priority=500

[program:ffmpeg]
command=/usr/bin/ffmpeg -y -f x11grab -r 16 -s %(ENV_KARATE_WIDTH)sx%(ENV_KARATE_HEIGHT)s -i :1 -vcodec libx264 -pix_fmt yuv420p -preset fast /tmp/karate.mp4
autostart=%(ENV_KARATE_SOCAT_START)s
priority=600

[program:karate]
command=/usr/bin/java -jar karate.jar %(ENV_KARATE_OPTIONS)s
autorestart=false
autostart=%(ENV_KARATE_START)s
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=700

0 comments on commit a6a5da8

Please sign in to comment.