Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add Dockerfile and a few notes #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

38 changes: 38 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 $*