|
| 1 | +from postgres:16 AS builder |
| 2 | + |
| 3 | +ENV DEBIAN_FRONTEND=noninteractive |
| 4 | + |
| 5 | +# Install uv (https://docs.astral.sh/uv/guides/integration/docker/#installing-uv) |
| 6 | +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ |
| 7 | +ENV UV_COMPILE_BYTECODE=1 |
| 8 | +# The uv package cache will be on a cache volume, so can't be linked |
| 9 | +ENV UV_LINK_MODE=copy |
| 10 | +# Assert that the lockfile (uv.lock) is up-to-date. Use `uv lock` to update it |
| 11 | +# manually if this fails the container build. |
| 12 | +ENV UV_LOCKED=1 |
| 13 | + |
| 14 | +WORKDIR /augur |
| 15 | + |
| 16 | +COPY pyproject.toml . |
| 17 | +COPY uv.lock . |
| 18 | +COPY .python-version . |
| 19 | + |
| 20 | +# Install augur's dependencies early to take advantage of build cache |
| 21 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 22 | + uv sync --no-install-project --no-dev |
| 23 | + |
| 24 | +# Copy in the actual code |
| 25 | +# The RUN line below ensure that permissions are set correctly. |
| 26 | +# This is the equivalent of the following docker --chmod flags, but done in a way thats compatible with podman. |
| 27 | +# This can be removed once https://github.com/containers/buildah/issues/6066 or relevant equivalent is fixed |
| 28 | +# - u=rw,u+X: user can read and write all files/dirs and execute directories |
| 29 | +# - go=r,go+X: group and others can read all files/dirs and execute directories |
| 30 | +COPY README.md . |
| 31 | +COPY LICENSE . |
| 32 | +COPY alembic.ini . |
| 33 | +COPY augur/ augur/ |
| 34 | +COPY metadata.py . |
| 35 | +COPY scripts/ scripts/ |
| 36 | + |
| 37 | +RUN find augur -type d -exec chmod u=rwx,go=rx {} + && find augur -type f -exec chmod u=rw,go=r {} + |
| 38 | + |
| 39 | +RUN find scripts -exec chmod u=rwx,go=rx {} + |
| 40 | + |
| 41 | +# Install the main project |
| 42 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 43 | + uv sync --no-dev |
| 44 | + |
| 45 | +# We aren't going to activate the virtualenv (manually or via uv run), so we |
| 46 | +# need adjust the PATH |
| 47 | +ENV PATH="/augur/.venv/bin:${PATH}" |
| 48 | + |
| 49 | +ENV POSTGRES_DB="augur" |
| 50 | +ENV POSTGRES_USER="augur" |
| 51 | +ENV POSTGRES_PASSWORD="augur" |
| 52 | +ENV AUGUR_DB="postgresql+psycopg2://augur:augur@localhost:5432/augur" |
| 53 | +# ENV PGDATA="/var/lib/postgresql/data" |
| 54 | + |
| 55 | +RUN set -e && \ |
| 56 | + gosu postgres initdb && \ |
| 57 | + gosu postgres pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost'" -w start && \ |
| 58 | + gosu postgres psql -c "CREATE USER ${POSTGRES_USER} WITH SUPERUSER PASSWORD '${POSTGRES_PASSWORD}';" && \ |
| 59 | + gosu postgres psql -c "CREATE DATABASE ${POSTGRES_DB} OWNER ${POSTGRES_USER};" && \ |
| 60 | + augur db create-schema && \ |
| 61 | + gosu postgres pg_ctl -D "$PGDATA" -m fast -w stop |
| 62 | + |
| 63 | + |
| 64 | +FROM postgres:16 |
| 65 | + |
| 66 | +COPY --from=builder /var/lib/postgresql/data /var/lib/postgresql/data |
0 commit comments