From aa80df2b26c7455007d3db96f01bfde66c6779df Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Thu, 12 Aug 2021 13:53:33 -0700 Subject: build: deploy to fly Don't deploy to Google App anymore, but use fly.io instead. Add steps to the Makefile to build a docker image, and to deploy the application to fly.io. --- tools/govanity/Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tools/govanity/Dockerfile (limited to 'tools/govanity/Dockerfile') diff --git a/tools/govanity/Dockerfile b/tools/govanity/Dockerfile new file mode 100644 index 0000000..caca19a --- /dev/null +++ b/tools/govanity/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.16-alpine + +WORKDIR /src + +ADD go.mod /src +ADD go.sum /src +RUN go mod download + +ADD . /src + +RUN go build -o app . + +ENTRYPOINT ["/src/app"] -- cgit v1.2.3 From 714b3309ec5c8d7d4881ba2965be84b3a49b76b8 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sat, 14 Aug 2021 14:52:36 -0700 Subject: build: trim the size of the Docker container Prior to this change, the size of the image was about 300MB: ``` ; docker images|grep fcuny/golang|grep days fcuny/golang.fcuny.net d07add42f21a69e2c057eae8492bbd599dc50082 9fd284c5d8ee 2 days ago 313MB fcuny/golang.fcuny.net ca3dd083f8d6642821781ce03829713524322bbe 8104afadfd1f 2 days ago 313MB ``` With this change, we're reducing the image to less than 10MB: ``` fcuny/golang.fcuny.net 19b3dccc1ff31534df3636d4d7d6a28c0ae1e189 c9ae35574f8e 24 seconds ago 9.09MB ``` Since there's storage and bandwidth involved in this process, there's no point in not going for a smaller image. --- tools/govanity/Dockerfile | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'tools/govanity/Dockerfile') diff --git a/tools/govanity/Dockerfile b/tools/govanity/Dockerfile index caca19a..db471c8 100644 --- a/tools/govanity/Dockerfile +++ b/tools/govanity/Dockerfile @@ -1,13 +1,30 @@ -FROM golang:1.16-alpine +FROM golang:1.16 AS builder WORKDIR /src +ENV USER=app +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/src" \ + --shell "/sbin/nologin" \ + --uid "10001" \ + "${USER}" + ADD go.mod /src ADD go.sum /src RUN go mod download ADD . /src -RUN go build -o app . +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -a -installsuffix cgo -ldflags '-extldflags "-static"' -o app . + +FROM scratch +COPY --from=builder /src/app /govanity +COPY --from=builder /src/vanity.yaml /vanity.yaml +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/group /etc/group + +USER app:app -ENTRYPOINT ["/src/app"] +ENTRYPOINT ["/govanity"] -- cgit v1.2.3 From 80c9c7e4ac76e4c0f7b245da79508f87ac9171cb Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sat, 14 Aug 2021 15:29:38 -0700 Subject: build: create user before setting workdir --- tools/govanity/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/govanity/Dockerfile') diff --git a/tools/govanity/Dockerfile b/tools/govanity/Dockerfile index db471c8..eb6b8db 100644 --- a/tools/govanity/Dockerfile +++ b/tools/govanity/Dockerfile @@ -1,7 +1,5 @@ FROM golang:1.16 AS builder -WORKDIR /src - ENV USER=app RUN adduser \ --disabled-password \ @@ -11,6 +9,8 @@ RUN adduser \ --uid "10001" \ "${USER}" +WORKDIR /src + ADD go.mod /src ADD go.sum /src RUN go mod download -- cgit v1.2.3 From 722389e918af9c44fba6ec658f576b5838661179 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Wed, 11 May 2022 18:18:39 -0700 Subject: Dockerfile: update steps --- tools/govanity/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/govanity/Dockerfile') diff --git a/tools/govanity/Dockerfile b/tools/govanity/Dockerfile index eb6b8db..20df29f 100644 --- a/tools/govanity/Dockerfile +++ b/tools/govanity/Dockerfile @@ -20,11 +20,11 @@ ADD . /src RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -a -installsuffix cgo -ldflags '-extldflags "-static"' -o app . FROM scratch -COPY --from=builder /src/app /govanity +COPY --from=builder /src/app /vanity COPY --from=builder /src/vanity.yaml /vanity.yaml COPY --from=builder /etc/passwd /etc/passwd COPY --from=builder /etc/group /etc/group USER app:app -ENTRYPOINT ["/govanity"] +ENTRYPOINT ["/vanity"] -- cgit v1.2.3