diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..ad8c446 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,50 @@ +# Two-staged build +# 1. Use a container with rust to build the executable +# 2. Copy the executable from that container to actual one. +# +# alpine is used, since it's small. +# alpine/edge is used, since it's flatpak and rust are modern. + +FROM alpine:edge AS builder +WORKDIR /root +RUN apk add cargo rust +RUN apk add postgresql-dev +RUN cargo --quiet install --git https://github.com/flatpak/flat-manager.git --tag 0.3.4 --root=/root +RUN cd /root/.cargo/git/checkouts/flat-manager*/* && \ + install -m 644 -D -t /root/etc example-config.json + +################################################################################# + +FROM alpine:edge + +# Run time dependencies +RUN apk add libpq # postgres runtime dependency +RUN apk add flatpak + +# Copy the executable(s) from builder +COPY --from=builder /root/bin/ /usr/bin +COPY --from=builder /root/etc /etc/flat-manager + + +# A setup script +ADD entrypoint.sh /usr/bin +RUN chown root:root /usr/bin/entrypoint.sh && chmod 755 /usr/bin/entrypoint.sh + +# Create needed directories +RUN mkdir -p /var/run/postgresql + +ENV HOME /var/run/flat-manager +ENV REPO_CONFIG $HOME/config.json +ENV RUST_LOG info + +# Add a user +RUN addgroup flatmanager &&\ + adduser -D -G flatmanager -h $HOME -s /sbin/nologin flatmanager + +USER flatmanager +# from default config; may change, if config changes +EXPOSE 8080 + +ENTRYPOINT ["/usr/bin/entrypoint.sh"] +CMD ["flat-manager"] + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..dcd666e --- /dev/null +++ b/docker/README.md @@ -0,0 +1,38 @@ +# Forewords + +In this simple setup, both flat-manager and postgres are alpine based to keep things small. +A socket is shared between the containers for simplicity. This, however, won't work across machines. + +# Set up storage + POSTGRES_RUNDIR=/path/to/some/storage/postgres-run + POSTGRES_DB=/path/to/some/storage/postgres-db + FLATMAN_REPO=/path/to/some/storage/flatman-repo + + mkdir -p $POSTGRES_RUNDIR + mkdir -p $POSTGRES_DB + mkdir -p $FLATMAN_REPO + +# Run postgres in one terminal + docker run --rm \ + -v $POSTGRES_RUNDIR:/var/run/postgresql \ + -e POSTGRES_PASSWORD=mysecretpasspassword \ + -e POSTGRES_USER=flatmanager \ + -e POSTGRES_DB=repo \ + --name flat-manager-postgres postgres:alpine + +# Flat-manager +## Build docker image + docker build --tag yourname/flat-manager:latest . +## Run image + docker run --rm \ + -v $FLATMAN_REPO:/var/run/flat-manager \ + -v $POSTGRES_RUNDIR:/var/run/postgresql \ + -p 8080:8080 yourname/flat-manager:latest + +At this point, you'll need to stop the container again and edit `$FLATMAN_REPO/config.js`. This is the unmodified default config. It would seem you need to tell `flat-manager` to listen on all interfaces to make forwarding work, namely: + +```json +"host": "0.0.0.0", +``` + +When running `yourname/flat-manager:latest` again, you should be able to access http://localhost:8080/status from your browser. diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..4770966 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ ! -f $REPO_CONFIG ]; then + echo No config found, copying example config. + cp /etc/flat-manager/example-config.json "$REPO_CONFIG" +fi + +exec $*