Make Docker image easier to use (#50)

* Use single server example as default frontend

This just works out of the box

* Refactor Dockerfile

- Remove the asset dir since it's embedded in the executable anyway
- Use the code in the current directory to build instead of downloading.
  Makes local testing very easy.
- Cache Go dependencies
- Run without root privileges. Note that using a BoltDB database
  requires mounting a volume with the correct permissions. The default
  database has thus been changed to memory so that starting the image
  just works.

* Automatically publish images
This commit is contained in:
minus
2022-07-26 15:30:23 +00:00
committed by GitHub
parent 580fc08e0e
commit 8e31fe25ac
5 changed files with 76 additions and 512 deletions

View File

@ -1,20 +1,18 @@
FROM golang:alpine AS build_base
#ENV GOARCH arm64
#ENV GOARCH amd64
RUN apk add --no-cache git gcc ca-certificates libc-dev \
&& mkdir -p /go/src/github.com/librespeed/ \
&& cd /go/src/github.com/librespeed/ \
&& git clone https://github.com/librespeed/speedtest-go.git
WORKDIR /go/src/github.com/librespeed/speedtest-go
RUN go get ./ && go build -ldflags "-w -s" -trimpath -o speedtest main.go
FROM golang:1.18-alpine AS build_base
RUN apk add --no-cache git gcc ca-certificates libc-dev
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY ./ ./
RUN go build -ldflags "-w -s" -trimpath -o speedtest .
FROM alpine:3.15
RUN apk add ca-certificates
FROM alpine:3.16
RUN apk add --no-cache ca-certificates
WORKDIR /app
COPY --from=build_base /go/src/github.com/librespeed/speedtest-go/speedtest .
COPY --from=build_base /go/src/github.com/librespeed/speedtest-go/web/assets ./assets
COPY --from=build_base /go/src/github.com/librespeed/speedtest-go/settings.toml .
COPY --from=build_base /build/speedtest ./
COPY settings.toml ./
USER nobody
EXPOSE 8989
CMD ["./speedtest"]