From dae058b53d1ca9a5039d37b93949d0287b8bfdff Mon Sep 17 00:00:00 2001 From: jdtron Date: Fri, 17 Mar 2023 10:02:22 +0100 Subject: [PATCH] Add Docker resources --- .dockerignore | 6 ++++++ Dockerfile | 22 ++++++++++++++++++++++ Makefile | 8 ++++++++ docker-entrypoint.sh | 30 ++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e33a9e8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +docs/ +Dockerfile +Makefile +README.md +readme.png +todo.org diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..be4978e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:alpine + +RUN apk add --no-cache \ + bash sqlite + +WORKDIR /app +COPY . . +RUN adduser -D bbj +RUN chown -R bbj:bbj . + +USER bbj +RUN /bin/bash /app/setup.sh + +EXPOSE 7099 +ENV PORT=7099 +ENV HOST=127.0.0.1 +ENV INSTANCE_NAME=BBJ +ENV ALLOW_ANON=true +ENV DEBUG=false +ENV ADMINS= + +ENTRYPOINT ["/bin/sh", "/app/docker-entrypoint.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bef6502 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +IMAGE_NAME = tildegit.org/jdtron/bbj +IMAGE_TAG = latest + +image: + docker build -t ${IMAGE_NAME}:${IMAGE_TAG} . + +push: + docker push ${IMAGE_NAME}:${IMAGE_TAG} diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..f6ebb89 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Helper to build a JSON list +function json_list { + [ -z $1 ] && printf '[]' && return + + local list="\"$1\"" + shift + + for i in $@; do + list="$list, \"$i\"" + done + + printf "[$list]" +} + +# Build config from env +cat < /app/config.json +{ + "port": $PORT, + "host": "$HOST", + "instance_name": "$INSTANCE_NAME", + "allow_anon": $ALLOW_ANON, + "debug": $DEBUG, + "admins": $(json_list $ADMINS) +} +EOL + +[ ! -f data.sqlite ] && /bin/bash /app/setup.sh --dbset +python /app/server.py