From 956a5dc3556209fb712b25031d8d972912199f53 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Sun, 16 May 2021 12:18:21 +0100 Subject: [PATCH] Add Dockerfile and update README --- README.md | 32 ++++++++++++++++++++++++++++++-- docker/ubsserver/Dockerfile | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 docker/ubsserver/Dockerfile diff --git a/README.md b/README.md index 446bb08..0a361b7 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,41 @@ worth my time. ### Building -`go install -ldflags="-s -w" -trimpath ./cmd/ubsserver` +You can get prebuilt binaries for a number of platforms from the gitlab repository in the "Download artifacts" section. +To build from source, just run: + +`go install ./cmd/ubsserver` + +It is also possible to build a very basic Docker container image by running: + +`docker build -t ubsserver -f docker/ubsserver/Dockerfile .` ### Running +To run the binary you just built: + `~/go/bin/ubsserver` -TODO: Suggest deployment setups +It will start the API server listening on port 8090 and using the `data` directory under $PWD as the datastore. +You can change the listening address using the `-listen` flag (e.g.: `-listen :9999` will listen on port 9999 on all +addresses). + +Similarly, you can change the datastore using the `-store` flag. The store is defined in the format +`driver_name:driver_args` where `driver_name` is the name of the store driver while `driver_args` contains +driver-specific settings. + +Currently, only two drivers are implemented: + + - **mem**: a volatile RAM-backed datastore only useful for testing and debugging. It does not take any arguments. + - **fs**: the default driver: it stores sync data in json files in the directory specified as the argument (default is + `data`) + +If you built the container image, you can run the containerised version: + +`docker run -it --rm -v /tmp/data:/data -p 8888:8090 localhost/ubsserver` + +You can replace `/tmp/data` with the name of the directory where you want to store sync data and `8888` with the port +where you want to expose the API service. ## Roadmap diff --git a/docker/ubsserver/Dockerfile b/docker/ubsserver/Dockerfile new file mode 100644 index 0000000..c699ed8 --- /dev/null +++ b/docker/ubsserver/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:alpine as builder +WORKDIR /go/src/uBrowserSync +COPY . . +ARG GOOS=linux +ARG GOARCH=amd64 +ARG GOARM=6 +RUN CGO_ENABLED=0 go install -ldflags="-w -s" -trimpath ./cmd/ubsserver + +FROM scratch +WORKDIR / +VOLUME ["/data"] +COPY --from=builder /go/bin/ubsserver /usr/bin/ +EXPOSE 8090 +ENTRYPOINT ["/usr/bin/ubsserver"]