Skip to content

Commit e2ba11d

Browse files
authored
Merge pull request #599 from powerapi-ng/build/container-image-install-method
build(Dockerfile): Enable build-time selection of powerapi install source
2 parents bbd3dcb + 6edfd7d commit e2ba11d

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Dockerfile

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
FROM python:3-slim@sha256:60248ff36cf701fcb6729c085a879d81e4603f7f507345742dc82d4b38d16784
1+
# ---- Image configuration flags:
2+
ARG POWERAPI_INSTALL_METHOD="pypi"
3+
ARG POWERAPI_COMPONENTS="everything"
4+
ARG POWERAPI_VERSION=""
5+
6+
# ---- Base stage (common setup):
7+
FROM python:3-slim@sha256:60248ff36cf701fcb6729c085a879d81e4603f7f507345742dc82d4b38d16784 AS base
28

39
RUN useradd -m -s /bin/bash powerapi
410
WORKDIR /home/powerapi
511

612
RUN python -m venv --clear /opt/powerapi-venv
7-
ENV VIRTUAL_ENV=/opt/powerapi-venv PATH="/opt/powerapi-venv/bin:$PATH"
13+
ENV VIRTUAL_ENV=/opt/powerapi-venv PATH="/opt/powerapi-venv/bin:${PATH}"
14+
15+
# ---- Install PowerAPI package from PyPI.org:
16+
FROM base AS pypi
17+
18+
ARG POWERAPI_COMPONENTS
19+
ARG POWERAPI_VERSION
20+
21+
RUN python -m pip install --no-cache-dir "powerapi[${POWERAPI_COMPONENTS}]${POWERAPI_VERSION:+==$POWERAPI_VERSION}"
22+
23+
# ---- Install PowerAPI package from local sources (editable install):
24+
FROM base AS local
25+
26+
ARG POWERAPI_COMPONENTS
827

928
COPY --chown=powerapi . /tmp/powerapi
10-
RUN pip install --no-cache-dir "/tmp/powerapi[everything]" && rm -r /tmp/powerapi
29+
RUN python -m pip install --no-cache-dir "/tmp/powerapi[${POWERAPI_COMPONENTS}]" && rm -r /tmp/powerapi
30+
31+
# ---- Final stage:
32+
FROM ${POWERAPI_INSTALL_METHOD} AS final
1133

12-
ENTRYPOINT ["sh", "-c", "echo 'This container image should be used as a base image for a formula and is not intended to be run directly.' >&2; exit 1"]
34+
ENTRYPOINT ["sh", "-c", "echo 'This container image is intended to be used as a base and should not be run directly.' >&2; exit 1"]

0 commit comments

Comments
 (0)