From 2a946dd5466217d3b4b57c748efd445ce29ba043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Sun, 9 Feb 2025 21:32:01 +0100 Subject: [PATCH 1/4] Change docker base image to alpine --- Dockerfile | 104 ++++++++--------------------------------------------- 1 file changed, 15 insertions(+), 89 deletions(-) diff --git a/Dockerfile b/Dockerfile index e082ef79f3..f659f89d14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Copyright © 2022-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 # -FROM ubuntu:22.04 +FROM alpine:3.21.2 # Sneak the stf executable into $PATH. ENV PATH=/app/bin:$PATH @@ -17,32 +17,13 @@ EXPOSE 3000 ARG TARGETARCH -RUN if [ "$TARGETARCH" = "amd64" ]; then \ - export DEBIAN_FRONTEND=noninteractive && \ - useradd --system \ - --create-home \ - --shell /usr/sbin/nologin \ - stf-build && \ - useradd --system \ - --create-home \ - --shell /usr/sbin/nologin \ - stf && \ - sed -i'' 's@http://archive.ubuntu.com/ubuntu/@mirror://mirrors.ubuntu.com/mirrors.txt@' /etc/apt/sources.list && \ - echo '--- Updating repositories' && \ - apt-get update && \ - echo '--- Upgrading repositories' && \ - apt-get -y dist-upgrade && \ - apt-get -y install wget python3 build-essential && \ - cd /tmp && \ - wget --progress=dot:mega \ - https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-x64.tar.xz && \ - tar -xJf node-v*.tar.xz --strip-components 1 -C /usr/local && \ - rm node-v*.tar.xz && \ - su stf-build -s /bin/bash -c '/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js install' && \ - apt-get -y install --no-install-recommends libzmq3-dev libprotobuf-dev git graphicsmagick openjdk-8-jdk yasm cmake && \ - apt-get clean && \ - rm -rf /var/cache/apt/* /var/lib/apt/lists/* && \ - mkdir /tmp/bundletool && \ +RUN apk update && \ + apk upgrade && \ + apk add zeromq-dev musl-dev protobuf-dev git graphicsmagick yasm ninja g++ git wget python3 cmake make curl unzip zip nodejs npm coreutils shadow && \ + adduser -D -h /home/stf -s /sbin/nologin stf && \ + mkdir -p /home/stf && \ + chown stf:stf /home/stf && \ + mkdir -p /tmp/bundletool && \ cd /tmp/bundletool && \ wget --progress=dot:mega \ https://github.com/google/bundletool/releases/download/1.2.0/bundletool-all-1.2.0.jar && \ @@ -50,14 +31,16 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \ mkdir -p /app && \ chown -R stf:stf /tmp/build /tmp/bundletool /app && \ set -x && \ - echo '--- Building app' && \ + echo '--- Building app' && \ cd /tmp/build && \ + if [ "$TARGETARCH" = "arm64" ]; then sed -i'' -e '/phantomjs/d' package.json ; fi && \ + if [ "$TARGETARCH" = "arm64" ]; then export VCPKG_FORCE_SYSTEM_BINARIES="arm"; fi && \ export PATH=$PWD/node_modules/.bin:$PATH && \ - echo 'npm install --python="/usr/bin/python3" --omit=optional --loglevel http' | su stf -s /bin/bash && \ + echo 'npm install --python="/usr/bin/python3" --omit=optional --loglevel http' | su stf -s /bin/sh && \ echo '--- Assembling app' && \ - echo 'npm pack' | su stf -s /bin/bash && \ + echo 'npm pack' | su stf -s /bin/sh && \ tar xzf devicefarmer-stf-*.tgz --strip-components 1 -C /app && \ - echo '/tmp/build/node_modules/.bin/bower cache clean' | su stf -s /bin/bash && \ + echo '/tmp/build/node_modules/.bin/bower cache clean' | su stf -s /bin/sh && \ npm prune --omit=dev && \ mv node_modules /app && \ rm -rf ~/.node-gyp && \ @@ -69,64 +52,7 @@ RUN if [ "$TARGETARCH" = "amd64" ]; then \ .eslintrc .nvmrc .tool-versions res/.eslintrc && \ cd && \ rm -rf .npm .cache .config .local && \ - cd /app; \ - fi - -RUN if [ "$TARGETARCH" = "arm64" ]; then \ - export DEBIAN_FRONTEND=noninteractive && \ - echo '--- Updating repositories' && \ - apt-get update && \ - echo '--- Upgrading repositories' && \ - apt-get -y dist-upgrade && \ - echo '--- Building node' && \ - apt-get -y install pkg-config curl zip unzip wget python3 build-essential cmake ninja-build && \ - cd /tmp && \ - wget --progress=dot:mega \ - https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-arm64.tar.xz && \ - tar -xJf node-v*.tar.xz --strip-components 1 -C /usr/local && \ - rm node-v*.tar.xz && \ - useradd --system \ - --create-home \ - --shell /usr/sbin/nologin \ - stf && \ - su stf -s /bin/bash -c '/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js install' && \ - apt-get -y install --no-install-recommends musl-dev libzmq3-dev libprotobuf-dev git graphicsmagick yasm && \ - ln -s /usr/lib/aarch64-linux-musl/libc.so /lib/libc.musl-aarch64.so.1 && \ - echo '--- Building app' && \ - mkdir -p /app && \ - chown -R stf:stf /tmp/build && \ - set -x && \ - cd /tmp/build && \ - export PATH=$PWD/node_modules/.bin:$PATH && \ - sed -i'' -e '/phantomjs/d' package.json && \ - export VCPKG_FORCE_SYSTEM_BINARIES="arm" && \ - echo 'npm install --save-dev pnpm' | su stf -s /bin/bash && \ - echo 'npm install --python="/usr/bin/python3" --omit=optional --loglevel http' | su stf -s /bin/bash && \ - echo '--- Assembling app' && \ - echo 'npm pack' | su stf -s /bin/bash && \ - tar xzf devicefarmer-stf-*.tgz --strip-components 1 -C /app && \ - echo '/tmp/build/node_modules/.bin/bower cache clean' | su stf -s /bin/bash && \ - echo 'npm prune --omit=dev' | su stf -s /bin/bash && \ - wget --progress=dot:mega \ - https://github.com/google/bundletool/releases/download/1.2.0/bundletool-all-1.2.0.jar && \ - mkdir -p /app/bundletool && \ - mv bundletool-all-1.2.0.jar /app/bundletool/bundletool.jar && \ - mv node_modules /app && \ - chown -R root:root /app && \ - echo '--- Cleaning up' && \ - echo 'npm cache clean --force' | su stf -s /bin/bash && \ - rm -rf ~/.node-gyp && \ - apt-get -y purge pkg-config curl zip unzip wget python3 build-essential cmake ninja-build && \ - apt-get -y clean && \ - apt-get -y autoremove && \ - cd /home/stf && \ - rm -rf vcpkg .npm .cache .cmake-ts .config .local && \ - rm -rf /var/cache/apt/* /var/lib/apt/lists/* && \ - cd /app && \ - rm -rf doc .github .tx .semaphore *.md *.yaml LICENSE Dockerfile* \ - .eslintrc .nvmrc .tool-versions res/.eslintrc && \ - rm -rf /tmp/*; \ - fi + cd /app # Switch to the app user. USER stf From d4d14130e4061c6db4b8780e52ffa00625234ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Sat, 22 Feb 2025 03:06:49 +0100 Subject: [PATCH 2/4] Pin nodejs version. Fix zeromq linkage --- Dockerfile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f659f89d14..f6b8fd5d47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Copyright © 2022-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 # -FROM alpine:3.21.2 +FROM alpine:3.21.3 # Sneak the stf executable into $PATH. ENV PATH=/app/bin:$PATH @@ -19,7 +19,18 @@ ARG TARGETARCH RUN apk update && \ apk upgrade && \ - apk add zeromq-dev musl-dev protobuf-dev git graphicsmagick yasm ninja g++ git wget python3 cmake make curl unzip zip nodejs npm coreutils shadow && \ + apk add zeromq-dev musl-dev protobuf-dev git graphicsmagick yasm ninja g++ git wget python3 cmake make curl unzip zip coreutils shadow && \ + NODE_VERSION="v22.11.0" && \ + BASE_URL="https://unofficial-builds.nodejs.org/download/release/$NODE_VERSION" && \ + if [ "$TARGETARCH" = "amd64" ]; then \ + FILE_NAME="node-$NODE_VERSION-linux-x64-musl.tar.xz"; \ + elif [ "$ARCH" = "arm64" ]; then \ + FILE_NAME="node-$NODE_VERSION-linux-arm64-musl.tar.xz"; \ + else \ + echo "Unsupported architecture: $ARCH"; \ + exit 1; \ + fi && \ + curl -fsSL "$BASE_URL/$FILE_NAME" | tar -xJ -C /usr/local --strip-components=1 && \ adduser -D -h /home/stf -s /sbin/nologin stf && \ mkdir -p /home/stf && \ chown stf:stf /home/stf && \ @@ -52,6 +63,7 @@ RUN apk update && \ .eslintrc .nvmrc .tool-versions res/.eslintrc && \ cd && \ rm -rf .npm .cache .config .local && \ + apk add libc6-compat && \ cd /app # Switch to the app user. From ed7ac0382305d9c1e4bffc04bf6f8361fa7c1e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Sat, 22 Feb 2025 12:12:10 +0100 Subject: [PATCH 3/4] Fix node installation --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6b8fd5d47..59dc0a9ca2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,10 @@ RUN apk update && \ BASE_URL="https://unofficial-builds.nodejs.org/download/release/$NODE_VERSION" && \ if [ "$TARGETARCH" = "amd64" ]; then \ FILE_NAME="node-$NODE_VERSION-linux-x64-musl.tar.xz"; \ - elif [ "$ARCH" = "arm64" ]; then \ + elif [ "$TARGETARCH" = "arm64" ]; then \ FILE_NAME="node-$NODE_VERSION-linux-arm64-musl.tar.xz"; \ else \ - echo "Unsupported architecture: $ARCH"; \ + echo "Unsupported architecture: $TARGETARCH"; \ exit 1; \ fi && \ curl -fsSL "$BASE_URL/$FILE_NAME" | tar -xJ -C /usr/local --strip-components=1 && \ From e9d4bb5d08281de7209ccf07404e788509bf3612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Sat, 22 Feb 2025 15:01:52 +0100 Subject: [PATCH 4/4] Change base image to official node --- Dockerfile | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 59dc0a9ca2..479530f879 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Copyright © 2022-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0 # -FROM alpine:3.21.3 +FROM node:22.14-alpine3.20 # Sneak the stf executable into $PATH. ENV PATH=/app/bin:$PATH @@ -20,17 +20,6 @@ ARG TARGETARCH RUN apk update && \ apk upgrade && \ apk add zeromq-dev musl-dev protobuf-dev git graphicsmagick yasm ninja g++ git wget python3 cmake make curl unzip zip coreutils shadow && \ - NODE_VERSION="v22.11.0" && \ - BASE_URL="https://unofficial-builds.nodejs.org/download/release/$NODE_VERSION" && \ - if [ "$TARGETARCH" = "amd64" ]; then \ - FILE_NAME="node-$NODE_VERSION-linux-x64-musl.tar.xz"; \ - elif [ "$TARGETARCH" = "arm64" ]; then \ - FILE_NAME="node-$NODE_VERSION-linux-arm64-musl.tar.xz"; \ - else \ - echo "Unsupported architecture: $TARGETARCH"; \ - exit 1; \ - fi && \ - curl -fsSL "$BASE_URL/$FILE_NAME" | tar -xJ -C /usr/local --strip-components=1 && \ adduser -D -h /home/stf -s /sbin/nologin stf && \ mkdir -p /home/stf && \ chown stf:stf /home/stf && \