Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
190 lines (172 loc) · 7.79 KB
/
Copy pathDockerfile
File metadata and controls
190 lines (172 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# Copyright © 2022-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
#
# Fork (Zebrunner): the build stage builds /app with the build tools (gcc,
# python3, cmake, the -dev packages, the JDK), the image gets /app, node and
# the runtime packages only.
FROM ubuntu:26.04 AS build
WORKDIR /app
COPY . /tmp/build/
ARG TARGETARCH
# Fork (Zebrunner): the amd64 and arm64 images are alike: stf has the uid 998,
# /app belongs to root, the build tools and caches are removed. zeromq ships
# its glibc addon for arm64, no musl libc nor pnpm is needed to build it.
# npm ci installs the versions of the committed package-lock.json.
RUN if [ "$TARGETARCH" = "amd64" ]; then \
export DEBIAN_FRONTEND=noninteractive && \
useradd --system \
--uid 998 \
--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.23.2/node-v22.23.2-linux-x64.tar.xz && \
tar -xJf node-v*.tar.xz --strip-components 1 -C /usr/local && \
rm node-v*.tar.xz && \
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 libzmq3-dev libprotobuf-dev git yasm cmake && \
apt-get clean && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/* && \
mkdir -p /app && \
chown -R stf:stf /tmp/build /app && \
set -x && \
echo '--- Building app' && \
cd /tmp/build && \
export PATH=$PWD/node_modules/.bin:$PATH && \
echo 'npm ci --python="/usr/bin/python3" --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 && \
test -d /app/res/build && \
npm prune --omit=dev && \
mv node_modules /app && \
rm -rf ~/.node-gyp && \
chown -R root:root /app && \
echo '--- Cleaning up' && \
apt-get -y purge wget python3 build-essential cmake && \
apt-get -y autoremove && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/* && \
rm -rf /home/stf/.npm /home/stf/.cache /home/stf/.config /home/stf/.local && \
cd /app && \
find /tmp -mindepth 1 ! -regex '^/tmp/hsperfdata_root\(/.*\)?' -delete && \
rm -rf doc .github .tx .semaphore *.md *.yaml LICENSE Dockerfile* \
.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.23.2/node-v22.23.2-linux-arm64.tar.xz && \
tar -xJf node-v*.tar.xz --strip-components 1 -C /usr/local && \
rm node-v*.tar.xz && \
useradd --system \
--uid 998 \
--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 libzmq3-dev libprotobuf-dev git yasm && \
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 ci --python="/usr/bin/python3" --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 && \
test -d /app/res/build && \
echo 'npm prune --omit=dev' | su stf -s /bin/bash && \
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
# Fork (Zebrunner): the prebuilt addons of Windows and macOS are not loaded on
# Linux (node-gyp-build and cmake-ts pick the one of the platform)
RUN find /app/node_modules \( -path '*/prebuilds/*win32*' -o -path '*/prebuilds/*darwin*' \
-o -path '*/zeromq/build/win32' -o -path '*/zeromq/build/darwin' \) -prune -exec rm -rf {} +
FROM ubuntu:26.04
# Sneak the stf executable into $PATH.
ENV PATH=/app/bin:$PATH
# Work in app dir by default.
WORKDIR /app
# Export default app port, not enough for all processes but it should do
# for now.
EXPOSE 3000
# Fork (Zebrunner): the runtime packages: java (OpenJDK 21) and keytool of
# bundletool (storage-temp, .aab), gm (storage-plugin-image), plistutil (the
# binary Info.plist of the uploaded .ipa files, storage-plugin-apk), the
# TurboJPEG of @julusian/jpeg-turbo; stf has the uid 998, /app belongs to root.
RUN useradd --system \
--uid 998 \
--create-home \
--shell /usr/sbin/nologin \
stf && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get -y dist-upgrade && \
apt-get -y install --no-install-recommends \
ca-certificates graphicsmagick openjdk-21-jre-headless libplist-utils libturbojpeg0 && \
apt-get clean && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/*
COPY --from=build /usr/local/bin/node /usr/local/bin/node
COPY --from=build /app /app
# Fork (Zebrunner): bundletool converts the uploaded .aab files into universal .apk
# files (storage-temp, --bundletool-path), the release checked by its sha256
ADD --checksum=sha256:a099cfa1543f55593bc2ed16a70a7c67fe54b1747bb7301f37fdfd6d91028e29 \
https://github.com/google/bundletool/releases/download/1.18.3/bundletool-all-1.18.3.jar /app/bundletool/bundletool.jar
RUN chmod 644 /app/bundletool/bundletool.jar
# Fork (Zebrunner): the platform icons replace the generic ones of
# stf-device-db. The iOS tools (go-ios, socat) are in the mcloud-device image.
RUN cd /app/node_modules/@devicefarmer/stf-device-db/dist/icon && \
cp /app/icon/x120/iOS.jpg x120/iOS && \
cp /app/icon/x24/iOS.jpg x24/iOS && \
cp /app/icon/x120/Android.jpg x120/Android && \
cp /app/icon/x24/Android.jpg x24/Android && \
cp /app/icon/x120/tvOS.png x120/tvOS && \
cp /app/icon/x24/tvOS.png x24/tvOS
# Fork (Zebrunner): /data of storage-temp (--save-dir /data) belongs to stf: a new
# volume mounted there gets the owner of the directory of the image, the uploads
# (screenshots, apps, images) fail without it
RUN mkdir -p /data && chown stf:stf /data
# Switch to the app user.
USER stf
# The version of the image: make build VERSION=<tag> (ZEBRUNNER.md#build)
ARG VERSION=dev
LABEL org.opencontainers.image.title="Zebrunner STF" \
org.opencontainers.image.source="https://github.com/zebrunner/stf" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.licenses="Apache-2.0"
# Show help by default.
CMD ["stf", "--help"]