spiegel-keyman/resources/docker-images/base/Dockerfile
Markus Greiner fb14a67db6 Docker changes permissions to match the file owner uid and gid
There is an issue that the Docker containers cannot modify the
files on KEYMAN_ROOT, since the user running build and tests on
Docker does not have the same gid and uid as the host user starting
the container.
The issue is solved by temporarily changing the uid and gid to
match the container user's uid and gid.

Test-bot: skip
Build-bot: skip
2025-10-21 15:59:06 +02:00

75 lines
2.4 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 chmod -R +x,+r $HOME/
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