diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ca4fe73 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +vendor/pkg +vendor/src +pkg +hooks +bin +.git 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] diff --git a/Dockerfile b/Dockerfile index e45e881..9761d79 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,32 @@ -FROM alpine:3.6 +# Build go-neb +FROM golang:1.10-alpine as builder -ENV BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=/data/go-neb.db?_busy_timeout=5000 +COPY . /tmp/go-neb +WORKDIR /tmp/go-neb +RUN apk add --no-cache -t build-deps git gcc musl-dev go \ + && go get -u github.com/constabulary/gb/... \ + && gb vendor restore \ + && gb build -f github.com/matrix-org/go-neb -COPY bin/go-neb /go-neb + +# Run go-neb +FROM alpine:3.7 + +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 /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/README.md b/README.md index 4f48f7d..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 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. +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: ``` 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 . 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..e5a9b58 --- /dev/null +++ b/docker/root/etc/s6.d/go-neb/finish @@ -0,0 +1,2 @@ +#!/bin/sh +s6-svscanctl -t /etc/s6.d 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