From b947ae5dc20a992a7b8c64332ae0efaed1e36785 Mon Sep 17 00:00:00 2001 From: Don Richards <2738244+DonRichards@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:32:25 -0400 Subject: [PATCH] Update Dockerfile --- Dockerfile | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b37993f..f9dead5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,20 +2,44 @@ FROM python:3.10.6 # Build the image and name it workbench-docker-image-name (or whatever you want) -# docker build -t workbench-docker-image-name . +# docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) -t workbench-docker . # Build the container from the built image and run workbench: -# docker run -it --rm --network="host" -v $(pwd):/workbench --name workbench-docker-container-name workbench-docker-image-name bash -lc "(./workbench --config example.yml --check)" -# docker run -it --rm --network="host" -v $(pwd)/islandora_workbench:/workbench --name workbench-docker-container-name workbench-docker-image-name bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/example.yml --check" +# docker run -it --rm --network="host" -v .:/workbench --name update_existing_objects workbench-docker bash -lc "./workbench --config /workbench/prod/update_islandora_objects.yml --check" +# Another example but with mounted directories for the migration to have access to. +# docker run -it --rm --network="host" -v .:/workbench -v /path/to/your/tmp:/tmp -v /path/to/your/files:/mnt/data/local --name update_existing_objects workbench-docker bash -lc "./workbench --config /workbench/prod/update_islandora_objects.yml --check" # To export a CSV file, that includes the available Drupal fields, run: -# docker run -it --rm --network="host" -v $(pwd)/islandora_workbench:/workbench --name workbench-docker-container-name workbench-docker-image-name bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_example_geo.yml --get_csv_template" +# docker run -it --rm --network="host" -v .:/workbench --name workbench-docker-container-name workbench-docker-image-name bash -lc "./workbench --config /workbench/islandora_workbench_demo_content/idc_example_geo.yml --get_csv_template" # The directory this file is in is mounted within the container at /workbench # Rename example.yml to your YML file. -ADD . /workbench/ +# Create a non-root user and set up the environment +ARG USER_ID +ARG GROUP_ID + +# Create a group with the specified GID +RUN groupadd -g $GROUP_ID dockeruser || true + +# Create a user with the specified UID and GID +RUN useradd -m -u $USER_ID -g $GROUP_ID -s /bin/bash dockeruser + +# Set the working directory WORKDIR /workbench -# Works with and without this line -RUN python -m pip install setuptools libmagic urllib3>=1.21.1 +# Copy the current directory contents into the container at /workbench +COPY . /workbench/ + +# Set ownership and permissions for the non-root user +RUN chown -R dockeruser:dockeruser /workbench + +# Set the PATH environment variable to include .local/bin +ENV PATH=/home/dockeruser/.local/bin:$PATH + +# Switch to the non-root user +USER dockeruser -RUN python setup.py install +# Install dependencies and setup the environment +RUN python -m pip install --user --upgrade pip setuptools build && \ + python -m pip install --user --no-cache-dir "urllib3>=1.21.1" libmagic && \ + python -m build && \ + python -m pip install --user dist/*.whl