diff --git a/Dockerfile b/Dockerfile index 65661d3..f7f6813 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,13 +6,22 @@ WORKDIR /stackedit RUN npm install RUN npm run build -FROM nginx:1.15-alpine +FROM golang:alpine AS server +RUN apk --update add git build-base upx +WORKDIR /go/src/app +COPY main.go ./ +RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags="-s -w" -installsuffix cgo -o server . && \ + upx -v --best --overlay=strip server && \ + upx -t server + +FROM scratch LABEL maintainer="quentin.mcgaw@gmail.com" \ description="StackEdit server in a lightweight Docker container" \ - download="15.6MB" \ - size="45.5MB" \ + size="29.6MB" \ ram="7MB" \ cpu_usage="Very low" \ github="https://github.com/qdm12/stackedit-docker" -COPY --from=stackedit /stackedit/dist /usr/share/nginx/html/ -ENTRYPOINT nginx -g "daemon off;" +EXPOSE 80 +COPY --from=stackedit /stackedit/dist / +COPY --from=server /go/src/app/server /server +ENTRYPOINT [ "/server" ] diff --git a/main.go b/main.go new file mode 100644 index 0000000..7357f2c --- /dev/null +++ b/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, r.URL.Path[1:]) + }) + log.Fatal(http.ListenAndServe(":80", nil)) +}