From 08079316447862a8a255c506a60b97e36153205a Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 15 Oct 2024 09:21:26 -0400 Subject: [PATCH 1/2] make lighter alpine multi-stage build docker image, ~60% smaller --- Dockerfile | 189 +++++++++-------------------------------------------- 1 file changed, 32 insertions(+), 157 deletions(-) diff --git a/Dockerfile b/Dockerfile index f9bf7fd2..428dbd91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,159 +1,34 @@ -# Generated by Neurodocker and Reproenv. +FROM python:3.10-alpine AS builder -FROM neurodebian:bullseye -ENV PATH="/opt/dcm2niix-v1.0.20220720/bin:$PATH" -RUN apt-get update -qq \ - && apt-get install -y -q --no-install-recommends \ - ca-certificates \ - cmake \ - g++ \ - gcc \ - git \ - make \ - pigz \ - zlib1g-dev \ - && rm -rf /var/lib/apt/lists/* \ - && git clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix \ - && cd /tmp/dcm2niix \ - && git fetch --tags \ - && git checkout v1.0.20220720 \ - && mkdir /tmp/dcm2niix/build \ - && cd /tmp/dcm2niix/build \ - && cmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON -DCMAKE_INSTALL_PREFIX:PATH=/opt/dcm2niix-v1.0.20220720 .. \ - && make -j1 \ - && make install \ - && rm -rf /tmp/dcm2niix -RUN apt-get update -qq \ - && apt-get install -y -q --no-install-recommends \ - gcc \ - git \ - git-annex-standalone \ - libc-dev \ - liblzma-dev \ - netbase \ - pigz \ - && rm -rf /var/lib/apt/lists/* -COPY [".", \ - "/src/heudiconv"] -ENV CONDA_DIR="/opt/miniconda-py39_4.12.0" \ - PATH="/opt/miniconda-py39_4.12.0/bin:$PATH" -RUN apt-get update -qq \ - && apt-get install -y -q --no-install-recommends \ - bzip2 \ - ca-certificates \ - curl \ - && rm -rf /var/lib/apt/lists/* \ - # Install dependencies. - && export PATH="/opt/miniconda-py39_4.12.0/bin:$PATH" \ - && echo "Downloading Miniconda installer ..." \ - && conda_installer="/tmp/miniconda.sh" \ - && curl -fsSL -o "$conda_installer" https://repo.continuum.io/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh \ - && bash "$conda_installer" -b -p /opt/miniconda-py39_4.12.0 \ - && rm -f "$conda_installer" \ - # Prefer packages in conda-forge - && conda config --system --prepend channels conda-forge \ - # Packages in lower-priority channels not considered if a package with the same - # name exists in a higher priority channel. Can dramatically speed up installations. - # Conda recommends this as a default - # https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html - && conda config --set channel_priority strict \ - && conda config --system --set auto_update_conda false \ - && conda config --system --set show_channel_urls true \ - # Enable `conda activate` - && conda init bash \ - && conda install -y --name base \ - "python=3.9" \ - "traits>=4.6.0" \ - "scipy" \ - "numpy" \ - "nomkl" \ - "pandas" \ - "gdcm" \ - && bash -c "source activate base \ - && python -m pip install --no-cache-dir --editable \ - "/src/heudiconv[all]"" \ - # Clean up - && sync && conda clean --all --yes && sync \ - && rm -rf ~/.cache/pip/* -ENTRYPOINT ["heudiconv"] +RUN apk add bash \ + gcc \ + g++ \ + libc-dev \ + make \ + cmake \ + util-linux-dev \ + curl \ + git +RUN pip install --no-cache-dir pylibjpeg-libjpeg traits==6.3.2 + +ARG DCM2NIIX_VERSION=v1.0.20240202 +RUN git clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix \ + && cd /tmp/dcm2niix \ + && git fetch --tags \ + && git checkout $DCM2NIIX_VERSION \ + && mkdir /tmp/dcm2niix/build \ + && cd /tmp/dcm2niix/build \ + && cmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr/ .. \ + && make -j1 \ + && make install \ + && rm -rf /tmp/dcm2niix + +FROM python:3.10-alpine +COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages +COPY --from=builder /usr/bin/dcm2niix /usr/bin/dcm2niix -# Save specification to JSON. -RUN printf '{ \ - "pkg_manager": "apt", \ - "existing_users": [ \ - "root" \ - ], \ - "instructions": [ \ - { \ - "name": "from_", \ - "kwds": { \ - "base_image": "neurodebian:bullseye" \ - } \ - }, \ - { \ - "name": "env", \ - "kwds": { \ - "PATH": "/opt/dcm2niix-v1.0.20220720/bin:$PATH" \ - } \ - }, \ - { \ - "name": "run", \ - "kwds": { \ - "command": "apt-get update -qq\\napt-get install -y -q --no-install-recommends \\\\\\n ca-certificates \\\\\\n cmake \\\\\\n g++ \\\\\\n gcc \\\\\\n git \\\\\\n make \\\\\\n pigz \\\\\\n zlib1g-dev\\nrm -rf /var/lib/apt/lists/*\\ngit clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix\\ncd /tmp/dcm2niix\\ngit fetch --tags\\ngit checkout v1.0.20220720\\nmkdir /tmp/dcm2niix/build\\ncd /tmp/dcm2niix/build\\ncmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON -DCMAKE_INSTALL_PREFIX:PATH=/opt/dcm2niix-v1.0.20220720 ..\\nmake -j1\\nmake install\\nrm -rf /tmp/dcm2niix" \ - } \ - }, \ - { \ - "name": "install", \ - "kwds": { \ - "pkgs": [ \ - "git", \ - "gcc", \ - "pigz", \ - "liblzma-dev", \ - "libc-dev", \ - "git-annex-standalone", \ - "netbase" \ - ], \ - "opts": null \ - } \ - }, \ - { \ - "name": "run", \ - "kwds": { \ - "command": "apt-get update -qq \\\\\\n && apt-get install -y -q --no-install-recommends \\\\\\n gcc \\\\\\n git \\\\\\n git-annex-standalone \\\\\\n libc-dev \\\\\\n liblzma-dev \\\\\\n netbase \\\\\\n pigz \\\\\\n && rm -rf /var/lib/apt/lists/*" \ - } \ - }, \ - { \ - "name": "copy", \ - "kwds": { \ - "source": [ \ - ".", \ - "/src/heudiconv" \ - ], \ - "destination": "/src/heudiconv" \ - } \ - }, \ - { \ - "name": "env", \ - "kwds": { \ - "CONDA_DIR": "/opt/miniconda-py39_4.12.0", \ - "PATH": "/opt/miniconda-py39_4.12.0/bin:$PATH" \ - } \ - }, \ - { \ - "name": "run", \ - "kwds": { \ - "command": "apt-get update -qq\\napt-get install -y -q --no-install-recommends \\\\\\n bzip2 \\\\\\n ca-certificates \\\\\\n curl\\nrm -rf /var/lib/apt/lists/*\\n# Install dependencies.\\nexport PATH=\\"/opt/miniconda-py39_4.12.0/bin:$PATH\\"\\necho \\"Downloading Miniconda installer ...\\"\\nconda_installer=\\"/tmp/miniconda.sh\\"\\ncurl -fsSL -o \\"$conda_installer\\" https://repo.continuum.io/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh\\nbash \\"$conda_installer\\" -b -p /opt/miniconda-py39_4.12.0\\nrm -f \\"$conda_installer\\"\\n# Prefer packages in conda-forge\\nconda config --system --prepend channels conda-forge\\n# Packages in lower-priority channels not considered if a package with the same\\n# name exists in a higher priority channel. Can dramatically speed up installations.\\n# Conda recommends this as a default\\n# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html\\nconda config --set channel_priority strict\\nconda config --system --set auto_update_conda false\\nconda config --system --set show_channel_urls true\\n# Enable `conda activate`\\nconda init bash\\nconda install -y --name base \\\\\\n \\"python=3.9\\" \\\\\\n \\"traits>=4.6.0\\" \\\\\\n \\"scipy\\" \\\\\\n \\"numpy\\" \\\\\\n \\"nomkl\\" \\\\\\n \\"pandas\\" \\\\\\n \\"gdcm\\"\\nbash -c \\"source activate base\\n python -m pip install --no-cache-dir --editable \\\\\\n \\"/src/heudiconv[all]\\"\\"\\n# Clean up\\nsync && conda clean --all --yes && sync\\nrm -rf ~/.cache/pip/*" \ - } \ - }, \ - { \ - "name": "entrypoint", \ - "kwds": { \ - "args": [ \ - "heudiconv" \ - ] \ - } \ - } \ - ] \ -}' > /.reproenv.json -# End saving to specification to JSON. +RUN apk update && apk add --no-cache git git-annex pigz gcompat + +RUN pip install --no-cache-dir heudiconv + +ENTRYPOINT ["heudiconv"] From a2df95207bd1166da692ab269401bc2ead8d9b02 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Wed, 30 Oct 2024 14:34:59 -0400 Subject: [PATCH 2/2] add alpine deployed version with -alpine suffix --- .github/workflows/docker.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 38a407a5..9bcaeb08 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,6 +7,9 @@ on: jobs: build-docker: + strategy: + matrix: + version: ["", "-alpine"] runs-on: ubuntu-latest steps: - name: Checkout source @@ -23,18 +26,20 @@ jobs: run: | # build only if not release tag, i.e. has some "-" in describe # so we do not duplicate work with release workflow. + dockerfile=Dockerfile${version/-/.} git describe --match 'v[0-9]*' | grep -q -e - && \ docker build \ - -t nipy/heudiconv:master \ - -t nipy/heudiconv:unstable \ - . + -t nipy/heudiconv:master${version} \ + -t nipy/heudiconv:unstable${version} \ + . \ + -f $dockerfile - name: Push Docker image run: | git describe --match 'v[0-9]*' | grep -q -e - && ( docker login -u "$DOCKER_LOGIN" --password-stdin <<<"$DOCKER_TOKEN" - docker push nipy/heudiconv:master - docker push nipy/heudiconv:unstable + docker push nipy/heudiconv:master${version} + docker push nipy/heudiconv:unstable${version} ) env: DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }}