Skip to content

Commit b6016a5

Browse files
author
Olaf Leidinger
committed
Add Dockerfile and a few notes
1 parent 034cea8 commit b6016a5

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

docker/Dockerfile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Two-staged build
2+
# 1. Use a container with rust to build the executable
3+
# 2. Copy the executable from that container to actual one.
4+
#
5+
# alpine is used, since it's small.
6+
# alpine/edge is used, since it's flatpak and rust are modern.
7+
8+
FROM alpine:edge AS builder
9+
WORKDIR /root
10+
RUN apk add cargo rust
11+
RUN apk add postgresql-dev
12+
RUN cargo --quiet install --git https://github.com/flatpak/flat-manager.git --tag 0.3.4 --root=/root
13+
RUN cd /root/.cargo/git/checkouts/flat-manager*/* && \
14+
install -m 755 -D -t /root/bin flat-manager-client && \
15+
install -m 644 -D -t /root/etc example-config.json
16+
17+
#################################################################################
18+
19+
FROM alpine:edge
20+
21+
# Run time dependencies
22+
RUN apk add libpq # postgres runtime dependency
23+
RUN apk add flatpak
24+
25+
# Copy the executable(s) from builder
26+
COPY --from=builder /root/bin/ /usr/bin
27+
COPY --from=builder /root/etc /etc/flat-manager
28+
29+
30+
# A setup script
31+
ADD entrypoint.sh /usr/bin
32+
RUN chown root:root /usr/bin/entrypoint.sh && chmod 755 /usr/bin/entrypoint.sh
33+
34+
# Create needed directories
35+
RUN mkdir -p /var/run/postgresql
36+
37+
ENV HOME /var/run/flat-manager
38+
ENV REPO_CONFIG $HOME/config.json
39+
ENV RUST_LOG info
40+
41+
# Add a user
42+
RUN addgroup flatmanager &&\
43+
adduser -D -G flatmanager -h $HOME -s /sbin/nologin flatmanager
44+
45+
USER flatmanager
46+
# from default config; may change, if config changes
47+
EXPOSE 8080
48+
49+
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
50+
CMD ["flat-manager"]
51+

docker/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Forewords
2+
3+
In this simple setup, both flat-manager and postgres are alpine based to keep things small.
4+
A socket is shared between the containers for simplicity. This, however, won't work across machines.
5+
6+
# Set up storage
7+
POSTGRES_RUNDIR=/path/to/some/storage/postgres-run
8+
POSTGRES_DB=/path/to/some/storage/postgres-db
9+
FLATMAN_REPO=/path/to/some/storage/flatman-repo
10+
11+
mkdir -p $POSTGRES_RUNDIR
12+
mkdir -p $POSTGRES_DB
13+
mkdir -p $FLATMAN_REPO
14+
15+
# Run postgres in one terminal
16+
docker run --rm \
17+
-v $POSTGRES_RUNDIR:/var/run/postgresql \
18+
-e POSTGRES_PASSWORD=mysecretpasspassword \
19+
-e POSTGRES_USER=flatmanager \
20+
-e POSTGRES_DB=repo \
21+
--name flat-manager-postgres postgres:alpine
22+
23+
# Flat-manager
24+
## Build docker image
25+
docker build --tag yourname/flat-manager:latest .
26+
## Run image
27+
docker run --rm \
28+
-v $FLATMAN_REPO:/var/run/flat-manager \
29+
-v $POSTGRES_RUNDIR:/var/run/postgresql \
30+
-p 8080:8080 yourname/flat-manager:latest
31+
32+
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:
33+
34+
```json
35+
"host": "0.0.0.0",
36+
```
37+
38+
When running `yourname/flat-manager:latest` again, you should be able to access http://localhost:8080/status from your browser.

docker/entrypoint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
if [ ! -f $REPO_CONFIG ]; then
4+
echo No config found, copying example config.
5+
cp /etc/flat-manager/example-config.json "$REPO_CONFIG"
6+
fi
7+
8+
exec $*

0 commit comments

Comments
 (0)