Skip to content

Commit

Permalink
Minimize Docker image size
Browse files Browse the repository at this point in the history
Using the pre-built wheels from PyPI with the Debian-based images is a lot more efficient: 1.2G vs. 0.2G.
  • Loading branch information
good-bye authored and TheAssassin committed May 17, 2024
1 parent b2c2643 commit 1211246
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
21 changes: 6 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
FROM python:3.10-alpine
FROM python:3.10-slim

MAINTAINER "TheAssassin <[email protected]>"

# this port won't ever change, really
EXPOSE 5000

# install dependencies
RUN apk add --no-cache gcc libxml2-dev libxml2 musl-dev xmlsec xmlsec-dev curl libffi-dev openssl-dev make rust cargo

# create non-root user
RUN adduser -S app

# install poetry system-wide, the rest per user
# for some reason, we can't just pip install the entire package, but have to invoke poetry directly...
RUN pip install poetry
RUN adduser app

USER app
WORKDIR /app

# must provide both the
COPY pyproject.toml poetry.lock /app/
COPY README.md pyproject.toml poetry.lock /app/
COPY np_web_api/ /app/np_web_api/

# note: pip doesn't support editable (-e) installs with pyproject.toml only
RUN poetry install
RUN pip install .

HEALTHCHECK --interval=5m --timeout=15s \
CMD curl -f http://localhost:5000/data.json || exit 1

COPY np_web_api/ /app/np_web_api/

# using just one worker worked fine so far, and allows for some very crappy "synchronization" between requests by just
# using global variables, which help prevent concurrent requests to update cached data
CMD ["poetry", "run", "uvicorn", "np_web_api.asgi:app", "--host", "0.0.0.0", "--port", "5000", "--workers", "1", "--no-access-log"]
CMD ["python", "-m", "uvicorn", "np_web_api.asgi:app", "--host", "0.0.0.0", "--port", "5000", "--workers", "1", "--no-access-log"]
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ license = "MIT"
readme = "README.md"
homepage = "https://github.com/TeamNewPipe/web-api"
repository = "https://github.com/TeamNewPipe/web-api.git"
package-mode = false
packages = [
{ include = "np_web_api" }
]

[tool.poetry.dependencies]
# quart requires Python 3.7+
Expand Down

0 comments on commit 1211246

Please sign in to comment.