spiegel-keyman/resources/docker-images/base/Dockerfile
Eberhard Beilharz 72d8b705ff
maint(common): on Windows build as root inside docker container
This fixes a permission problem when we run docker from git bash.
On Windows we want to build as _root_ inside of the docker container.
This gives the necessary permissions due to the way the Windows user
is mapped to git bash/mingw and the docker container. On Linux
however we want to build as _build_ user inside the container so that
files we create are owned by the host user.

See https://github.com/keymanapp/keyman/pull/14154#issuecomment-2970577312
for further explanation.
2025-08-18 17:50:29 +02:00

74 lines
2.3 KiB
Docker

# syntax=docker/dockerfile:1.4
# Keyman is copyright (C) SIL Global. MIT License.
ARG DISTRO=ubuntu
ARG DISTRO_VERSION=latest
FROM ${DISTRO}:${DISTRO_VERSION}
LABEL org.opencontainers.image.authors="SIL Global."
LABEL org.opencontainers.image.url="https://github.com/keymanapp/keyman.git"
LABEL org.opencontainers.image.title="Keyman Build Base Image"
SHELL ["/bin/bash", "-c"]
# We will switch to a build user after some installation
USER root
ENV HOME=/home/build
RUN grep ubuntu /etc/passwd && userdel ubuntu || true && \
rm -rf /home/ubuntu && \
useradd -c "Build user" --uid 1000 --home-dir $HOME --create-home --shell /usr/bin/bashwrapper build
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_PRIORITY=critical
ENV DEBCONF_NOWARNINGS=yes
# Update to the latest
RUN apt-get -q -y update && \
apt-get -q -y install ca-certificates curl gnupg meson software-properties-common sudo && \
if [[ "$(lsb_release -is)" == "Ubuntu" ]]; then \
add-apt-repository ppa:keymanapp/keyman && \
add-apt-repository ppa:keymanapp/keyman-alpha ; \
fi
RUN apt-get -q -y update && \
apt-get -q -y upgrade
# Allow build user to use `sudo`
RUN echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN <<EOF cat > /usr/bin/bashwrapper
#!/bin/bash
set -eu
if [[ "${DOCKER_RUN_AS_ROOT:-}" == "1" ]] && [[ "$(id -u)" != "0" ]] ; then
# On Windows run as root so that the permissions are correct
# (root in Docker container is mapped to current user on Windows,
# whereas when Docker is run on Linux root is mapped to root)
sudo -u root -i "$0" "$@"
exit $?
fi
export KEYMAN_USE_NVM=1
export DOCKER_RUNNING=true
EOF
# Install NVM
RUN NVM_RELEASE=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep tag_name | cut -d : -f 2 | cut -d '"' -f 2) && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_RELEASE}/install.sh | bash
RUN <<EOF cat >> /usr/bin/bashwrapper
PATH=/home/build/.keyman/node:\$PATH
export NVM_DIR="$HOME/.nvm"
. /home/build/.nvm/nvm.sh
EOF
RUN chmod +x /usr/bin/bashwrapper && \
chown -R build:build $HOME
USER build
# Pre-install node
ARG REQUIRED_NODE_VERSION=unset
RUN echo "HOME=\${HOME}; REQUIRED_NODE_VERSION=${REQUIRED_NODE_VERSION}" && \
export NVM_DIR="/home/build/.nvm" && \
. /home/build/.nvm/nvm.sh && \
nvm install "${REQUIRED_NODE_VERSION}" && \
nvm use "${REQUIRED_NODE_VERSION}"
USER root