Skip to content

Commit 6272100

Browse files
authored
Merge pull request #38 from robomics/dockerfile
Add Dockerfile
2 parents 1c9de4e + 02651f2 commit 6272100

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (C) 2024 Roberto Rossini <roberros@uio.no>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Ignore everything
6+
**
7+
8+
# Allowed directories
9+
!src/**/*.py
10+
!test/**/*.py
11+
12+
13+
# Allowed files
14+
!LICENCE
15+
!pyproject.toml
16+
!README.md

Dockerfile

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Copyright (C) 2024 Roberto Rossini <roberros@uio.no>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
##### IMPORTANT #####
6+
# This Dockerfile requires several build arguments to be defined through --build-arg
7+
# See utils/devel/build_dockerfile.sh for an example of how to build this Dockerfile
8+
#####################
9+
10+
ARG BASE_IMAGE
11+
ARG BASE_IMAGE_DIGEST
12+
FROM "${BASE_IMAGE}@${BASE_IMAGE_DIGEST}" AS builder
13+
14+
ARG GIT_HASH
15+
ARG CREATION_DATE
16+
ARG VERSION
17+
18+
RUN if [ -z "$GIT_HASH" ]; then echo "Missing GIT_HASH --build-arg" && exit 1; fi \
19+
&& if [ -z "$CREATION_DATE" ]; then echo "Missing CREATION_DATE --build-arg" && exit 1; fi \
20+
&& if [ -z "$VERSION" ]; then echo "Missing VERSION --build-arg" && exit 1; fi
21+
22+
ARG SETUPTOOLS_SCM_PRETEND_VERSION="$VERSION"
23+
ARG src_dir='/root/stripepy'
24+
ARG install_dir='/opt/stripepy'
25+
26+
COPY . "$src_dir/"
27+
28+
RUN python3 -m venv "$install_dir" \
29+
&& "$install_dir/bin/pip" install "$src_dir" -v
30+
31+
32+
ARG BASE_IMAGE
33+
ARG BASE_IMAGE_DIGEST
34+
FROM "${BASE_IMAGE}@${BASE_IMAGE_DIGEST}" AS tester
35+
36+
ARG VERSION
37+
38+
ARG SETUPTOOLS_SCM_PRETEND_VERSION="$VERSION"
39+
ARG src_dir='/root/stripepy'
40+
ARG install_dir='/opt/stripepy'
41+
42+
COPY --from=builder "$src_dir" "$src_dir"
43+
COPY --from=builder "$install_dir" "$install_dir"
44+
45+
RUN "$install_dir/bin/pip" install "$src_dir[test]" -v
46+
47+
RUN "$install_dir/bin/python3" -m pytest "$src_dir/test"
48+
49+
50+
ARG BASE_IMAGE
51+
ARG BASE_IMAGE_DIGEST
52+
FROM "${BASE_IMAGE}@${BASE_IMAGE_DIGEST}" AS base
53+
54+
ARG BASE_IMAGE
55+
ARG BASE_IMAGE_DIGEST
56+
ARG GIT_HASH
57+
ARG CREATION_DATE
58+
ARG VERSION
59+
60+
ARG src_dir='/root/stripepy'
61+
ARG install_dir='/opt/stripepy'
62+
63+
COPY --from=builder "$install_dir" /opt/stripepy/
64+
COPY --from=tester "$src_dir/LICENCE" /opt/stripepy/share/licenses/stripepy/LICENCE
65+
66+
WORKDIR /data
67+
ENTRYPOINT ["/opt/stripepy/bin/stripepy"]
68+
ENV PATH="$PATH:/opt/stripepy/bin"
69+
70+
RUN stripepy --help
71+
RUN stripepy --version
72+
73+
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
74+
LABEL org.opencontainers.image.authors='Andrea Raffo <andrea.raffo@ibv.uio.no>,Roberto Rossini <roberros@uio.no>'
75+
LABEL org.opencontainers.image.url='https://github.com/paulsengroup/stripepy'
76+
LABEL org.opencontainers.image.documentation='https://github.com/paulsengroup/stripepy'
77+
LABEL org.opencontainers.image.source='https://github.com/paulsengroup/stripepy'
78+
LABEL org.opencontainers.image.licenses='MIT'
79+
LABEL org.opencontainers.image.title='StripePy'
80+
LABEL org.opencontainers.image.description='StripePy recognizes linear patterns in chromosome conformation capture contact maps using geometric reasoning'
81+
LABEL org.opencontainers.image.base.digest="$BASE_IMAGE_DIGEST"
82+
LABEL org.opencontainers.image.base.name="$BASE_IMAGE"
83+
84+
LABEL org.opencontainers.image.revision="$GIT_HASH"
85+
LABEL org.opencontainers.image.created="$CREATION_DATE"
86+
LABEL org.opencontainers.image.version="$VERSION"

utils/devel/build_dockerfile.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2024 Roberto Rossini <roberros@uio.no>
4+
#
5+
# SPDX-License-Identifier: MIT
6+
7+
set -e
8+
set -u
9+
set -o pipefail
10+
11+
ARGC=$#
12+
13+
if [ $ARGC -gt 2 ]; then
14+
1>&2 echo "Usage: $0 [platform]"
15+
1>&2 echo "Example: $0 linux/amd64"
16+
1>&2 echo "Example: $0 linux/amd64,linux/arm64"
17+
exit 1
18+
fi
19+
20+
IMAGE_NAME='stripepy'
21+
22+
if [ "$(uname)" == "Darwin" ]; then
23+
BUILD_USER="$USER"
24+
else
25+
BUILD_USER='root'
26+
fi
27+
28+
if [ $ARGC -eq 1 ]; then
29+
PLATFORM="$1"
30+
else
31+
PLATFORM="$(sudo -u "$BUILD_USER" docker info --format '{{ .OSType }}/{{ .Architecture }}')"
32+
fi
33+
34+
venv_dir="$(mktemp -d)"
35+
36+
trap "rm -rf '$venv_dir'" EXIT
37+
38+
python3 -m venv "$venv_dir"
39+
40+
"$venv_dir/bin/pip" install hatchling hatch_vcs
41+
VERSION="$("$venv_dir/bin/hatchling" version)"
42+
43+
GIT_HASH="$(git rev-parse HEAD)"
44+
GIT_SHORT_HASH="$(git rev-parse --short HEAD)"
45+
GIT_TAG="$(git for-each-ref 'refs/tags/v*.*.*' --count 1 --sort=-v:refname --format "%(refname:short)" --points-at HEAD)"
46+
CREATION_DATE="$(date -I)"
47+
48+
if [[ $(git status --porcelain -uno) ]]; then
49+
GIT_IS_DIRTY=1
50+
else
51+
GIT_IS_DIRTY=0
52+
fi
53+
54+
IMAGE_TAG="sha-$GIT_SHORT_HASH"
55+
if [ $GIT_IS_DIRTY -ne 0 ]; then
56+
IMAGE_TAG+='-dirty'
57+
fi
58+
59+
if [ -z "$GIT_TAG" ]; then
60+
GIT_TAG="sha-$GIT_SHORT_HASH"
61+
else
62+
GIT_TAG="$GIT_TAG"
63+
fi
64+
65+
BASE_IMAGE='docker.io/library/python:3.12.7'
66+
2>&1 echo "Building \"$IMAGE_NAME:$IMAGE_TAG\" (stripepy v$VERSION) for platform $PLATFORM..."
67+
68+
sudo -u "$BUILD_USER" docker pull "$BASE_IMAGE"
69+
BASE_IMAGE_DIGEST="$(sudo -u "$BUILD_USER" docker inspect --format='{{index .RepoDigests 0}}' "$BASE_IMAGE" | cut -f 2 -d '@')"
70+
71+
sudo -u "$BUILD_USER" docker buildx build --platform "$PLATFORM" --load \
72+
--build-arg "BASE_IMAGE=$BASE_IMAGE" \
73+
--build-arg "BASE_IMAGE_DIGEST=$BASE_IMAGE_DIGEST" \
74+
--build-arg "GIT_HASH=$GIT_HASH" \
75+
--build-arg "CREATION_DATE=$CREATION_DATE" \
76+
--build-arg "VERSION=$VERSION" \
77+
-t "$IMAGE_NAME:latest" \
78+
-t "$IMAGE_NAME:$(echo "$CREATION_DATE" | tr -d '\-' )" \
79+
-t "$IMAGE_NAME:$IMAGE_TAG" \
80+
"$(git rev-parse --show-toplevel)"
81+
82+
# sudo singularity build -F "${img_name}_v${ver}.sif" \
83+
# "docker-daemon://${img_name}:${ver}"

0 commit comments

Comments
 (0)