Skip to content

Commit 6e47e07

Browse files
authored
Merge pull request #171 from Code-Otto/trimmed-docker
Reduce size of Docker image and add an experimental Dockerfile
2 parents 478ce2d + 43b2ee0 commit 6e47e07

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ARG BUILD_DIR
2323

2424
ENV PUID=1000
2525
ENV PGID=1000
26+
ENV EXEC_TOOL=gosu
2627

2728
ENV APP_PATH=/app
2829
ENV FLATNOTES_PATH=/data
@@ -35,12 +36,13 @@ RUN apt update && apt install -y \
3536
gosu \
3637
&& rm -rf /var/lib/apt/lists/*
3738

38-
RUN pip install pipenv
39+
RUN pip install --no-cache-dir pipenv
3940

4041
WORKDIR ${APP_PATH}
4142

4243
COPY LICENSE Pipfile Pipfile.lock ./
43-
RUN pipenv install --deploy --ignore-pipfile --system
44+
RUN pipenv install --deploy --ignore-pipfile --system && \
45+
pipenv --clear
4446

4547
COPY server ./server
4648
COPY --from=build ${BUILD_DIR}/client/dist ./client/dist

Dockerfile.experimental

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
ARG BUILD_DIR=/build
2+
3+
# Client Build Container
4+
FROM --platform=$BUILDPLATFORM python:3.11-slim-bullseye AS build
5+
6+
ARG BUILD_DIR
7+
8+
RUN mkdir ${BUILD_DIR}
9+
WORKDIR ${BUILD_DIR}
10+
11+
RUN apt update && apt install -y npm
12+
13+
COPY package.json package-lock.json .htmlnanorc ./
14+
RUN npm ci
15+
16+
COPY client ./client
17+
RUN npm run build
18+
19+
# Pipenv Build Container
20+
FROM python:3.11-alpine3.19 as pipenv-build
21+
22+
ARG BUILD_DIR
23+
24+
ENV APP_PATH=/app
25+
26+
RUN apk add --no-cache build-base rust cargo libffi libffi-dev libssl3 openssl-dev
27+
28+
RUN pip install --no-cache-dir pipenv
29+
30+
WORKDIR ${APP_PATH}
31+
32+
COPY LICENSE Pipfile Pipfile.lock ./
33+
RUN mkdir .venv
34+
RUN pipenv install --deploy --ignore-pipfile && \
35+
pipenv --clear
36+
37+
# Runtime Container
38+
FROM python:3.11-alpine3.19
39+
40+
ARG BUILD_DIR
41+
42+
ENV PUID=1000
43+
ENV PGID=1000
44+
ENV EXEC_TOOL=su-exec
45+
46+
ENV APP_PATH=/app
47+
ENV FLATNOTES_PATH=/data
48+
49+
RUN mkdir -p ${APP_PATH}
50+
RUN mkdir -p ${FLATNOTES_PATH}
51+
52+
RUN apk add --no-cache su-exec libssl3 libgcc curl
53+
54+
WORKDIR ${APP_PATH}
55+
56+
COPY server ./server
57+
COPY --from=build ${BUILD_DIR}/client/dist ./client/dist
58+
COPY --from=pipenv-build ${APP_PATH}/.venv/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
59+
60+
VOLUME /data
61+
EXPOSE 8080/tcp
62+
HEALTHCHECK --interval=60s --timeout=10s CMD curl -f http://localhost:8080/health || exit 1
63+
64+
COPY entrypoint.sh /
65+
RUN chmod +x /entrypoint.sh
66+
ENTRYPOINT [ "/entrypoint.sh" ]

entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
set -e
44

@@ -31,7 +31,7 @@ if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then
3131
chown -R ${PUID}:${PGID} ${FLATNOTES_PATH}
3232

3333
echo Starting flatnotes as user ${PUID}...
34-
exec gosu ${PUID}:${PGID} ${flatnotes_command}
34+
exec ${EXEC_TOOL} ${PUID}:${PGID} ${flatnotes_command}
3535

3636
else
3737
echo "A user was set by docker, skipping file permission changes."

0 commit comments

Comments
 (0)