diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 0000000000..a18d6b4c86 --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1,14 @@ +.mypy_cache/ +.pytest_cache/ +.ruff_cache/ +.venv/ +.vscode/ + +.minio/ +polar_backoffice/ +tests/ + +ip-geolocation.mmdb +.env* +.jkws.json +.DS_Store diff --git a/server/Dockerfile b/server/Dockerfile index a8a21d3765..bad310b470 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -2,25 +2,20 @@ FROM --platform=$BUILDPLATFORM python:3.12-slim LABEL org.opencontainers.image.source=https://github.com/polarsource/polar LABEL org.opencontainers.image.description="Polar" LABEL org.opencontainers.image.licenses=Apache-2.0 +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ ENV PYTHONUNBUFFERED=1 +ENV UV_COMPILE_BYTECODE=1 WORKDIR /app/server -ADD uv.lock . -ADD pyproject.toml . - -RUN apt-get update && apt-get install -y build-essential redis libpq-dev curl \ - && pip install --upgrade pip uv \ +RUN --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + apt-get update && apt-get install -y build-essential redis libpq-dev curl \ && uv sync --no-group dev --no-group backoffice --frozen \ && apt-get autoremove -y build-essential -ADD polar polar -ADD scripts scripts -ADD run_worker.py . - -ADD migrations migrations -ADD alembic.ini . +ADD . /app/server/ RUN --mount=type=secret,id=IPINFO_ACCESS_TOKEN mkdir /data && curl -fsSL https://ipinfo.io/data/free/country_asn.mmdb?token=$(cat /run/secrets/IPINFO_ACCESS_TOKEN) -o /data/country_asn.mmdb ENV POLAR_IP_GEOLOCATION_DATABASE_DIRECTORY_PATH=/data @@ -29,4 +24,7 @@ ENV POLAR_IP_GEOLOCATION_DATABASE_NAME=country_asn.mmdb ARG RELEASE_VERSION ENV RELEASE_VERSION=${RELEASE_VERSION} +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen + CMD ["uv", "run", "uvicorn", "polar.app:app", "--host", "0.0.0.0", "--port", "10000"] diff --git a/server/poetry.toml b/server/poetry.toml deleted file mode 100644 index 53b35d370d..0000000000 --- a/server/poetry.toml +++ /dev/null @@ -1,3 +0,0 @@ -[virtualenvs] -create = true -in-project = true