mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-17 13:21:48 +01:00
chore: optimize Dockerfile (#2576)
By doing a multi-stage Docker build, the size of the final image is reduced by ~45%.
This commit is contained in:
parent
a00292544f
commit
1bee84d419
@ -3,6 +3,7 @@ data
|
|||||||
docker
|
docker
|
||||||
docs
|
docs
|
||||||
tests
|
tests
|
||||||
|
node_modules
|
||||||
|
|
||||||
lnbits/static/css/*
|
lnbits/static/css/*
|
||||||
lnbits/static/bundle.js
|
lnbits/static/bundle.js
|
||||||
|
45
Dockerfile
45
Dockerfile
@ -1,25 +1,50 @@
|
|||||||
FROM python:3.10-slim-bookworm
|
FROM python:3.10-slim-bookworm AS builder
|
||||||
|
|
||||||
RUN apt-get clean
|
RUN apt-get clean
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
RUN apt-get install -y curl pkg-config build-essential libnss-myhostname automake libtool libffi-dev libgmp-dev
|
RUN apt-get install -y curl pkg-config build-essential libnss-myhostname
|
||||||
|
|
||||||
RUN curl -sSL https://install.python-poetry.org | python3 -
|
RUN curl -sSL https://install.python-poetry.org | python3 -
|
||||||
ENV PATH="/root/.local/bin:$PATH"
|
ENV PATH="/root/.local/bin:$PATH"
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Only copy the files required to install the dependencies
|
||||||
|
COPY pyproject.toml poetry.lock ./
|
||||||
|
|
||||||
|
RUN mkdir data
|
||||||
|
|
||||||
|
ENV POETRY_NO_INTERACTION=1 \
|
||||||
|
POETRY_VIRTUALENVS_IN_PROJECT=1 \
|
||||||
|
POETRY_VIRTUALENVS_CREATE=1 \
|
||||||
|
POETRY_CACHE_DIR=/tmp/poetry_cache
|
||||||
|
|
||||||
|
RUN poetry install --only main
|
||||||
|
|
||||||
|
FROM python:3.10-slim-bookworm
|
||||||
|
|
||||||
# needed for backups postgresql-client version 14 (pg_dump)
|
# needed for backups postgresql-client version 14 (pg_dump)
|
||||||
RUN apt install -y postgresql-common ca-certificates
|
RUN apt-get update && apt-get -y upgrade && \
|
||||||
RUN install -d /usr/share/postgresql-common/pgdg
|
apt-get -y install gnupg2 curl lsb-release && \
|
||||||
RUN curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
|
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
|
||||||
RUN sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
|
||||||
RUN apt-get update
|
apt-get update && \
|
||||||
RUN apt-get install -y postgresql-client-14
|
apt-get -y install postgresql-client-14 postgresql-client-common && \
|
||||||
|
apt-get clean all && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN curl -sSL https://install.python-poetry.org | python3 -
|
||||||
|
ENV PATH="/root/.local/bin:$PATH"
|
||||||
|
|
||||||
|
ENV POETRY_NO_INTERACTION=1 \
|
||||||
|
POETRY_VIRTUALENVS_IN_PROJECT=1 \
|
||||||
|
POETRY_VIRTUALENVS_CREATE=1 \
|
||||||
|
VIRTUAL_ENV=/app/.venv \
|
||||||
|
PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
COPY --from=builder /app/.venv .venv
|
||||||
RUN mkdir data
|
|
||||||
|
|
||||||
RUN poetry install --only main
|
RUN poetry install --only main
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user