Skip to content
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

[ENH] lighter alpine multi-stage build docker image, ~65% smaller #791

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:

jobs:
build-docker:
strategy:
matrix:
version: ["", "-alpine"]
runs-on: ubuntu-latest
steps:
- name: Checkout source
Expand All @@ -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 }}
Expand Down
34 changes: 34 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM python:3.10-alpine AS builder

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

RUN apk update && apk add --no-cache git git-annex pigz gcompat

RUN pip install --no-cache-dir heudiconv

ENTRYPOINT ["heudiconv"]