Skip to content

Commit

Permalink
[docker] Allow non-unique GID (#15699)
Browse files Browse the repository at this point in the history
* Allow non-unique GID

* update CI

* Update context path

* Update dependencies
  • Loading branch information
trungleduc committed Feb 19, 2024
1 parent d4c2f9f commit d835cf3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ tests/**/coverage
tests/**/.cache-loader

**/node_modules
.yarn
5 changes: 5 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ name: Docker Tests
on:
schedule:
- cron: '0 0 * * *'
push:
branches: [main]
pull_request:
branches: [main]

jobs:
docker:
name: Docker Dev Container
if: ${{ github.event_name == 'schedule' }} || contains( github.event.pull_request.title, '[docker]')
runs-on: ubuntu-22.04
steps:
- name: Checkout
Expand Down
41 changes: 20 additions & 21 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

FROM mambaorg/micromamba:latest
FROM --platform=linux/amd64 mambaorg/micromamba:1.5.5-jammy

# Create new user
ARG NEW_MAMBA_USER_ID=57440
ARG NEW_MAMBA_USER_GID=57440
ARG NEW_MAMBA_USER=labdev


USER root

RUN if grep -q '^ID=alpine$' /etc/os-release; then \
# alpine does not have usermod/groupmod
apk add --no-cache --virtual temp-packages shadow=4.13-r0; \
fi && \
usermod "--login=${NEW_MAMBA_USER}" "--home=/home/${NEW_MAMBA_USER}" \
--move-home "-u ${NEW_MAMBA_USER_ID}" "${MAMBA_USER}" && \
groupmod "--new-name=${NEW_MAMBA_USER}" \
"-g ${NEW_MAMBA_USER_GID}" "${MAMBA_USER}" && \
if grep -q '^ID=alpine$' /etc/os-release; then \
# remove the packages that were only needed for usermod/groupmod
apk del temp-packages; \
fi && \
# Update the expected value of MAMBA_USER for the
# _entrypoint.sh consistency check.
echo "${NEW_MAMBA_USER}" > "/etc/arg_mamba_user" && \
:
ENV MAMBA_USER=$NEW_MAMBA_USER
# alpine does not have usermod/groupmod
apk add --no-cache --virtual temp-packages shadow=4.13-r0; \
fi
RUN if [ "$(id ${MAMBA_USER} -u)" != "$NEW_MAMBA_USER_ID" ]; then \
usermod "-u ${NEW_MAMBA_USER_ID}" "${MAMBA_USER}"; \
fi
RUN if [ "$(id ${MAMBA_USER} -g)" != "$NEW_MAMBA_USER_GID" ]; then \
groupmod -o -g ${NEW_MAMBA_USER_GID} ${MAMBA_USER} && \
usermod -g ${NEW_MAMBA_USER_GID} ${MAMBA_USER}; \
fi
RUN if grep -q '^ID=alpine$' /etc/os-release; then \
# remove the packages that were only needed for usermod/groupmod
apk del temp-packages; \
fi

USER $MAMBA_USER

WORKDIR /home/$MAMBA_USER/jupyterlab_cache

COPY --chown=$MAMBA_USER:$MAMBA_USER ../binder/environment.yml ./binder/environment.yml
COPY --chown=$MAMBA_USER:$MAMBA_USER docker/environment.yml ./docker/environment.yml

RUN micromamba install -n base -c conda-forge git rsync -y && micromamba install -y -n base -f ./binder/environment.yml && micromamba clean --all --yes
RUN micromamba install -n base -c conda-forge git rsync -y && micromamba install -y -n base -f ./docker/environment.yml && micromamba clean --all --yes

COPY --chown=$MAMBA_USER:$MAMBA_USER .. .
COPY --chown=$MAMBA_USER:$MAMBA_USER . .

RUN micromamba run jlpm install

Expand Down
17 changes: 17 additions & 0 deletions docker/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: base

channels:
- conda-forge
- nodefaults

dependencies:
# runtimes
- nodejs ==20.1
- python =3.11
# package managers
- pip
- yarn >=3,<4
# build
- hatch-jupyter-builder >=0.3.2
- hatchling >=1.5.0
- jupyterlab >=4,<5
7 changes: 4 additions & 3 deletions docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ set -o pipefail
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ROOT_DIR=$(dirname $SCRIPT_DIR)

DEV_USER="labdev"
DEV_USER="mambauser"
GID=$(id -g)
USER_ID=$(id -u)
RSYNC_CMD="rsync -ar /home/$DEV_USER/jupyterlab_cache/node_modules/. /home/$DEV_USER/jupyterlab/node_modules"
CMD=$1 # possible command: build, clean, dev, shell

Expand All @@ -34,7 +35,7 @@ IMAGE_TAG="jupyterlab_dev:$ROOT_DIR_MD5"
DEV_CONTAINER="jupyterlab_dev_container_$ROOT_DIR_MD5"

build_image () {
docker build --build-arg NEW_MAMBA_USER_ID=$UID --build-arg NEW_MAMBA_USER_GID=$GID $ROOT_DIR -f $SCRIPT_DIR/Dockerfile -t $IMAGE_TAG
docker build --build-arg NEW_MAMBA_USER_ID=$USER_ID --build-arg NEW_MAMBA_USER_GID=$GID $ROOT_DIR -f $SCRIPT_DIR/Dockerfile -t $IMAGE_TAG
}

stop_contaniner () {
Expand Down Expand Up @@ -68,5 +69,5 @@ if [[ $CMD == 'build' ]]; then
if [[ $CMD == 'dev-detach' ]]; then
RUN_MODE="-d"
fi
docker run $RUN_MODE --name $DEV_CONTAINER --rm -p $PORT:$PORT -v $ROOT_DIR:/home/$DEV_USER/jupyterlab --entrypoint "/bin/bash" $IMAGE_TAG -i -c "$DOCKER_CMD"
docker run $RUN_MODE --user $USER_ID:$GID --name $DEV_CONTAINER --rm -p $PORT:$PORT -v $ROOT_DIR:/home/$DEV_USER/jupyterlab --entrypoint "/bin/bash" $IMAGE_TAG -i -c "$DOCKER_CMD"
fi

0 comments on commit d835cf3

Please sign in to comment.