forked from NOAA-OWP/nwm-eval-mgr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
146 lines (123 loc) · 5.15 KB
/
Copy pathDockerfile
File metadata and controls
146 lines (123 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# syntax=docker/dockerfile:1.4
############################################################################
# Bookworm image for NWM/NextGen Evaluation Manager
#
# Uses the official Python 3.11 Bookworm image rather than building Python
# from source. Python 3.11 is currently required because the pinned TEEHR
# dependency restricts DuckDB to an older release that does not provide a
# compatible Python 3.12 wheel.
############################################################################
ARG BASE_IMAGE=python:3.11-slim-bookworm
FROM ${BASE_IMAGE}
# OCI metadata arguments
ARG BASE_IMAGE
ARG BASE_IMAGE_NAME="${BASE_IMAGE}"
ARG BASE_IMAGE_DIGEST="unknown"
ARG BASE_REVISION="unknown"
ARG IMAGE_SOURCE="unknown"
ARG IMAGE_VENDOR="unknown"
ARG IMAGE_VERSION="unknown"
ARG IMAGE_REVISION="unknown"
ARG IMAGE_CREATED="unknown"
# OCI standard labels
LABEL org.opencontainers.image.base.name="${BASE_IMAGE_NAME}" \
org.opencontainers.image.base.digest="${BASE_IMAGE_DIGEST}" \
io.ngwpc.image.base.revision="${BASE_REVISION}" \
org.opencontainers.image.source="${IMAGE_SOURCE}" \
org.opencontainers.image.vendor="${IMAGE_VENDOR}" \
org.opencontainers.image.version="${IMAGE_VERSION}" \
org.opencontainers.image.revision="${IMAGE_REVISION}" \
org.opencontainers.image.created="${IMAGE_CREATED}" \
org.opencontainers.image.title="NWM/NextGen Evaluation Manager" \
org.opencontainers.image.description="Docker image for the NWM/NextGen evaluation application"
ENV LANG="C.UTF-8" \
PATH="/usr/local/bin:${PATH}"
############################################################################
# System dependencies
############################################################################
RUN --mount=type=cache,target=/var/cache/apt,id=apt-cache-bookworm,sharing=locked \
--mount=type=cache,target=/var/lib/apt,id=apt-lib-bookworm,sharing=locked \
set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
build-essential \
bzip2 \
ca-certificates \
cmake \
curl \
file \
findutils \
git \
jq \
libbz2-dev \
libcurl4-openssl-dev \
libffi-dev \
libsqlite3-dev \
libssl-dev \
m4 \
rsync \
tk-dev \
uuid-dev \
xz-utils \
zlib1g-dev; \
rm -rf /var/lib/apt/lists/*
SHELL ["/bin/bash", "-c"]
############################################################################
# Shared Python virtual environment
############################################################################
# Create a dedicated virtual environment for nwm_metrics and nwm_eval so their
# Python packages are isolated from the base image's global site-packages.
ENV VIRTUAL_ENV="/ngen-app/nwm-eval-mgr-python"
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
RUN set -eux; \
mkdir -p /ngen-app; \
python -m venv "${VIRTUAL_ENV}"
# Install current Python packaging and PEP 517 build tools before installing
# the local nwm_metrics and nwm_eval packages.
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache-bookworm \
set -eux; \
python -m pip install --upgrade \
pip \
setuptools \
wheel \
build \
pyproject_hooks \
packaging
############################################################################
# NWM/NextGen Evaluation Manager
############################################################################
COPY . /ngen-app/nwm-eval-mgr/
WORKDIR /ngen-app/nwm-eval-mgr/
# Install nwm_metrics first because nwm_eval depends on it. The pip cache is
# retained across builds, while the installed packages remain in the image.
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache-bookworm \
set -eux; \
python -m pip install ./nwm_metrics; \
python -m pip install ./nwm_eval; \
python -m pip check
COPY --chmod=0755 \
./docker/run-nwm-eval-mgr.sh \
/ngen-app/bin/run-nwm-eval-mgr.sh
############################################################################
# Git build information
############################################################################
ARG CI_COMMIT_REF_NAME
RUN set -eux; \
repo_url="$(git config --get remote.origin.url)"; \
key="${repo_url##*/}"; \
key="${key%.git}"; \
GIT_INFO_PATH="/ngen-app/${key}_git_info.json"; \
branch="$([ -n "${CI_COMMIT_REF_NAME:-}" ] && echo "${CI_COMMIT_REF_NAME}" || git rev-parse --abbrev-ref HEAD)"; \
jq -n \
--arg commit_hash "$(git rev-parse HEAD)" \
--arg branch "${branch}" \
--arg tags "$(git tag --points-at HEAD | tr '\n' ' ')" \
--arg author "$(git log -1 --pretty=format:'%an')" \
--arg commit_date "$(date -u -d @"$(git log -1 --pretty=format:'%ct')" +'%Y-%m-%d %H:%M:%S UTC')" \
--arg message "$(git log -1 --pretty=format:'%s' | tr '\n' ';')" \
--arg build_date "$(date -u +'%Y-%m-%d %H:%M:%S UTC')" \
"{\"${key}\": {commit_hash: \$commit_hash, branch: \$branch, tags: \$tags, author: \$author, commit_date: \$commit_date, message: \$message, build_date: \$build_date}}" \
> "${GIT_INFO_PATH}"
WORKDIR /
ENTRYPOINT ["/ngen-app/bin/run-nwm-eval-mgr.sh"]
CMD ["--help"]