-
Notifications
You must be signed in to change notification settings - Fork 34
Simplify and optimize Docker image #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4c26777
Add a starting Dockerfile
edoardob90 991dc16
Merge branch 'main' into add-dockerfile
edoardob90 3ac0f44
Paths fixed
edoardob90 dd70a0e
Use base environment
edoardob90 a1ef367
Remove pinned python version
edoardob90 46fd36f
Optimize Docker image build
edoardob90 ebab118
Add metadata labels
edoardob90 7a939de
Add GitHub workflow
edoardob90 fe3520f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 521ae7b
Add AI dependencies
edoardob90 f591ad5
Merge branch 'main' into add-dockerfile
yakutovicha 6d1f381
Remove unused files
edoardob90 3786be6
Use official actions
edoardob90 536dfca
Merge branch 'main' into add-dockerfile
edoardob90 ee4f830
Update environment.yml
edoardob90 1fbd74e
Remove COPY command
edoardob90 6b7023e
Rename workflow
edoardob90 fc29c4d
Add missing dependency
edoardob90 b73f19f
Update instructions to run Docker
edoardob90 21ffc79
Remove old workflow
edoardob90 0aad780
Adjust workflow
edoardob90 edcb8aa
Remove COPY
edoardob90 5df484c
Update Docker tags
edoardob90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .git | ||
| slides/ | ||
| .DS_Store | ||
| __pycache__/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| 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 | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 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 <scientificit@empa.ch>" | ||
| 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} | ||
| ENV IPYTHONDIR="${HOME}/.ipython" | ||
|
|
||
| # Switch to root user to install additional dependencies | ||
| USER root | ||
| 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/* | ||
|
|
||
| # Switch back to the default notebook user | ||
| USER ${NB_UID} | ||
|
|
||
| # 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}" | ||
|
|
||
| # 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/ | ||
|
|
||
| # Copy the repository late in the build process | ||
| RUN mkdir -p ${REPO} | ||
| COPY --chown=${NB_UID}:${NB_GID} . ${REPO}/ | ||
|
yakutovicha marked this conversation as resolved.
Outdated
|
||
|
|
||
| # 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"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/bash | ||
| conda activate python-tutorial |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| name: base | ||
| channels: | ||
| - conda-forge | ||
| dependencies: | ||
| - pip | ||
| - pip: | ||
| - numpy | ||
| - matplotlib | ||
| - pandas | ||
| - ipywidgets | ||
| - ipynbname | ||
| - jupyterlab | ||
| - pytest | ||
| - pytest-timeout | ||
| - markdown | ||
| - pre-commit | ||
| - geostatspy | ||
| - gstools | ||
| - scikit-learn | ||
| - attrs | ||
| - multiprocess | ||
| - openai | ||
| - tenacity | ||
| - markdown2 | ||
| - python-dotenv |
|
edoardob90 marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| mkdir -p ${HOME}/.ipython/profile_default | ||
| cp binder/ipython_config.py ${HOME}/.ipython/profile_default/ |
|
edoardob90 marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.