+ARG BUILD_DIR=/build
+
+# Build Container
FROM --platform=$BUILDPLATFORM python:3.11-slim-bullseye AS build
-RUN apt update && apt install -y npm
+ARG BUILD_DIR
-ARG BUILD_DIR=/build
RUN mkdir ${BUILD_DIR}
WORKDIR ${BUILD_DIR}
+RUN apt update && apt install -y npm
+
COPY package.json package-lock.json ./
RUN npm ci
COPY flatnotes/src ./flatnotes/src
RUN npm run build
-
+# Runtime Container
FROM python:3.11-slim-bullseye
-ARG USER=flatnotes
-ARG UID=1000
-ARG GID=1000
+ARG BUILD_DIR
-ARG APP_DIR=/app
-ARG DATA_DIR=${APP_DIR}/data
+ENV PUID=1000
+ENV PGID=1000
-ENV FLATNOTES_PATH=${DATA_DIR}
-ENV PORT=80
+ENV APP_PATH=/app
+ENV FLATNOTES_PATH=/data
-RUN addgroup \
- --gid $GID \
- ${USER} \
- || echo "Group '${GID}' already exists."
+RUN mkdir -p ${APP_PATH}
+RUN mkdir -p ${FLATNOTES_PATH}
-RUN adduser \
- --disabled-password \
- --gecos "" \
- --ingroup ${USER} \
- --uid ${UID} \
- ${USER} \
- || echo "User '${UID}' already exists."
+RUN apt update && apt install -y gosu \
+ && rm -rf /var/lib/apt/lists/*
RUN pip install pipenv
-RUN mkdir -p ${DATA_DIR}
-RUN chown -R ${UID}:${GID} ${APP_DIR}
-WORKDIR ${APP_DIR}
-
-USER ${UID}
+WORKDIR ${APP_PATH}
-COPY --chown=${UID}:${GID} LICENSE Pipfile Pipfile.lock ./
-RUN pipenv install --deploy --ignore-pipfile
+COPY LICENSE Pipfile Pipfile.lock ./
+RUN pipenv install --deploy --ignore-pipfile --system
COPY flatnotes ./flatnotes
-COPY --from=build --chown=${UID}:${GID} /build/flatnotes/dist ./flatnotes/dist
+COPY --from=build ${BUILD_DIR}/flatnotes/dist ./flatnotes/dist
-ENTRYPOINT [ "pipenv", "run", "python", "-m", "uvicorn", "main:app", "--app-dir", "flatnotes", "--host", "0.0.0.0", "--port", "${PORT}" ]
+COPY entrypoint.sh /
+ENTRYPOINT [ "/entrypoint.sh" ]
The easiest way to install flatnotes is using Docker.
-Note: To use either of the options below, please ensure the current directory contains a folder called "data" and that it's writable by user 1000.
-
### Example Docker Run Command
```shell
docker run -d \
+ -e "PUID=1000" \
+ -e "GUID=1000" \
-e "FLATNOTES_AUTH_TYPE=password" \
-e "FLATNOTES_USERNAME=user" \
-e "FLATNOTES_PASSWORD=changeMe" \
-e "FLATNOTES_SECRET_KEY=aLongRandomSeriesOfCharacters" \
- -v "$(pwd)/data:/app/data" \
- -p "80:80" \
+ -v "$(pwd)/data:/data" \
+ -p "8080:8080" \
dullage/flatnotes:latest
```
container_name: flatnotes
image: dullage/flatnotes:latest
environment:
+ PUID: 1000
+ GUID: 1000
FLATNOTES_AUTH_TYPE: "password"
FLATNOTES_USERNAME: "user"
FLATNOTES_PASSWORD: "changeMe!"
FLATNOTES_SECRET_KEY: "aLongRandomSeriesOfCharacters"
volumes:
- - "./data:/app/data"
- # - "./index:/app/data/.flatnotes"
- # Optional. Allows you to save the search index in a different location.
+ - "./data:/data"
+ # Optional. Allows you to save the search index in a different location:
+ # - "./index:/data/.flatnotes"
ports:
- - "80:80"
+ - "8080:8080"
restart: unless-stopped
```
--- /dev/null
+#!/bin/bash
+
+set -e
+
+USERNAME=flatnotes
+
+echo Setting up user and group...
+addgroup \
+ --gid ${PGID} \
+ ${USERNAME} \
+ || echo "Group '${PGID}' already exists."
+
+adduser \
+ --disabled-password \
+ --gecos "" \
+ --uid ${PUID} \
+ --gid ${PGID} \
+ ${USERNAME} \
+ || echo "User '${PUID}' already exists."
+
+echo Setting file permissions...
+chown -R ${PUID}:${PGID} ${FLATNOTES_PATH}
+
+echo Starting flatnotes...
+cd ${APP_PATH}
+exec gosu ${PUID}:${GUID} \
+ python -m \
+ uvicorn \
+ main:app \
+ --app-dir flatnotes \
+ --host 0.0.0.0 \
+ --port 8080