From 850a38cb272b7aaf1ed95af56e702841061fd1db Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 12:19:33 +0200 Subject: [PATCH 01/13] update: add Dockerfile-docs --- Dockerfile-docs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Dockerfile-docs diff --git a/Dockerfile-docs b/Dockerfile-docs new file mode 100644 index 000000000..c0cf282d2 --- /dev/null +++ b/Dockerfile-docs @@ -0,0 +1,34 @@ +# syntax=docker/dockerfile:1 + +ARG PYTHON_VERSION=3.12 + +FROM python:${PYTHON_VERSION}-slim + +WORKDIR /src +COPY .git/ /src/.git/ +COPY junifer /src/junifer +COPY pyproject.toml /src/pyproject.toml + +RUN apt-get update --allow-insecure-repositories && \ + apt-get install -y \ + pkg-config \ + libhdf5-dev \ + gcc \ + git \ + make \ + bc + +# Install junifer in editable mode +RUN --mount=type=cache,target=/cache/pip \ + PIP_CACHE_DIR=/cache/pip \ + pip install -e .[docs,neurokit2] + +# Add xfms +COPY --from=ghcr.io/juaml/human-template-xfms:main /opt/xfms /root/junifer/data/xfms +# Add ANTs +COPY --from=antsx/ants:latest /opt/ants /opt/ants +# Set env vars for ANTs +ENV PATH="/opt/ants/bin:$PATH" \ + LD_LIBRARY_PATH="/opt/ants/lib" + +WORKDIR /src/docs From 5f92e13f1c0f70279bbf4d2c4f58b13efc96a8bb Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 12:21:03 +0200 Subject: [PATCH 02/13] update: add .github/workflows/docker-docs-publish.yml --- .github/workflows/docker-docs-publish.yml | 100 ++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 .github/workflows/docker-docs-publish.yml diff --git a/.github/workflows/docker-docs-publish.yml b/.github/workflows/docker-docs-publish.yml new file mode 100644 index 000000000..c6fb36855 --- /dev/null +++ b/.github/workflows/docker-docs-publish.yml @@ -0,0 +1,100 @@ +name: Docker for docs + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + # Only run when the file is edited on main + branches: [ "main" ] + paths: [ "Dockerfile-docs" ] + pull_request: + # Only run when the file is edited on main + branches: [ "main" ] + paths: [ "Dockerfile-docs" ] + workflow_dispatch: {} + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }}-docs + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + file: Dockerfile-docs + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} From 3d36420230b156254597ad87f045bc9d4476f296 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 12:36:31 +0200 Subject: [PATCH 03/13] update: add .dockerignore --- .dockerignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e103eae68 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# .git/ + +build +dist +tools +*.egg-info +*.egg/ +*.pyc +*.swp + +.tox +.pytest_cache +.ruff_cache +.coverage +html/* +__pycache__ + +# Compiled Documentation +docs/_build From 06b0bf3f60683c1581d30239ce217e87648fee6f Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 12:39:05 +0200 Subject: [PATCH 04/13] chore: remove pip cache in Dockerfile-docs --- Dockerfile-docs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile-docs b/Dockerfile-docs index c0cf282d2..b6b5efb14 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -19,9 +19,7 @@ RUN apt-get update --allow-insecure-repositories && \ bc # Install junifer in editable mode -RUN --mount=type=cache,target=/cache/pip \ - PIP_CACHE_DIR=/cache/pip \ - pip install -e .[docs,neurokit2] +RUN pip install -e .[docs,neurokit2] # Add xfms COPY --from=ghcr.io/juaml/human-template-xfms:main /opt/xfms /root/junifer/data/xfms From 192529664da450403291f94da06ab258c90fe5e9 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 12:52:31 +0200 Subject: [PATCH 05/13] chore: improve python deps installation in Dockerfile-docs --- Dockerfile-docs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile-docs b/Dockerfile-docs index b6b5efb14..a35aa5722 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -19,7 +19,9 @@ RUN apt-get update --allow-insecure-repositories && \ bc # Install junifer in editable mode -RUN pip install -e .[docs,neurokit2] +RUN --mount=type=cache,target=/cache/pip \ + PIP_CACHE_DIR=/cache/pip \ + python -m pip install -e .[docs,neurokit2] # Add xfms COPY --from=ghcr.io/juaml/human-template-xfms:main /opt/xfms /root/junifer/data/xfms From 19776af2d553a1e9618cd836e7311218f9606d6e Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 13:36:46 +0200 Subject: [PATCH 06/13] chore: copy junifer dir recursively in Dockerfile-docs --- Dockerfile-docs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile-docs b/Dockerfile-docs index a35aa5722..e877f5e50 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -6,7 +6,7 @@ FROM python:${PYTHON_VERSION}-slim WORKDIR /src COPY .git/ /src/.git/ -COPY junifer /src/junifer +COPY junifer/ /src/junifer/ COPY pyproject.toml /src/pyproject.toml RUN apt-get update --allow-insecure-repositories && \ From 75ee16c64d84e0345c374401ebe0e3e9a77a4d03 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 13:45:02 +0200 Subject: [PATCH 07/13] chore: add README.md in Dockerfile-docs --- Dockerfile-docs | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile-docs b/Dockerfile-docs index e877f5e50..0f82df5f1 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -8,6 +8,7 @@ WORKDIR /src COPY .git/ /src/.git/ COPY junifer/ /src/junifer/ COPY pyproject.toml /src/pyproject.toml +COPY README.md /src/README.md RUN apt-get update --allow-insecure-repositories && \ apt-get install -y \ From 806992f271288cb8b911029b0b1379671ecd20e2 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 13:45:16 +0200 Subject: [PATCH 08/13] chore: explicit copy of vendored h5io in Dockerfile-docs --- Dockerfile-docs | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile-docs b/Dockerfile-docs index 0f82df5f1..183750c18 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -7,6 +7,7 @@ FROM python:${PYTHON_VERSION}-slim WORKDIR /src COPY .git/ /src/.git/ COPY junifer/ /src/junifer/ +COPY junifer/external/h5io/ /src/junifer/external/h5io/ COPY pyproject.toml /src/pyproject.toml COPY README.md /src/README.md From a39c9963f386b1b8dbf267eab9fb99dd379f114c Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 13:57:55 +0200 Subject: [PATCH 09/13] chore: improve apt-get commands in Dockerfile-docs --- Dockerfile-docs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile-docs b/Dockerfile-docs index 183750c18..a31e13586 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -11,7 +11,7 @@ COPY junifer/external/h5io/ /src/junifer/external/h5io/ COPY pyproject.toml /src/pyproject.toml COPY README.md /src/README.md -RUN apt-get update --allow-insecure-repositories && \ +RUN apt-get update && \ apt-get install -y \ pkg-config \ libhdf5-dev \ @@ -33,4 +33,7 @@ COPY --from=antsx/ants:latest /opt/ants /opt/ants ENV PATH="/opt/ants/bin:$PATH" \ LD_LIBRARY_PATH="/opt/ants/lib" +# Clean apt cache +RUN apt-get autoremove --purge && apt-get clean + WORKDIR /src/docs From c43acdf80a452966596f54a12eb768469bac85ed Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 13:58:47 +0200 Subject: [PATCH 10/13] chore: add LABELs in Dockerfile-docs --- Dockerfile-docs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile-docs b/Dockerfile-docs index a31e13586..c8e9f3943 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -4,6 +4,10 @@ ARG PYTHON_VERSION=3.12 FROM python:${PYTHON_VERSION}-slim +LABEL org.opencontainers.image.source=https://github.com/juaml/junifer +LABEL org.opencontainers.image.description="Junifer docs CI container image" +LABEL org.opencontainers.image.licenses=AGPL-3.0-only + WORKDIR /src COPY .git/ /src/.git/ COPY junifer/ /src/junifer/ From 66767340bef03c8c90669c4febf47971c582efa8 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 14:49:27 +0200 Subject: [PATCH 11/13] chore: bypass WORKDIR usage in Dockerfile-docs --- Dockerfile-docs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Dockerfile-docs b/Dockerfile-docs index c8e9f3943..951fd2e81 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -8,12 +8,10 @@ LABEL org.opencontainers.image.source=https://github.com/juaml/junifer LABEL org.opencontainers.image.description="Junifer docs CI container image" LABEL org.opencontainers.image.licenses=AGPL-3.0-only -WORKDIR /src -COPY .git/ /src/.git/ -COPY junifer/ /src/junifer/ -COPY junifer/external/h5io/ /src/junifer/external/h5io/ -COPY pyproject.toml /src/pyproject.toml -COPY README.md /src/README.md +COPY .git/ /opt/src/.git/ +COPY junifer/ /opt/src/junifer/ +COPY pyproject.toml /opt/src/pyproject.toml +COPY README.md /opt/src/README.md RUN apt-get update && \ apt-get install -y \ @@ -26,6 +24,7 @@ RUN apt-get update && \ # Install junifer in editable mode RUN --mount=type=cache,target=/cache/pip \ + cd /opt/src && \ PIP_CACHE_DIR=/cache/pip \ python -m pip install -e .[docs,neurokit2] @@ -39,5 +38,3 @@ ENV PATH="/opt/ants/bin:$PATH" \ # Clean apt cache RUN apt-get autoremove --purge && apt-get clean - -WORKDIR /src/docs From 70ad445f645566a8bdad3f905690d962458c4c16 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 17:09:03 +0200 Subject: [PATCH 12/13] chore: remove editable junifer in Dockerfile-docs --- Dockerfile-docs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/Dockerfile-docs b/Dockerfile-docs index 951fd2e81..116eee16e 100644 --- a/Dockerfile-docs +++ b/Dockerfile-docs @@ -1,33 +1,17 @@ # syntax=docker/dockerfile:1 -ARG PYTHON_VERSION=3.12 - -FROM python:${PYTHON_VERSION}-slim +FROM debian:bookworm-slim LABEL org.opencontainers.image.source=https://github.com/juaml/junifer LABEL org.opencontainers.image.description="Junifer docs CI container image" LABEL org.opencontainers.image.licenses=AGPL-3.0-only -COPY .git/ /opt/src/.git/ -COPY junifer/ /opt/src/junifer/ -COPY pyproject.toml /opt/src/pyproject.toml -COPY README.md /opt/src/README.md - RUN apt-get update && \ apt-get install -y \ - pkg-config \ + # ANTs runtime stuff libhdf5-dev \ - gcc \ - git \ - make \ bc -# Install junifer in editable mode -RUN --mount=type=cache,target=/cache/pip \ - cd /opt/src && \ - PIP_CACHE_DIR=/cache/pip \ - python -m pip install -e .[docs,neurokit2] - # Add xfms COPY --from=ghcr.io/juaml/human-template-xfms:main /opt/xfms /root/junifer/data/xfms # Add ANTs From d586606bc00eb819341e5a4a4a3fc63ebe0d8a64 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 10 Oct 2024 17:16:41 +0200 Subject: [PATCH 13/13] chore: add changelog 373.misc --- docs/changes/newsfragments/373.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/373.misc diff --git a/docs/changes/newsfragments/373.misc b/docs/changes/newsfragments/373.misc new file mode 100644 index 000000000..d89e4fb7c --- /dev/null +++ b/docs/changes/newsfragments/373.misc @@ -0,0 +1 @@ +Add Dockerfile for docs CI and a corresponding action for building and publishing the image by `Synchon Mandal`_