From 4c2677774691b51bf7fc9d59e9218eb42f27ad58 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 10:01:59 +0100 Subject: [PATCH 01/20] Add a starting Dockerfile --- Dockerfile | 60 +++++++++++++++++++++++++++++++++++ docker/activate-custom-env.sh | 2 ++ docker/post-build.sh | 5 +++ docker/setup_custom_env.py | 52 ++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 Dockerfile create mode 100644 docker/activate-custom-env.sh create mode 100755 docker/post-build.sh create mode 100644 docker/setup_custom_env.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ed71d5e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +# Use the jupyter/minimal-notebook as the base image +FROM quay.io/jupyter/minimal-notebook:latest + +# Switch to root user to install additional dependencies (if needed) +USER root + +# Install additional dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + gcc \ + g++ \ + libffi-dev \ + && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy the script to setup the environment +COPY docker/setup_custom_env.py /opt/setup-scripts/ +# Make the script executable +RUN chmod +x /opt/setup-scripts/setup_custom_env.py + +# Copy the script to activate the Conda environment +COPY docker/activate-custom-env.sh /usr/local/bin/before-notebook.d/ + +# Switch back to the default notebook user +USER ${NB_UID} + +# Set a shortcut to the tutorial name +ENV BASENAME="python-tutorial" + +# Set the working directory to the home directory of the notebook user +WORKDIR ${HOME} + +# Clone the tutorial repository +RUN git clone \ + --branch main \ + --depth 1 \ + https://github.com/empa-scientific-it/${BASENAME} + +WORKDIR ${HOME}/${BASENAME} + +# Create the Conda environment defined in environment.yml +RUN mamba env create -f binder/environment.yml && \ + mamba clean --all -f -y && \ + fix-permissions "${CONDA_DIR}" && \ + fix-permissions "/home/${NB_USER}" + +# Register the Jupyter kernel from the custom environment +RUN /opt/setup-scripts/setup_custom_env.py ${BASENAME} + +# Copy the IPython configuration file +RUN mkdir -p ${HOME}/.ipython/profile_default +COPY binder/ipython_config.py ${HOME}/.ipython/profile_default/ + +# Set the environment variable IPYTHONDIR +ENV IPYTHONDIR="${HOME}/.ipython" + +# Use the default ENTRYPOINT from the base image to start Jupyter Lab +ENTRYPOINT ["tini", "-g", "--", "start.sh"] diff --git a/docker/activate-custom-env.sh b/docker/activate-custom-env.sh new file mode 100644 index 00000000..deb43178 --- /dev/null +++ b/docker/activate-custom-env.sh @@ -0,0 +1,2 @@ +#!/bin/bash +conda activate python-tutorial diff --git a/docker/post-build.sh b/docker/post-build.sh new file mode 100755 index 00000000..90c25f1c --- /dev/null +++ b/docker/post-build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +mkdir -p ${HOME}/.ipython/profile_default +cp binder/ipython_config.py ${HOME}/.ipython/profile_default/ diff --git a/docker/setup_custom_env.py b/docker/setup_custom_env.py new file mode 100644 index 00000000..afcd8e94 --- /dev/null +++ b/docker/setup_custom_env.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +import json +import os +import sys +from pathlib import Path + +# Retrieve the environment name from the command-line arguments +env_name = sys.argv[1] + +# Get the Conda directory from the environment variables +CONDA_DIR = os.environ["CONDA_DIR"] + +# Define the path to the kernel.json file +kernel_dir = Path.home() / f".local/share/jupyter/kernels/{env_name}" +kernel_file = kernel_dir / "kernel.json" + +# Ensure the kernel directory exists +kernel_dir.mkdir(parents=True, exist_ok=True) + +# Define default kernel.json content +default_content = { + "argv": [ + f"{CONDA_DIR}/envs/{env_name}/bin/python", + "-m", + "ipykernel_launcher", + "-f", + "{connection_file}", + ], + "display_name": f"Python ({env_name})", + "language": "python", +} + +# If the kernel.json file doesn't exist, create it with default content +if not kernel_file.exists(): + kernel_file.write_text(json.dumps(default_content, indent=1)) + +# Read the existing kernel.json content +content = json.loads(kernel_file.read_text()) + +# Add the environment variables to the kernel configuration +content["env"] = { + "XML_CATALOG_FILES": "", + "PATH": f"{CONDA_DIR}/envs/{env_name}/bin:$PATH", + "CONDA_PREFIX": f"{CONDA_DIR}/envs/{env_name}", + "CONDA_PROMPT_MODIFIER": f"({env_name}) ", + "CONDA_SHLVL": "2", + "CONDA_DEFAULT_ENV": env_name, + "CONDA_PREFIX_1": CONDA_DIR, +} + +# Write the updated content back to the kernel.json file +kernel_file.write_text(json.dumps(content, indent=1)) From 3ac0f441c9d8ac355b3aba2ffae5527bca87c586 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Wed, 20 Nov 2024 13:20:49 +0100 Subject: [PATCH 02/20] Paths fixed --- Dockerfile | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed71d5e5..70984b9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,22 @@ # Use the jupyter/minimal-notebook as the base image FROM quay.io/jupyter/minimal-notebook:latest +# Set a shortcut to the tutorial name +ENV BASENAME="python-tutorial" +ENV REPO="https://github.com/edoardob90/${BASENAME}" + +# Set the working directory to the home directory of the notebook user +WORKDIR ${HOME} + +# Clone the tutorial repository +RUN git clone \ + --branch add-dockerfile \ + --depth 1 \ + ${REPO} + +# Set the working directory to the repository directory +WORKDIR ${BASENAME} + # Switch to root user to install additional dependencies (if needed) USER root @@ -16,29 +32,17 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* # Copy the script to setup the environment -COPY docker/setup_custom_env.py /opt/setup-scripts/ -# Make the script executable -RUN chmod +x /opt/setup-scripts/setup_custom_env.py +RUN cp -a docker/setup_custom_env.py /opt/setup-scripts/ && \ + chmod +x /opt/setup-scripts/setup_custom_env.py # Copy the script to activate the Conda environment -COPY docker/activate-custom-env.sh /usr/local/bin/before-notebook.d/ +RUN cp -a docker/activate-custom-env.sh /usr/local/bin/before-notebook.d/ # Switch back to the default notebook user USER ${NB_UID} -# Set a shortcut to the tutorial name -ENV BASENAME="python-tutorial" - -# Set the working directory to the home directory of the notebook user -WORKDIR ${HOME} - -# Clone the tutorial repository -RUN git clone \ - --branch main \ - --depth 1 \ - https://github.com/empa-scientific-it/${BASENAME} - -WORKDIR ${HOME}/${BASENAME} +# Set the working directory to the repository directory +# WORKDIR ${HOME}/${BASENAME} # Create the Conda environment defined in environment.yml RUN mamba env create -f binder/environment.yml && \ @@ -49,7 +53,7 @@ RUN mamba env create -f binder/environment.yml && \ # Register the Jupyter kernel from the custom environment RUN /opt/setup-scripts/setup_custom_env.py ${BASENAME} -# Copy the IPython configuration file +# Copy the IPython configuration file (binder/postBuild script) RUN mkdir -p ${HOME}/.ipython/profile_default COPY binder/ipython_config.py ${HOME}/.ipython/profile_default/ From dd70a0e41a1c683a387b487093d05b5844f55fe6 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 14:05:51 +0100 Subject: [PATCH 03/20] Use base environment --- Dockerfile | 17 +++++++---------- docker/environment.yml | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 docker/environment.yml diff --git a/Dockerfile b/Dockerfile index 70984b9a..76bf767f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,30 +32,27 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* # Copy the script to setup the environment -RUN cp -a docker/setup_custom_env.py /opt/setup-scripts/ && \ - chmod +x /opt/setup-scripts/setup_custom_env.py +# RUN cp -a docker/setup_custom_env.py /opt/setup-scripts/ && \ +# chmod +x /opt/setup-scripts/setup_custom_env.py # Copy the script to activate the Conda environment -RUN cp -a docker/activate-custom-env.sh /usr/local/bin/before-notebook.d/ +# RUN cp -a docker/activate-custom-env.sh /usr/local/bin/before-notebook.d/ # Switch back to the default notebook user USER ${NB_UID} -# Set the working directory to the repository directory -# WORKDIR ${HOME}/${BASENAME} - # Create the Conda environment defined in environment.yml -RUN mamba env create -f binder/environment.yml && \ +RUN mamba env update -f docker/environment.yml && \ mamba clean --all -f -y && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" # Register the Jupyter kernel from the custom environment -RUN /opt/setup-scripts/setup_custom_env.py ${BASENAME} +# RUN /opt/setup-scripts/setup_custom_env.py ${BASENAME} # Copy the IPython configuration file (binder/postBuild script) -RUN mkdir -p ${HOME}/.ipython/profile_default -COPY binder/ipython_config.py ${HOME}/.ipython/profile_default/ +RUN mkdir -p ${HOME}/.ipython/profile_default && \ + cp -a binder/ipython_config.py ${HOME}/.ipython/profile_default/ # Set the environment variable IPYTHONDIR ENV IPYTHONDIR="${HOME}/.ipython" diff --git a/docker/environment.yml b/docker/environment.yml new file mode 100644 index 00000000..ade81543 --- /dev/null +++ b/docker/environment.yml @@ -0,0 +1,23 @@ +--- +name: base +channels: + - conda-forge +dependencies: + - python=3.10 + - pip + - pip: + - numpy + - matplotlib + - pandas + - ipywidgets + - ipynbname + - jupyterlab + - pytest + - pytest-timeout + - markdown + - pre-commit + - geostatspy + - gstools + - scikit-learn + - attrs + - multiprocess From a1ef367c337a58cbb0eb7b2857c480677fdd4f61 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 14:37:48 +0100 Subject: [PATCH 04/20] Remove pinned python version --- Dockerfile | 15 +++------------ docker/environment.yml | 1 - 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 76bf767f..6b1903e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ WORKDIR ${HOME} # Clone the tutorial repository RUN git clone \ - --branch add-dockerfile \ + --branch main \ --depth 1 \ ${REPO} @@ -31,25 +31,16 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Copy the script to setup the environment -# RUN cp -a docker/setup_custom_env.py /opt/setup-scripts/ && \ -# chmod +x /opt/setup-scripts/setup_custom_env.py - -# Copy the script to activate the Conda environment -# RUN cp -a docker/activate-custom-env.sh /usr/local/bin/before-notebook.d/ - # Switch back to the default notebook user USER ${NB_UID} # Create the Conda environment defined in environment.yml -RUN mamba env update -f docker/environment.yml && \ +# COPY --chown=${NB_USER}:${NB_GID} docker/environment.yml docker/environment.yml +RUN mamba env update -n base -f docker/environment.yml && \ mamba clean --all -f -y && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" -# Register the Jupyter kernel from the custom environment -# RUN /opt/setup-scripts/setup_custom_env.py ${BASENAME} - # Copy the IPython configuration file (binder/postBuild script) RUN mkdir -p ${HOME}/.ipython/profile_default && \ cp -a binder/ipython_config.py ${HOME}/.ipython/profile_default/ diff --git a/docker/environment.yml b/docker/environment.yml index ade81543..5e4420c7 100644 --- a/docker/environment.yml +++ b/docker/environment.yml @@ -3,7 +3,6 @@ name: base channels: - conda-forge dependencies: - - python=3.10 - pip - pip: - numpy From 46fd36f324302a88f565ed7266c9b953e04d6567 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 15:16:15 +0100 Subject: [PATCH 05/20] Optimize Docker image build --- .dockerignore | 4 ++++ Dockerfile | 44 +++++++++++++++++--------------------------- 2 files changed, 21 insertions(+), 27 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..8513c1d3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +slides/ +.DS_Store +__pycache__/ diff --git a/Dockerfile b/Dockerfile index 6b1903e6..2d980eb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,42 @@ # Use the jupyter/minimal-notebook as the base image FROM quay.io/jupyter/minimal-notebook:latest -# Set a shortcut to the tutorial name +# Set environment variables for the tutorial and repository ENV BASENAME="python-tutorial" -ENV REPO="https://github.com/edoardob90/${BASENAME}" - -# Set the working directory to the home directory of the notebook user -WORKDIR ${HOME} - -# Clone the tutorial repository -RUN git clone \ - --branch main \ - --depth 1 \ - ${REPO} - -# Set the working directory to the repository directory -WORKDIR ${BASENAME} +ENV REPO=${HOME}/${BASENAME} +ENV IPYTHONDIR="${HOME}/.ipython" -# Switch to root user to install additional dependencies (if needed) +# Switch to root user to install additional dependencies USER root - -# Install additional dependencies RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ gcc \ g++ \ - libffi-dev \ - && \ + libffi-dev && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # Switch back to the default notebook user USER ${NB_UID} -# Create the Conda environment defined in environment.yml -# COPY --chown=${NB_USER}:${NB_GID} docker/environment.yml docker/environment.yml -RUN mamba env update -n base -f docker/environment.yml && \ +# Set up the Conda environment +COPY docker/environment.yml /tmp/environment.yml +RUN mamba env update -n base -f /tmp/environment.yml && \ mamba clean --all -f -y && \ fix-permissions "${CONDA_DIR}" && \ fix-permissions "/home/${NB_USER}" -# Copy the IPython configuration file (binder/postBuild script) -RUN mkdir -p ${HOME}/.ipython/profile_default && \ - cp -a binder/ipython_config.py ${HOME}/.ipython/profile_default/ +# Prepare IPython configuration (move earlier in the build) +RUN mkdir -p ${HOME}/.ipython/profile_default +COPY --chown=${NB_UID}:${NB_GID} binder/ipython_config.py ${HOME}/.ipython/profile_default/ -# Set the environment variable IPYTHONDIR -ENV IPYTHONDIR="${HOME}/.ipython" +# Copy the repository late in the build process +RUN mkdir -p ${REPO} +COPY --chown=${NB_UID}:${NB_GID} . ${REPO}/ + +# Set the working directory to the repository +WORKDIR ${REPO} # Use the default ENTRYPOINT from the base image to start Jupyter Lab ENTRYPOINT ["tini", "-g", "--", "start.sh"] From ebab11842bf35f011e0be3ec07699bb01ac6e394 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 15:29:51 +0100 Subject: [PATCH 06/20] Add metadata labels --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Dockerfile b/Dockerfile index 2d980eb4..7fdae0f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,15 @@ # Use the jupyter/minimal-notebook as the base image FROM quay.io/jupyter/minimal-notebook:latest +# Metadata labels +LABEL org.opencontainers.image.title="Python Tutorial" +LABEL org.opencontainers.image.description="A containerized Python tutorial environment with Jupyter Lab." +LABEL org.opencontainers.image.authors="Empa Scientific IT " +LABEL org.opencontainers.image.url="https://github.com/empa-scientific-it/python-tutorial" +LABEL org.opencontainers.image.source="https://github.com/empa-scientific-it/python-tutorial" +LABEL org.opencontainers.image.version="1.0.0" +LABEL org.opencontainers.image.licenses="MIT" + # Set environment variables for the tutorial and repository ENV BASENAME="python-tutorial" ENV REPO=${HOME}/${BASENAME} From 7a939de1284f49fc1706c128addab31f1dc245b8 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Wed, 20 Nov 2024 15:30:44 +0100 Subject: [PATCH 07/20] Add GitHub workflow --- .github/workflows/docker-build.yml | 36 +++++++++++++++++++ ...build-docker-image.yml => repo2docker.yml} | 0 2 files changed, 36 insertions(+) create mode 100644 .github/workflows/docker-build.yml rename .github/workflows/{build-docker-image.yml => repo2docker.yml} (100%) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..3191db75 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,36 @@ +name: Build Tutorial Container + +on: + push: + branches: + - main + paths-ignore: + - "*.md" + - slides/** + - images/** + - .gitignore + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build the Docker image + run: | + docker build -t ghcr.io/${{ github.repository }}:latest . + + - name: Push the Docker image + run: | + docker push ghcr.io/${{ github.repository }}:latest diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/repo2docker.yml similarity index 100% rename from .github/workflows/build-docker-image.yml rename to .github/workflows/repo2docker.yml From fe3520f23d5fc539bba775cedf3229295f25f3c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:38:40 +0000 Subject: [PATCH 08/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/docker-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 3191db75..d986d7d4 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,3 +1,4 @@ +--- name: Build Tutorial Container on: From 521ae7b4f5bbb841593d6844a1c62b9de29b4cdc Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Fri, 22 Nov 2024 11:21:13 +0100 Subject: [PATCH 09/20] Add AI dependencies --- binder/environment.yml | 4 ++++ docker/environment.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/binder/environment.yml b/binder/environment.yml index 7d382e1d..60d0322a 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -21,3 +21,7 @@ dependencies: - scikit-learn - attrs - multiprocess + - openai + - tenacity + - markdown2 + - python-dotenv diff --git a/docker/environment.yml b/docker/environment.yml index 5e4420c7..b9a588de 100644 --- a/docker/environment.yml +++ b/docker/environment.yml @@ -20,3 +20,7 @@ dependencies: - scikit-learn - attrs - multiprocess + - openai + - tenacity + - markdown2 + - python-dotenv From 6d1f3811d967981f34a929af3e78c29a24540cc7 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 25 Nov 2024 21:33:37 +0100 Subject: [PATCH 10/20] Remove unused files --- docker/activate-custom-env.sh | 2 -- docker/post-build.sh | 5 ---- docker/setup_custom_env.py | 52 ----------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 docker/activate-custom-env.sh delete mode 100755 docker/post-build.sh delete mode 100644 docker/setup_custom_env.py diff --git a/docker/activate-custom-env.sh b/docker/activate-custom-env.sh deleted file mode 100644 index deb43178..00000000 --- a/docker/activate-custom-env.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -conda activate python-tutorial diff --git a/docker/post-build.sh b/docker/post-build.sh deleted file mode 100755 index 90c25f1c..00000000 --- a/docker/post-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -e - -mkdir -p ${HOME}/.ipython/profile_default -cp binder/ipython_config.py ${HOME}/.ipython/profile_default/ diff --git a/docker/setup_custom_env.py b/docker/setup_custom_env.py deleted file mode 100644 index afcd8e94..00000000 --- a/docker/setup_custom_env.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 -import json -import os -import sys -from pathlib import Path - -# Retrieve the environment name from the command-line arguments -env_name = sys.argv[1] - -# Get the Conda directory from the environment variables -CONDA_DIR = os.environ["CONDA_DIR"] - -# Define the path to the kernel.json file -kernel_dir = Path.home() / f".local/share/jupyter/kernels/{env_name}" -kernel_file = kernel_dir / "kernel.json" - -# Ensure the kernel directory exists -kernel_dir.mkdir(parents=True, exist_ok=True) - -# Define default kernel.json content -default_content = { - "argv": [ - f"{CONDA_DIR}/envs/{env_name}/bin/python", - "-m", - "ipykernel_launcher", - "-f", - "{connection_file}", - ], - "display_name": f"Python ({env_name})", - "language": "python", -} - -# If the kernel.json file doesn't exist, create it with default content -if not kernel_file.exists(): - kernel_file.write_text(json.dumps(default_content, indent=1)) - -# Read the existing kernel.json content -content = json.loads(kernel_file.read_text()) - -# Add the environment variables to the kernel configuration -content["env"] = { - "XML_CATALOG_FILES": "", - "PATH": f"{CONDA_DIR}/envs/{env_name}/bin:$PATH", - "CONDA_PREFIX": f"{CONDA_DIR}/envs/{env_name}", - "CONDA_PROMPT_MODIFIER": f"({env_name}) ", - "CONDA_SHLVL": "2", - "CONDA_DEFAULT_ENV": env_name, - "CONDA_PREFIX_1": CONDA_DIR, -} - -# Write the updated content back to the kernel.json file -kernel_file.write_text(json.dumps(content, indent=1)) From 3786be671ca9de635d799102d3055f7417dac19a Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 25 Nov 2024 21:45:18 +0100 Subject: [PATCH 11/20] Use official actions --- .github/workflows/docker-build.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index d986d7d4..ef1de6d2 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -18,8 +18,8 @@ jobs: permissions: packages: write steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Log in to GHCR uses: docker/login-action@v3 @@ -28,10 +28,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build the Docker image - run: | - docker build -t ghcr.io/${{ github.repository }}:latest . - - - name: Push the Docker image - run: | - docker push ghcr.io/${{ github.repository }}:latest + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/${{ github.repository }}:latest From ee4f830d1d3776cf1bdcd3ba57d848990e9bb328 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Sun, 4 May 2025 21:43:17 +0200 Subject: [PATCH 12/20] Update environment.yml --- docker/environment.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/environment.yml b/docker/environment.yml index b9a588de..6df2975c 100644 --- a/docker/environment.yml +++ b/docker/environment.yml @@ -24,3 +24,10 @@ dependencies: - tenacity - markdown2 - python-dotenv + - pillow + - opencv-python + - torch + - torchaudio + - torchvision + - albumentations + - grad-cam From 1fbd74e28fdeb15f7afaea804e39defe0c506b0b Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 10:53:07 +0200 Subject: [PATCH 13/20] Remove COPY command --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7fdae0f6..2b61e3f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,8 +41,8 @@ RUN mkdir -p ${HOME}/.ipython/profile_default COPY --chown=${NB_UID}:${NB_GID} binder/ipython_config.py ${HOME}/.ipython/profile_default/ # Copy the repository late in the build process -RUN mkdir -p ${REPO} -COPY --chown=${NB_UID}:${NB_GID} . ${REPO}/ +# RUN mkdir -p ${REPO} +# COPY --chown=${NB_UID}:${NB_GID} . ${REPO}/ # Set the working directory to the repository WORKDIR ${REPO} From 6b7023eb4e2e6a14d372fef2d78c1d5daf15a71b Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 11:31:23 +0200 Subject: [PATCH 14/20] Rename workflow --- .github/workflows/repo2docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/repo2docker.yml b/.github/workflows/repo2docker.yml index 035cb9a9..f3eb9450 100644 --- a/.github/workflows/repo2docker.yml +++ b/.github/workflows/repo2docker.yml @@ -1,5 +1,5 @@ --- -name: Build Tutorial Container +name: Build Container with repo2docker on: push: branches: From fc29c4d961a6eb17fd603b5e29adcc60cf0eed18 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 11:31:35 +0200 Subject: [PATCH 15/20] Add missing dependency --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2b61e3f6..ec85241c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,8 @@ RUN apt-get update && \ build-essential \ gcc \ g++ \ - libffi-dev && \ + libffi-dev \ + libgl1 && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* From b73f19fe3a73fcbc1db911269e237b766556d410 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 11:45:41 +0200 Subject: [PATCH 16/20] Update instructions to run Docker --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b09bbdce..b7bb9520 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ docker pull ghcr.io/empa-scientific-it/python-tutorial:latest 5. Run the Docker container: Once the image is downloaded, run the following command to start a Docker container from the image: ```console -docker run -p 8888:8888 --name python_tutorial -v /path/to/python-tutorial:/home/jovyan/work ghcr.io/empa-scientific-it/python-tutorial:latest jupyter lab --ip 0.0.0.0 --no-browser +docker run -p 8888:8888 --name python_tutorial -v /path/to/python-tutorial:/home/jovyan/python-tutorial ghcr.io/empa-scientific-it/python-tutorial:latest jupyter lab --ip 0.0.0.0 --no-browser ``` Replace `/path/to/python-tutorial` with the path to the folder you created in step 2, for example `C:/Users/yourusername/Desktop/python-tutorial`. From 21ffc79291073089a2099896c20df5db05c031a8 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 15:25:17 +0200 Subject: [PATCH 17/20] Remove old workflow --- .github/workflows/repo2docker.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .github/workflows/repo2docker.yml diff --git a/.github/workflows/repo2docker.yml b/.github/workflows/repo2docker.yml deleted file mode 100644 index f3eb9450..00000000 --- a/.github/workflows/repo2docker.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: Build Container with repo2docker -on: - push: - branches: - - main - paths-ignore: - - "*.md" - - slides/** - - images/** - - .gitignore - workflow_dispatch: -jobs: - repo2docker: - runs-on: ubuntu-latest - permissions: - packages: write - steps: - - name: checkout files in repo - uses: actions/checkout@main - - name: update jupyter dependencies with repo2docker - uses: jupyterhub/repo2docker-action@master - with: - DOCKER_USERNAME: ${{ github.actor }} - DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} - DOCKER_REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - FORCE_REPO2DOCKER_VERSION: jupyter-repo2docker==2024.07.0 From 0aad7809058f98aadf170375bebe73f1654a7d91 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 15:27:27 +0200 Subject: [PATCH 18/20] Adjust workflow * Trigger build for PR, but only when from the same repo * Multi-arch build * Uses "docker/metadata" action to set up labels and tags --- .github/workflows/docker-build.yml | 38 +++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index ef1de6d2..61e51fb8 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -10,6 +10,12 @@ on: - slides/** - images/** - .gitignore + pull_request: + paths-ignore: + - "*.md" + - slides/** + - images/** + - .gitignore workflow_dispatch: jobs: @@ -17,20 +23,46 @@ jobs: runs-on: ubuntu-latest permissions: packages: write + strategy: + matrix: + arch: [amd64, arm64] + fail-fast: false steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GHCR + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.arch == 'amd64' }} + type=ref,event=branch + type=ref,event=pr + type=sha,format=short + flavor: | + suffix=-${{ matrix.arch }} + - name: Build and push uses: docker/build-push-action@v6 with: - platforms: linux/amd64,linux/arm64 - push: true - tags: ghcr.io/${{ github.repository }}:latest + context: . + platforms: linux/${{ matrix.arch }} + push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From edcb8aae159943862143cf8cf76288f53dbd5989 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 15:47:12 +0200 Subject: [PATCH 19/20] Remove COPY --- Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ec85241c..cf496d34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,10 +41,6 @@ RUN mamba env update -n base -f /tmp/environment.yml && \ RUN mkdir -p ${HOME}/.ipython/profile_default COPY --chown=${NB_UID}:${NB_GID} binder/ipython_config.py ${HOME}/.ipython/profile_default/ -# Copy the repository late in the build process -# RUN mkdir -p ${REPO} -# COPY --chown=${NB_UID}:${NB_GID} . ${REPO}/ - # Set the working directory to the repository WORKDIR ${REPO} From 5df484c7dd425b53b6b8ad4f7240ef590a4f0f0d Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Mon, 5 May 2025 15:56:09 +0200 Subject: [PATCH 20/20] Update Docker tags * Keep only branch, pr, and SHA * Add repo tags vX.Y or vX.Y.Z --- .github/workflows/docker-build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 61e51fb8..5762f13b 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -10,6 +10,9 @@ on: - slides/** - images/** - .gitignore + tags: + - "v*.*" + - "v*.*.*" pull_request: paths-ignore: - "*.md" @@ -51,12 +54,10 @@ jobs: with: images: ghcr.io/${{ github.repository }} tags: | - type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.arch == 'amd64' }} - type=ref,event=branch + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} type=ref,event=pr + type=ref,event=tag type=sha,format=short - flavor: | - suffix=-${{ matrix.arch }} - name: Build and push uses: docker/build-push-action@v6