mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-25 12:50:23 +00:00
Simplify Docker build (#865)
This commit is contained in:
parent
791a5c73ca
commit
d4c348cc5a
4 changed files with 42 additions and 66 deletions
|
@ -1,4 +1,4 @@
|
||||||
FROM node:18-alpine AS node-build
|
FROM node:20-alpine AS node-build
|
||||||
WORKDIR /etc/linkding
|
WORKDIR /etc/linkding
|
||||||
# install build dependencies
|
# install build dependencies
|
||||||
COPY rollup.config.mjs postcss.config.js package.json package-lock.json ./
|
COPY rollup.config.mjs postcss.config.js package.json package-lock.json ./
|
||||||
|
@ -10,7 +10,7 @@ COPY bookmarks/styles ./bookmarks/styles
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|
||||||
FROM python:3.12.6-alpine3.20 AS python-base
|
FROM python:3.12.6-alpine3.20 AS build-deps
|
||||||
# Add required packages
|
# Add required packages
|
||||||
# alpine-sdk linux-headers pkgconfig: build Python packages from source
|
# alpine-sdk linux-headers pkgconfig: build Python packages from source
|
||||||
# libpq-dev: build Postgres client from source
|
# libpq-dev: build Postgres client from source
|
||||||
|
@ -18,24 +18,8 @@ FROM python:3.12.6-alpine3.20 AS python-base
|
||||||
# libffi-dev openssl-dev rust cargo: build Python cryptography from source
|
# libffi-dev openssl-dev rust cargo: build Python cryptography from source
|
||||||
RUN apk update && apk add alpine-sdk linux-headers libpq-dev pkgconfig icu-dev sqlite-dev libffi-dev openssl-dev rust cargo
|
RUN apk update && apk add alpine-sdk linux-headers libpq-dev pkgconfig icu-dev sqlite-dev libffi-dev openssl-dev rust cargo
|
||||||
WORKDIR /etc/linkding
|
WORKDIR /etc/linkding
|
||||||
|
# install python dependencies
|
||||||
|
|
||||||
FROM python-base AS python-build
|
|
||||||
# install build dependencies
|
|
||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
RUN pip install -U pip && pip install -r requirements.txt
|
|
||||||
# copy files needed for Django build
|
|
||||||
COPY . .
|
|
||||||
COPY --from=node-build /etc/linkding .
|
|
||||||
# remove style sources
|
|
||||||
RUN rm -rf bookmarks/styles
|
|
||||||
# run Django part of the build
|
|
||||||
RUN mkdir data && \
|
|
||||||
python manage.py collectstatic
|
|
||||||
|
|
||||||
|
|
||||||
FROM python-base AS prod-deps
|
|
||||||
COPY requirements.txt ./requirements.txt
|
|
||||||
# Need to build psycopg2 from source for ARM platforms
|
# Need to build psycopg2 from source for ARM platforms
|
||||||
RUN sed -i 's/psycopg2-binary/psycopg2/g' requirements.txt
|
RUN sed -i 's/psycopg2-binary/psycopg2/g' requirements.txt
|
||||||
RUN mkdir /opt/venv && \
|
RUN mkdir /opt/venv && \
|
||||||
|
@ -44,7 +28,7 @@ RUN mkdir /opt/venv && \
|
||||||
/opt/venv/bin/pip install -r requirements.txt
|
/opt/venv/bin/pip install -r requirements.txt
|
||||||
|
|
||||||
|
|
||||||
FROM python-base AS compile-icu
|
FROM build-deps AS compile-icu
|
||||||
# Defines SQLite version
|
# Defines SQLite version
|
||||||
# Since this is only needed for downloading the header files this probably
|
# Since this is only needed for downloading the header files this probably
|
||||||
# doesn't need to be up-to-date, assuming the SQLite APIs used by the ICU
|
# doesn't need to be up-to-date, assuming the SQLite APIs used by the ICU
|
||||||
|
@ -74,19 +58,23 @@ RUN set -x ; \
|
||||||
addgroup -g 82 -S www-data ; \
|
addgroup -g 82 -S www-data ; \
|
||||||
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
|
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
|
||||||
WORKDIR /etc/linkding
|
WORKDIR /etc/linkding
|
||||||
# copy prod dependencies
|
# copy python dependencies
|
||||||
COPY --from=prod-deps /opt/venv /opt/venv
|
COPY --from=build-deps /opt/venv /opt/venv
|
||||||
# copy output from build stage
|
# copy output from node build
|
||||||
COPY --from=python-build /etc/linkding/static static/
|
COPY --from=node-build /etc/linkding/bookmarks/static bookmarks/static/
|
||||||
# copy compiled icu extension
|
# copy compiled icu extension
|
||||||
COPY --from=compile-icu /etc/linkding/libicu.so libicu.so
|
COPY --from=compile-icu /etc/linkding/libicu.so libicu.so
|
||||||
# copy application code
|
# copy application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
# Activate virtual env
|
||||||
|
ENV VIRTUAL_ENV=/opt/venv
|
||||||
|
ENV PATH=/opt/venv/bin:$PATH
|
||||||
|
# Generate static files, remove source styles that are not needed
|
||||||
|
RUN mkdir data && \
|
||||||
|
python manage.py collectstatic
|
||||||
|
|
||||||
# Expose uwsgi server at port 9090
|
# Expose uwsgi server at port 9090
|
||||||
EXPOSE 9090
|
EXPOSE 9090
|
||||||
# Activate virtual env
|
|
||||||
ENV VIRTUAL_ENV /opt/venv
|
|
||||||
ENV PATH /opt/venv/bin:$PATH
|
|
||||||
# Allow running containers as an an arbitrary user in the root group, to support deployment scenarios like OpenShift, Podman
|
# Allow running containers as an an arbitrary user in the root group, to support deployment scenarios like OpenShift, Podman
|
||||||
RUN chmod g+w . && \
|
RUN chmod g+w . && \
|
||||||
chmod +x ./bootstrap.sh
|
chmod +x ./bootstrap.sh
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:18-alpine AS node-build
|
FROM node:20-alpine AS node-build
|
||||||
WORKDIR /etc/linkding
|
WORKDIR /etc/linkding
|
||||||
# install build dependencies
|
# install build dependencies
|
||||||
COPY rollup.config.mjs postcss.config.js package.json package-lock.json ./
|
COPY rollup.config.mjs postcss.config.js package.json package-lock.json ./
|
||||||
|
@ -10,7 +10,7 @@ COPY bookmarks/styles ./bookmarks/styles
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
|
||||||
FROM python:3.12.6-slim-bookworm AS python-base
|
FROM python:3.12.6-slim-bookworm AS build-deps
|
||||||
# Add required packages
|
# Add required packages
|
||||||
# build-essential pkg-config: build Python packages from source
|
# build-essential pkg-config: build Python packages from source
|
||||||
# libpq-dev: build Postgres client from source
|
# libpq-dev: build Postgres client from source
|
||||||
|
@ -20,24 +20,8 @@ RUN apt-get update && apt-get -y install build-essential pkg-config libpq-dev li
|
||||||
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
WORKDIR /etc/linkding
|
WORKDIR /etc/linkding
|
||||||
|
# install python dependencies
|
||||||
|
|
||||||
FROM python-base AS python-build
|
|
||||||
# install build dependencies
|
|
||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
RUN pip install -U pip && pip install -r requirements.txt
|
|
||||||
# copy files needed for Django build
|
|
||||||
COPY . .
|
|
||||||
COPY --from=node-build /etc/linkding .
|
|
||||||
# remove style sources
|
|
||||||
RUN rm -rf bookmarks/styles
|
|
||||||
# run Django part of the build
|
|
||||||
RUN mkdir data && \
|
|
||||||
python manage.py collectstatic
|
|
||||||
|
|
||||||
|
|
||||||
FROM python-base AS prod-deps
|
|
||||||
COPY requirements.txt ./requirements.txt
|
|
||||||
# Need to build psycopg2 from source for ARM platforms
|
# Need to build psycopg2 from source for ARM platforms
|
||||||
RUN sed -i 's/psycopg2-binary/psycopg2/g' requirements.txt
|
RUN sed -i 's/psycopg2-binary/psycopg2/g' requirements.txt
|
||||||
RUN mkdir /opt/venv && \
|
RUN mkdir /opt/venv && \
|
||||||
|
@ -46,7 +30,7 @@ RUN mkdir /opt/venv && \
|
||||||
/opt/venv/bin/pip install -r requirements.txt
|
/opt/venv/bin/pip install -r requirements.txt
|
||||||
|
|
||||||
|
|
||||||
FROM python-base AS compile-icu
|
FROM build-deps AS compile-icu
|
||||||
# Defines SQLite version
|
# Defines SQLite version
|
||||||
# Since this is only needed for downloading the header files this probably
|
# Since this is only needed for downloading the header files this probably
|
||||||
# doesn't need to be up-to-date, assuming the SQLite APIs used by the ICU
|
# doesn't need to be up-to-date, assuming the SQLite APIs used by the ICU
|
||||||
|
@ -67,27 +51,31 @@ RUN wget https://www.sqlite.org/${SQLITE_RELEASE_YEAR}/sqlite-amalgamation-${SQL
|
||||||
gcc -fPIC -shared icu.c `pkg-config --libs --cflags icu-uc icu-io` -o libicu.so
|
gcc -fPIC -shared icu.c `pkg-config --libs --cflags icu-uc icu-io` -o libicu.so
|
||||||
|
|
||||||
|
|
||||||
FROM python:3.12.6-slim-bookworm as linkding
|
FROM python:3.12.6-slim-bookworm AS linkding
|
||||||
LABEL org.opencontainers.image.source="https://github.com/sissbruecker/linkding"
|
LABEL org.opencontainers.image.source="https://github.com/sissbruecker/linkding"
|
||||||
|
# install runtime dependencies
|
||||||
RUN apt-get update && apt-get -y install mime-support libpq-dev libicu-dev libssl3 curl
|
RUN apt-get update && apt-get -y install mime-support libpq-dev libicu-dev libssl3 curl
|
||||||
WORKDIR /etc/linkding
|
WORKDIR /etc/linkding
|
||||||
# copy prod dependencies
|
# copy python dependencies
|
||||||
COPY --from=prod-deps /opt/venv /opt/venv
|
COPY --from=build-deps /opt/venv /opt/venv
|
||||||
# copy output from build stage
|
# copy output from node build
|
||||||
COPY --from=python-build /etc/linkding/static static/
|
COPY --from=node-build /etc/linkding/bookmarks/static bookmarks/static/
|
||||||
# copy compiled icu extension
|
# copy compiled icu extension
|
||||||
COPY --from=compile-icu /etc/linkding/libicu.so libicu.so
|
COPY --from=compile-icu /etc/linkding/libicu.so libicu.so
|
||||||
# copy application code
|
# copy application code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
# Activate virtual env
|
||||||
|
ENV VIRTUAL_ENV=/opt/venv
|
||||||
|
ENV PATH=/opt/venv/bin:$PATH
|
||||||
|
# Generate static files
|
||||||
|
RUN mkdir data && \
|
||||||
|
python manage.py collectstatic
|
||||||
|
|
||||||
# Expose uwsgi server at port 9090
|
# Expose uwsgi server at port 9090
|
||||||
EXPOSE 9090
|
EXPOSE 9090
|
||||||
# Activate virtual env
|
|
||||||
ENV VIRTUAL_ENV /opt/venv
|
|
||||||
ENV PATH /opt/venv/bin:$PATH
|
|
||||||
# Allow running containers as an an arbitrary user in the root group, to support deployment scenarios like OpenShift, Podman
|
# Allow running containers as an an arbitrary user in the root group, to support deployment scenarios like OpenShift, Podman
|
||||||
RUN ["chmod", "g+w", "."]
|
RUN chmod g+w . && \
|
||||||
# Run bootstrap logic
|
chmod +x ./bootstrap.sh
|
||||||
RUN ["chmod", "+x", "./bootstrap.sh"]
|
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --retries=3 --timeout=1s \
|
HEALTHCHECK --interval=30s --retries=3 --timeout=1s \
|
||||||
CMD curl -f http://localhost:${LD_SERVER_PORT:-9090}/${LD_CONTEXT_PATH}health || exit 1
|
CMD curl -f http://localhost:${LD_SERVER_PORT:-9090}/${LD_CONTEXT_PATH}health || exit 1
|
||||||
|
|
|
@ -128,14 +128,6 @@ STATIC_URL = "/" + LD_CONTEXT_PATH + "static/"
|
||||||
# Collect static files in static folder
|
# Collect static files in static folder
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
||||||
|
|
||||||
STATICFILES_DIRS = [
|
|
||||||
# Resolve theme files from style source folder
|
|
||||||
os.path.join(BASE_DIR, "bookmarks", "styles"),
|
|
||||||
# Resolve downloaded files in dev environment
|
|
||||||
os.path.join(BASE_DIR, "data", "favicons"),
|
|
||||||
os.path.join(BASE_DIR, "data", "previews"),
|
|
||||||
]
|
|
||||||
|
|
||||||
# REST framework
|
# REST framework
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
"DEFAULT_AUTHENTICATION_CLASSES": [
|
"DEFAULT_AUTHENTICATION_CLASSES": [
|
||||||
|
|
|
@ -20,6 +20,14 @@ INTERNAL_IPS = [
|
||||||
# Allow access through ngrok
|
# Allow access through ngrok
|
||||||
CSRF_TRUSTED_ORIGINS = ["https://*.ngrok-free.app"]
|
CSRF_TRUSTED_ORIGINS = ["https://*.ngrok-free.app"]
|
||||||
|
|
||||||
|
STATICFILES_DIRS = [
|
||||||
|
# Resolve theme files from style source folder
|
||||||
|
os.path.join(BASE_DIR, "bookmarks", "styles"),
|
||||||
|
# Resolve downloaded files in dev environment
|
||||||
|
os.path.join(BASE_DIR, "data", "favicons"),
|
||||||
|
os.path.join(BASE_DIR, "data", "previews"),
|
||||||
|
]
|
||||||
|
|
||||||
# Enable debug logging
|
# Enable debug logging
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
|
|
Loading…
Reference in a new issue