Skip to content

Commit

Permalink
Add support for arm64 to Dockerfile (#821)
Browse files Browse the repository at this point in the history
* Add support for arm64 to Dockerfile
* Change machine type R1
Fixes #820
  • Loading branch information
koral-- authored Jan 11, 2025
1 parent 8e6c257 commit 536d1cb
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 34 deletions.
9 changes: 5 additions & 4 deletions .semaphore/deploy_dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ blocks:
commands:
- checkout
- export TAG=$(echo ${SEMAPHORE_GIT_TAG_NAME:-vlatest} |cut -c 2-)
- 'docker build -t "devicefarmer/stf:$TAG" .'
- docker push devicefarmer/stf:$TAG
- docker buildx create --platform=linux/amd64,linux/arm64 --use
- 'docker buildx build --platform=linux/amd64,linux/arm64 -t "devicefarmer/stf:$TAG" .'
- docker push "devicefarmer/stf:$TAG"
secrets:
- name: dockerhub-secrets
prologue:
Expand All @@ -18,5 +19,5 @@ blocks:
dependencies: []
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
type: r1-standard-4
os_image: ubuntu2204
20 changes: 13 additions & 7 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ version: v1.0
name: Docker
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
type: r1-standard-4
os_image: ubuntu2204
blocks:
- name: Build Standard Docker image
task:
jobs:
- name: docker build
commands:
- checkout
- docker build .
- docker buildx create --platform=linux/amd64,linux/arm64 --use
- docker buildx build --platform=linux/amd64,linux/arm64 .
dependencies: []
- name: Build npm package
dependencies: []
task:
jobs:
- name: npm test
commands:
- install-package libzmq3-dev libprotobuf-dev graphicsmagick yasm gulp python3
- sem-version node 20
- checkout
- npm install
- install-package libzmq3-dev libprotobuf-dev graphicsmagick yasm gulp python3 pkg-config curl zip unzip wget build-essential cmake ninja-build git
- sem-version node 22
- export PATH=$PWD/node_modules/.bin:$PATH
- sed -i'' -e '/phantomjs/d' package.json
- export VCPKG_FORCE_SYSTEM_BINARIES="arm"
- npm install --save-dev pnpm
- npm install --python="/usr/bin/python3" --omit=optional --loglevel http
- npm test
- name: Build Debian Docker image
dependencies: []
Expand All @@ -31,7 +36,8 @@ blocks:
- name: docker build
commands:
- checkout
- docker build . -f Dockerfile-debian-x86_64
- docker buildx create --platform=linux/amd64 --use
- docker buildx build --platform=linux/amd64 . -f Dockerfile-debian-x86_64
promotions:
- name: Deploy to DockerHub
pipeline_file: deploy_dockerhub.yml
Expand Down
92 changes: 69 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ ENV PATH=/app/bin:$PATH

# Work in app dir by default.
WORKDIR /app
COPY . /tmp/build/

# Export default app port, not enough for all processes but it should do
# for now.
EXPOSE 3000

# Install app requirements. Trying to optimize push speed for dependant apps
# by reducing layers as much as possible. Note that one of the final steps
# installs development files for node-gyp so that npm install won't have to
# wait for them on the first native module installation.
RUN export DEBIAN_FRONTEND=noninteractive && \
ARG TARGETARCH

RUN if [ "$TARGETARCH" = "amd64" ]; then \
export DEBIAN_FRONTEND=noninteractive && \
useradd --system \
--create-home \
--shell /usr/sbin/nologin \
Expand Down Expand Up @@ -46,28 +46,18 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
cd /tmp/bundletool && \
wget --progress=dot:mega \
https://github.com/google/bundletool/releases/download/1.2.0/bundletool-all-1.2.0.jar && \
mv bundletool-all-1.2.0.jar bundletool.jar

# Copy app source.
COPY . /tmp/build/

# Give permissions to our build user.
RUN mkdir -p /app && \
chown -R stf-build:stf-build /tmp/build /tmp/bundletool /app

# Switch over to the build user.
USER stf-build

# Run the build.
RUN set -x && \
mv bundletool-all-1.2.0.jar bundletool.jar && \
mkdir -p /app && \
chown -R stf:stf /tmp/build /tmp/bundletool /app && \
set -x && \
echo '--- Building app' && \
cd /tmp/build && \
export PATH=$PWD/node_modules/.bin:$PATH && \
npm install --python="/usr/bin/python3" --omit=optional --loglevel http && \
echo 'npm install --python="/usr/bin/python3" --omit=optional --loglevel http' | su stf -s /bin/bash && \
echo '--- Assembling app' && \
npm pack && \
echo 'npm pack' | su stf -s /bin/bash && \
tar xzf devicefarmer-stf-*.tgz --strip-components 1 -C /app && \
bower cache clean && \
echo '/tmp/build/node_modules/.bin/bower cache clean' | su stf -s /bin/bash && \
npm prune --omit=dev && \
mv node_modules /app && \
rm -rf ~/.node-gyp && \
Expand All @@ -79,7 +69,63 @@ RUN set -x && \
.eslintrc .nvmrc .tool-versions res/.eslintrc && \
cd && \
rm -rf .npm .cache .config .local && \
cd /app
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 libzmq3-dev libprotobuf-dev git graphicsmagick 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 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

# Switch to the app user.
USER stf
Expand Down

0 comments on commit 536d1cb

Please sign in to comment.