forked from Taxel/PlexTraktSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
85 lines (74 loc) · 2.27 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
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
# syntax = docker/dockerfile:1.3-labs
FROM python:3.11-alpine3.16 AS base
WORKDIR /app
# Create minimal layer with extra tools
FROM base AS tools
RUN apk add util-linux shadow
WORKDIR /dist
RUN <<eot
install -d ./usr/bin ./usr/lib
install -p /usr/bin/setpriv ./usr/bin
install -p /usr/lib/libcap-ng.so.0 ./usr/lib
install -p /usr/sbin/usermod /usr/sbin/groupmod ./usr/bin
eot
FROM base AS wheels
# Download wheels/sources
RUN \
--mount=type=cache,id=pip,target=/root/.cache/pip \
--mount=type=bind,source=./requirements.txt,target=./requirements.txt \
pip download --dest /wheels -r requirements.txt
# Build missing wheels
RUN \
--mount=type=cache,id=pip,target=/root/.cache/pip \
pip wheel $(ls /wheels/*.gz /wheels/*.zip 2>/dev/null) --wheel-dir=/wheels
# Install app dependencies
FROM base AS build
RUN apk add git
RUN pip install pipenv
RUN \
--mount=type=bind,from=wheels,source=/wheels,target=/wheels \
pipenv run pip install /wheels/*.whl
FROM base AS compile
ARG APP_VERSION=$APP_VERSION
ENV APP_VERSION=$APP_VERSION
COPY plextraktsync ./plextraktsync/
COPY plextraktsync.sh .
# Create __version__ from $APP_VERSION
RUN echo "__version__ = '${APP_VERSION:-unknown}'" > plextraktsync/__init__.py
RUN cat plextraktsync/__init__.py
RUN python -c "from plextraktsync import __version__; print(__version__)"
# Compile sources
RUN python -m compileall .
RUN chmod -R a+rX,g-w .
FROM base
ENTRYPOINT ["/init"]
LABEL org.opencontainers.image.description Plex-Trakt-Sync is a two-way-sync between trakt.tv and Plex Media Server
ENV \
PATH=/root/.local/bin:$PATH \
PTS_CONFIG_DIR=/app/config \
PTS_CACHE_DIR=/app/config \
PTS_LOG_DIR=/app/config \
PTS_IN_DOCKER=1 \
PYTHONUNBUFFERED=1
VOLUME /app/config
# Add user/group
RUN <<eot
set -x
addgroup --gid 1000 --system plextraktsync
adduser \
--disabled-password \
--gecos "Plex Trakt Sync" \
--home "$(pwd)" \
--ingroup plextraktsync \
--no-create-home \
--uid 1000 \
plextraktsync
eot
# Copy things together
COPY --from=tools /dist /
COPY --from=build /root/.local/share/virtualenvs/app-*/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=compile /app ./
COPY entrypoint.sh /init
RUN ln -s /app/plextraktsync.sh /usr/bin/plextraktsync
# https://github.com/python/cpython/issues/69667
RUN chmod a+x /root