diff --git a/Dockerfile b/Dockerfile index 80f74f75..54345758 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,25 +3,35 @@ FROM continuumio/miniconda3:4.9.2 ARG DEBIAN_FRONTEND=noninteractive ARG USER=user ARG GROUP=user -ARG UID=1000 -ARG GID=1000 +ARG UID +ARG GID ENV TERM="xterm-256color" ENV HOME="/home/user" RUN set -x \ - && mkdir -p ${HOME}/data \ - && addgroup --system --gid ${GID} ${GROUP} \ - && useradd --system --create-home --home-dir ${HOME} \ - --shell /bin/bash \ - --gid ${GROUP} \ - --groups sudo \ - --uid ${UID} \ - ${USER} \ - && touch ${HOME}.hushlogin + && mkdir -p ${HOME}/src \ + && \ + if [ -z "$(getent group ${GID})" ]; then \ + addgroup --system --gid ${GID} ${GROUP}; \ + else \ + groupmod -n ${GROUP} $(getent group ${GID} | cut -d: -f1); \ + fi \ + && \ + if [ -z "$(getent passwd ${UID})" ]; then \ + useradd \ + --system \ + --create-home --home-dir ${HOME} \ + --shell /bin/bash \ + --gid ${GROUP} \ + --groups sudo \ + --uid ${UID} \ + ${USER}; \ + fi \ + && touch ${HOME}/.hushlogin RUN set -x \ - && chown -R ${USER}:${GROUP} ${HOME} + && chown -R ${UID}:${GID} ${HOME} COPY environment.yml ${HOME}/src/ @@ -30,7 +40,7 @@ WORKDIR ${HOME}/src RUN set -x \ && conda env create docs.nextstrain.org -USER ${USER} +USER ${UID} RUN set -x \ && conda init bash \ diff --git a/Makefile b/Makefile index ff75d6ab..cb5f9ef3 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,11 @@ help: .ONESHELL: docker-html: set -euox - docker build -t nextstrain-docs-builder --network=host . + docker build -t nextstrain-docs-builder \ + --network=host \ + --build-arg UID=$(shell id -u) \ + --build-arg GID=$(shell id -g) \ + . docker run -it --rm \ --name=nextstrain-docs-builder-$(shell date +%s) \ --init \