-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from jim60105/main
Rewrite Dockerfile
- Loading branch information
Showing
7 changed files
with
75 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sh eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ tmp* | |
__pycache__ | ||
.python-version | ||
cookies.txt | ||
master_urls.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,56 @@ | ||
FROM python:alpine as base | ||
FROM python:3.11-alpine as build | ||
|
||
WORKDIR /output | ||
VOLUME /output | ||
# RUN mount cache for multi-arch: https://github.com/docker/buildx/issues/549#issuecomment-1788297892 | ||
ARG TARGETARCH | ||
ARG TARGETVARIANT | ||
|
||
# Install build dependencies | ||
RUN apk add --no-cache build-base libffi-dev | ||
|
||
FROM base as builder | ||
WORKDIR /app | ||
|
||
ENV PIP_DEFAULT_TIMEOUT=100 \ | ||
PIP_DISABLE_PIP_VERSION_CHECK=1 \ | ||
PIP_NO_CACHE_DIR=1 | ||
# Set up venv | ||
RUN python3 -m venv /venv | ||
ENV PATH="/venv/bin:$PATH" | ||
|
||
RUN apk add --no-cache gcc libffi-dev musl-dev | ||
RUN pip install poetry | ||
RUN python -m venv /venv | ||
# Install poetry | ||
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip pip3.11 install poetry | ||
|
||
# Install dependencies | ||
COPY pyproject.toml poetry.lock ./ | ||
RUN poetry export -f requirements.txt | /venv/bin/pip install -r /dev/stdin | ||
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip poetry export -f requirements.txt | pip3.11 install -r /dev/stdin | ||
|
||
# Build | ||
COPY . . | ||
RUN poetry build && /venv/bin/pip install dist/*.whl | ||
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip poetry build && pip3.11 install dist/*.whl | ||
|
||
# Uninstall them inside venv | ||
RUN pip3.11 uninstall -y setuptools pip && \ | ||
pip3.11 uninstall -y setuptools pip | ||
|
||
FROM python:3.11-alpine as final | ||
|
||
# Uninstall them for security purpose | ||
RUN pip3.11 uninstall -y setuptools pip && \ | ||
rm -rf /root/.cache/pip | ||
|
||
FROM base as final | ||
# Copy venv | ||
COPY --link --from=build /venv /venv | ||
ENV PATH="/venv/bin:$PATH" | ||
|
||
RUN apk add --no-cache dumb-init ffmpeg | ||
COPY --from=builder /venv /venv | ||
# Use dumb-init to handle signals | ||
RUN apk add --no-cache dumb-init | ||
|
||
# ffmpeg | ||
COPY --link --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/ | ||
|
||
# Create output directory | ||
RUN mkdir -p /output && chown 1001:1001 /output | ||
VOLUME [ "/output" ] | ||
|
||
# Run as non-root user | ||
USER 1001 | ||
WORKDIR /output | ||
|
||
ENTRYPOINT [ "/usr/bin/dumb-init", "--", "/venv/bin/twspace_dl"] | ||
STOPSIGNAL SIGINT | ||
ENTRYPOINT [ "dumb-init", "--", "/venv/bin/twspace_dl" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters