From 1f6f77b675b15fd6004ea220876631230f0d2b3f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 15:40:52 -0600 Subject: [PATCH 01/10] Update .gitignore Signed-off-by: Travis Ralston --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9272758..c885821 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ bin pkg _obj _test +.idea +vendor/pkg +vendor/src # Architecture specific extensions/prefixes *.[568vq] From d135be92f6093c04425fbcacdb65016f4d6040f5 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 15:47:12 -0600 Subject: [PATCH 02/10] Update the Docker image for easier use of automated builds Signed-off-by: Travis Ralston --- .dockerignore | 10 ++++++++++ Dockerfile | 13 ++++++++++++- README.md | 2 +- build-docker-image.sh | 12 ------------ 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 .dockerignore delete mode 100755 build-docker-image.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5df1656 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +vendor/pkg +vendor/src +pkg +hooks +bin + +# Other stuff we just don't need +.gitignore +.git +.travis.yml diff --git a/Dockerfile b/Dockerfile index e45e881..7731c2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,18 @@ FROM alpine:3.6 ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 -COPY bin/go-neb /go-neb +COPY . /tmp/go-neb +WORKDIR /tmp/go-neb +ENV GOPATH=/tmp/go-neb/vendor/src:/tmp/go-neb/vendor:/tmp/go-neb +RUN apk add --no-cache -t build-deps git gcc musl-dev go \ + && go get -u github.com/constabulary/gb/... \ + && export PATH="/tmp/go-neb/vendor/src/bin:${PATH}" \ + && gb vendor restore \ + && gb build -f github.com/matrix-org/go-neb \ + && mv bin/go-neb /go-neb \ + && cd / \ + && rm -rf /tmp/* \ + && apk del build-deps VOLUME /data EXPOSE 4050 diff --git a/README.md b/README.md index 4f48f7d..ae81e08 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ sensible-browser http://localhost:6060/pkg/github.com/matrix-org/go-neb ## Docker image -There is a `Dockerfile` in the root of the repository and a `build-docker-image.sh` script that uses an alpine-based golang container to build `go-neb` (note that this will overwrite host-built binaries in `pkg/` and `bin/`) and then builds the docker image using that binary. +There is a `Dockerfile` in the root of the repository which copies the local source files and builds go-neb. The image sets the following environment variables: ``` diff --git a/build-docker-image.sh b/build-docker-image.sh deleted file mode 100755 index d5a3495..0000000 --- a/build-docker-image.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -docker run \ - --rm \ - -v "$PWD":/usr/src/myapp \ - -w /usr/src/myapp \ - golang:1.8-alpine \ - sh -c 'apk add --no-cache git gcc musl-dev && go get -u github.com/constabulary/gb/... && gb build -f github.com/matrix-org/go-neb' - -docker build -t ${IMAGE_PREFIX}go-neb:latest . From 65717f66ca3e115cede73cf183f8ae7869c2fc8c Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 15:49:38 -0600 Subject: [PATCH 03/10] Update documentation to mention where to get the Docker image This is assuming that it actually ends up on docker.io Signed-off-by: Travis Ralston --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae81e08..039dbd7 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,12 @@ sensible-browser http://localhost:6060/pkg/github.com/matrix-org/go-neb ## Docker image -There is a `Dockerfile` in the root of the repository which copies the local source files and builds go-neb. +To get started quickly, use the image from docker.io: +``` +docker run -v /path/to/data:/data -e "BASE_URL=http://your.public.url:4050" matrixdotorg/go-neb +``` + +If you'd prefer to build the file yourself, clone this repository and build the `Dockerfile`. The image sets the following environment variables: ``` From 1177c2527181cc8eb13ce29587562c25fcc0170f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 16:22:17 -0600 Subject: [PATCH 04/10] Convert Dockerfile to be a mutlistage build Signed-off-by: Travis Ralston --- Dockerfile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7731c2f..c5e6d6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,20 @@ -FROM alpine:3.6 - -ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 +# Build go-neb +FROM golang:1.8-alpine as builder COPY . /tmp/go-neb WORKDIR /tmp/go-neb -ENV GOPATH=/tmp/go-neb/vendor/src:/tmp/go-neb/vendor:/tmp/go-neb RUN apk add --no-cache -t build-deps git gcc musl-dev go \ && go get -u github.com/constabulary/gb/... \ - && export PATH="/tmp/go-neb/vendor/src/bin:${PATH}" \ && gb vendor restore \ - && gb build -f github.com/matrix-org/go-neb \ - && mv bin/go-neb /go-neb \ - && cd / \ - && rm -rf /tmp/* \ - && apk del build-deps + && gb build -f github.com/matrix-org/go-neb + + +# Run go-neb +FROM alpine:3.6 + +ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 + +COPY --from=builder /tmp/go-neb/bin/go-neb /go-neb VOLUME /data EXPOSE 4050 From 8210b38516dc972aa9bc608a340906b51bd2f422 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 16:33:54 -0600 Subject: [PATCH 05/10] Add ca-certificates to the docker image This is to ensure that the bot can connect to homeservers behind ssl. Signed-off-by: Travis Ralston --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c5e6d6d..8d4aace 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ FROM alpine:3.6 ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 COPY --from=builder /tmp/go-neb/bin/go-neb /go-neb +RUN apk add --no-cache ca-certificates VOLUME /data EXPOSE 4050 From f310d4796918758804335fc1c2481cd6e722efea Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 16:55:39 -0600 Subject: [PATCH 06/10] Clean up the .dockerignore Signed-off-by: Travis Ralston --- .dockerignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5df1656..ca4fe73 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,8 +3,4 @@ vendor/src pkg hooks bin - -# Other stuff we just don't need -.gitignore .git -.travis.yml From 930861f69565bfae196bbcc995747a4658d1e0d5 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 6 Jun 2018 16:56:15 -0600 Subject: [PATCH 07/10] Update the golang version used to build go-neb Signed-off-by: Travis Ralston --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8d4aace..1a7044c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build go-neb -FROM golang:1.8-alpine as builder +FROM golang:1.10-alpine as builder COPY . /tmp/go-neb WORKDIR /tmp/go-neb From fedc71a5325c09047d26c872acc9880a92443630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Wed, 13 Jun 2018 10:49:05 +0100 Subject: [PATCH 08/10] move to alpine 3.7 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1a7044c..5b37068 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN apk add --no-cache -t build-deps git gcc musl-dev go \ # Run go-neb -FROM alpine:3.6 +FROM alpine:3.7 ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 From e44cccb91d5977b145bde009678766eb4380f1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Wed, 13 Jun 2018 10:50:43 +0100 Subject: [PATCH 09/10] change default user and use supervisor --- Dockerfile | 17 +++++++++++++---- docker/root/etc/s6.d/.s6-svscan/finish | 1 + docker/root/etc/s6.d/go-neb/finish | 1 + docker/root/etc/s6.d/go-neb/run | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100755 docker/root/etc/s6.d/.s6-svscan/finish create mode 100755 docker/root/etc/s6.d/go-neb/finish create mode 100755 docker/root/etc/s6.d/go-neb/run diff --git a/Dockerfile b/Dockerfile index 5b37068..9761d79 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,12 +12,21 @@ RUN apk add --no-cache -t build-deps git gcc musl-dev go \ # Run go-neb FROM alpine:3.7 -ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 +ENV BIND_ADDRESS=:4050 \ + DATABASE_TYPE=sqlite3 \ + DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 \ + UID=1337 \ + GID=1337 -COPY --from=builder /tmp/go-neb/bin/go-neb /go-neb -RUN apk add --no-cache ca-certificates +COPY --from=builder /tmp/go-neb/bin/go-neb /usr/local/bin/go-neb +RUN apk add --no-cache \ + ca-certificates \ + su-exec \ + s6 VOLUME /data EXPOSE 4050 -ENTRYPOINT ["/go-neb"] +COPY docker/root / + +ENTRYPOINT ["/bin/s6-svscan", "/etc/s6.d/"] diff --git a/docker/root/etc/s6.d/.s6-svscan/finish b/docker/root/etc/s6.d/.s6-svscan/finish new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/docker/root/etc/s6.d/.s6-svscan/finish @@ -0,0 +1 @@ +#!/bin/sh diff --git a/docker/root/etc/s6.d/go-neb/finish b/docker/root/etc/s6.d/go-neb/finish new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/docker/root/etc/s6.d/go-neb/finish @@ -0,0 +1 @@ +#!/bin/sh diff --git a/docker/root/etc/s6.d/go-neb/run b/docker/root/etc/s6.d/go-neb/run new file mode 100755 index 0000000..880687f --- /dev/null +++ b/docker/root/etc/s6.d/go-neb/run @@ -0,0 +1,3 @@ +#!/bin/sh +chown -R ${UID}:${GID} /data +exec su-exec ${UID}:${GID} /usr/local/bin/go-neb From 859eff408489795da92536b853bcb6d85acfd267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Fri, 22 Jun 2018 19:00:33 +0100 Subject: [PATCH 10/10] stop s6 when go-neb exits --- docker/root/etc/s6.d/go-neb/finish | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/root/etc/s6.d/go-neb/finish b/docker/root/etc/s6.d/go-neb/finish index 1a24852..e5a9b58 100755 --- a/docker/root/etc/s6.d/go-neb/finish +++ b/docker/root/etc/s6.d/go-neb/finish @@ -1 +1,2 @@ #!/bin/sh +s6-svscanctl -t /etc/s6.d