Skip to content

Commit

Permalink
refactor: optimise Dockerfile for smaller image
Browse files Browse the repository at this point in the history
  • Loading branch information
qx6ghqkz committed Dec 11, 2024
1 parent 1f24699 commit 0ecfd1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
35 changes: 10 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#
# gallery-dl-server Dockerfile
#

FROM python:3.12-alpine

RUN apk add --no-cache \
Expand All @@ -11,16 +7,11 @@ RUN apk add --no-cache \

WORKDIR /usr/src/app

RUN python -m venv venv

ENV PATH="/usr/src/app/venv/bin:$PATH"

COPY requirements.txt .

RUN apk add --no-cache --virtual build-dependencies gcc libc-dev make \
&& pip install --no-cache-dir --upgrade pip \
RUN apk add --no-cache --virtual build-deps gcc libc-dev make \
&& pip install --no-cache-dir -r requirements.txt \
&& apk del build-dependencies
&& apk del build-deps

COPY . .

Expand All @@ -30,22 +21,16 @@ EXPOSE $CONTAINER_PORT

VOLUME ["/gallery-dl"]

ENV USER=app
ENV GROUP=$USER
ENV USER=appuser
ENV GROUP=appgroup
ENV UID=1000
ENV GID=$UID

RUN addgroup --gid "$GID" "$GROUP" \
&& adduser --disabled-password --gecos "" --home "$(pwd)" --ingroup "$GROUP" --no-create-home --uid "$UID" $USER

RUN mkdir -p /.cache/pip \
&& mkdir /.local

RUN chown -R $USER:$GROUP . \
&& chown -R $USER:$GROUP /.cache/pip \
&& chown -R $USER:$GROUP /.local
ENV GID=1000

RUN chmod +x ./start.sh
RUN addgroup --gid $GID $GROUP \
&& adduser --disabled-password --gecos "" --home $(pwd) --no-create-home --ingroup $GROUP --uid $UID $USER \
&& mkdir -p /.cache/pip /.local \
&& chown -R $UID:$GID . /.cache/pip /.local \
&& chmod +x ./start.sh

USER $USER

Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
exec uvicorn gallery-dl-server:app --host 0.0.0.0 --port ${CONTAINER_PORT} --log-level info --no-access-log
exec uvicorn gallery-dl-server:app --host 0.0.0.0 --port $CONTAINER_PORT --log-level info --no-access-log

0 comments on commit 0ecfd1f

Please sign in to comment.