Skip to content

Commit 70b7a34

Browse files
committed
changed dockerfile distrib to alpine
1 parent cd9262d commit 70b7a34

File tree

3 files changed

+47
-59
lines changed

3 files changed

+47
-59
lines changed

Dockerfile

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,60 @@
1-
FROM python:3.10-slim-bookworm AS builder
1+
FROM python:3.10-alpine3.22 AS builder
22

3-
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
3+
COPY --from=ghcr.io/astral-sh/uv:0.9 /uv /uvx /bin/
44

5-
# Install build dependencies
6-
RUN apt update && apt upgrade -y && apt install -y --no-install-recommends \
5+
RUN apk add --update --no-cache --virtual build-dependencies \
76
curl \
7+
bash \
88
git \
9-
build-essential \
10-
libldap2-dev \
11-
libsasl2-dev && \
12-
rm -rf /var/lib/apt/lists/*
13-
14-
# Install nodejs 18 with npm
15-
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
16-
apt update && \
17-
apt install -y --no-install-recommends nodejs && \
18-
rm -rf /var/lib/apt/lists/*
19-
20-
# Download the latest uv installer
21-
ADD https://astral.sh/uv/install.sh /uv-installer.sh
22-
23-
# Run the installer then remove it
24-
RUN sh /uv-installer.sh && rm /uv-installer.sh
9+
tar \
10+
musl-dev \
11+
gcc \
12+
openssl-dev \
13+
libffi-dev \
14+
cyrus-sasl-dev \
15+
openldap-dev \
16+
npm
2517

2618
# Ensure the installed uv binary is on the `PATH`
2719
ENV PATH="/root/.local/bin/:$PATH"
2820

29-
# Copy dependency files & set workdir
3021
WORKDIR /opt/lemur
3122
COPY . .
3223

33-
# Install Python dependencies with uv
34-
RUN uv sync --frozen
24+
RUN uv sync --frozen --compile-bytecode
25+
26+
RUN curl -sSL https://github.com/caddyserver/caddy/releases/download/v2.10.2/caddy_2.10.2_linux_amd64.tar.gz | tar xz -C /usr/bin
3527

3628
RUN npm install \
3729
&& npm run build_static \
3830
&& node_modules/.bin/gulp package --urlContextPath="" \
39-
&& rm -rf node_modules bower_components .tmp
31+
&& rm -rf node_modules bower_components .tmp \
32+
&& apk del build-dependencies
4033

4134

42-
FROM python:3.10-slim-bookworm AS runtime
35+
FROM python:3.10-alpine3.22 AS runtime
4336

44-
ENV PATH="/opt/lemur/.venv/bin:${PATH}" \
45-
PYTHONUNBUFFERED=1 \
46-
PYTHONDONTWRITEBYTECODE=1
37+
ENV uid=1337
38+
ENV gid=1337
39+
ENV user=lemur
40+
ENV group=lemur
4741

48-
RUN apt update && apt upgrade -y && apt install -y --no-install-recommends \
49-
debian-keyring debian-archive-keyring apt-transport-https curl libldap-2.5-0 make gnupg && \
50-
rm -rf /var/lib/apt/lists/*
42+
ENV PATH="/opt/lemur/.venv/bin:${PATH}" \
43+
PYTHONUNBUFFERED=1
5144

52-
RUN curl -1sLf https://dl.cloudsmith.io/public/caddy/stable/gpg.key | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg && \
53-
curl -1sLf https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt | tee /etc/apt/sources.list.d/caddy-stable.list && \
54-
chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg && \
55-
chmod o+r /etc/apt/sources.list.d/caddy-stable.list && \
56-
apt update && apt install caddy && \
57-
rm -rf /var/lib/apt/lists/*
45+
RUN apk add --update --no-cache curl libldap bash openssl
5846

59-
# Create lemur user
60-
RUN useradd --create-home --shell /bin/bash lemur
47+
RUN addgroup -S ${group} -g ${gid} && \
48+
adduser -D -S ${user} -G ${group} -u ${uid} && \
49+
apk add --no-cache --update curl
6150

62-
# Copy built project
63-
COPY --from=builder --chown=lemur:lemur /opt/lemur /opt/lemur
51+
COPY --from=builder --chown=${uid}:${gid} /opt/lemur /opt/lemur
52+
COPY --from=builder --chown=${uid}:${gid} /usr/bin/caddy /usr/bin/caddy
6453

65-
# Ensure entrypoint is executable
6654
RUN chmod +x /opt/lemur/docker/entrypoint.sh
6755

68-
# Switch to the user
6956
USER lemur
7057

71-
# Expose port
7258
EXPOSE 80
7359

74-
# Default command
7560
ENTRYPOINT ["/opt/lemur/docker/entrypoint.sh"]

compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
POSTGRES_USER: lemur
77
POSTGRES_PASSWORD: lemur
88
POSTGRES_HOST: postgres
9-
network_mode: host
9+
# network_mode: host
1010
ports:
1111
- "5432:5432"
1212
volumes:
@@ -41,8 +41,11 @@ services:
4141
LOG_FILE: "/opt/lemur/lemur.log"
4242
SQLALCHEMY_DATABASE_URI: "postgresql://lemur:lemur@postgres:5432/lemur"
4343
LEMUR_CONF: "/opt/lemur/lemur.conf.py"
44-
LEMUR_INIT: "1"
45-
LEMUR_PASSWORD: "lemur"
44+
# LEMUR_INIT: "1"
45+
# LEMUR_PASSWORD: "lemur"
46+
volumes:
47+
- ./lemur.conf.py:/opt/lemur/lemur.conf.py
48+
- ./lemur.log:/opt/lemur/lemur.log
4649
ports:
4750
- "80:80"
4851
healthcheck:

docker/entrypoint.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
#!/usr/bin/env bash
22
set -e
33

4+
source /opt/lemur/.venv/bin/activate
5+
46
echo "[supervisor] Starting Lemur container..."
57

6-
cd /opt/lemur
8+
cd /opt/lemur/lemur
79

810
if [[ "$LEMUR_INIT" == "1" ]]; then
911
echo "[supervisor] Running Lemur Bootstrap"
10-
.venv/bin/lemur db init
11-
.venv/bin/lemur db migrate
12-
.venv/bin/lemur init -p "$LEMUR_PASSWORD"
12+
lemur init -p "$LEMUR_PASSWORD"
13+
else
14+
echo "[supervisor] Running database migrations..."
15+
lemur db upgrade || {
16+
echo "[db] Migration failed; refusing to start app."
17+
exit 1
18+
}
1319
fi
1420

15-
echo "[supervisor] Running database migrations..."
16-
.venv/bin/lemur db upgrade || {
17-
echo "[db] Migration failed; refusing to start app."
18-
exit 1
19-
}
20-
2121
echo "[supervisor] Starting Lemur server..."
22-
.venv/bin/lemur start -w 4 -b 0.0.0.0:8000 &
22+
lemur start -w 2 -b 0.0.0.0:8000 &
2323
LEMUR_PID=$!
2424

2525
trap 'echo "[supervisor] Caught stop signal"; kill "$LEMUR_PID" "$CADDY_PID" 2>/dev/null || true' SIGTERM SIGINT

0 commit comments

Comments
 (0)