This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
56 lines (42 loc) · 1.91 KB
/
Dockerfile
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
FROM python:3.12.2-slim-bookworm@sha256:eb53cb99a609b86da6e239b16e1f2aed5e10cfbc538671fc4631093a00f133f2 AS base
# github metadata
LABEL org.opencontainers.image.source=https://github.com/paullockaby/enphase-poller
# install updates and dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -q update && apt-get -y upgrade && \
apt-get install --no-install-recommends -y tini libpq5 && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# used all over the place
ENV APP_NAME=enphase_poller
ENV APP_ROOT=/opt/$APP_NAME
# create the user (do not use yet)
RUN groupadd -g 1000 app && useradd -u 1000 -g 1000 -d /home/app --create-home app
FROM base AS builder
# install dependencies -- need git to run dunamai
RUN apt-get -q update && apt-get install -y --no-install-recommends git
# now become the app user to set up poetry and the versioning tool
RUN pip3 install poetry dunamai --no-cache-dir && mkdir -p $APP_ROOT && chown 1000:100 $APP_ROOT
COPY --chown=1000:1000 pyproject.toml poetry.lock entrypoint $APP_ROOT
RUN chmod +x $APP_ROOT/entrypoint
# we have enough to install the application now
USER app
WORKDIR $APP_ROOT
RUN poetry config virtualenvs.in-project true && \
poetry config virtualenvs.create true && \
poetry install --without=dev --no-interaction --no-directory --no-root
# now copy over the application
COPY --chown=1000:1000 src/$APP_NAME $APP_ROOT/$APP_NAME
# update the version number of our application
COPY --chown=1000:1000 .git/ $APP_ROOT/.git
RUN poetry version $(dunamai from git --dirty)
FROM base AS final
# copy over our actual application
COPY --from=builder --chown=0:0 $APP_ROOT/entrypoint /entrypoint
COPY --from=builder --chown=0:0 $APP_ROOT/.venv $APP_ROOT/.venv
COPY --from=builder --chown=0:0 $APP_ROOT/$APP_NAME $APP_ROOT/$APP_NAME
# set up the virtual environment
ENV VIRTUALENV=$APP_ROOT/.venv
ENV PATH=$VIRTUALENV/bin:$PATH
# start application
USER app
ENTRYPOINT ["/entrypoint"]