Commit 6ee06271ae47c29211fb15864a536990be527367

Parents: 41e1c00826587399c39f2eed6d7aa8663b4120f6

From: Moritz Poldrack <git@moritz.sh>
Date: Thu Nov 9 12:43:29 2023 +0700

docker: shrink image

		

Stats

Dockerfile +3/-2
Makefile +2/-1

Changeset

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
diff --git a/Dockerfile b/Dockerfile
index cdc1f3fe93fa511efbb5cfcbc4d77006fd2251db..792eac3f073e6c0e54a8bdeb60340a04f5ede7cd 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,10 @@
 FROM golang:alpine AS build
+RUN apk add --no-cache make
 COPY . /src
 WORKDIR /src
-RUN go build -o /bin/gogit
+RUN CGO_ENABLED=0 make GO_LDFLAGS="-s -w"
 
 FROM scratch
 COPY ./themes/ /themes
-COPY --from=build /bin/gogit /gogit
+COPY --from=build /src/gogit /gogit
 CMD ["/gogit"]
diff --git a/Makefile b/Makefile
index 5a10f0b6f76fcf29aa0f38681b6686c4c95e9a21..d44c3e0bb481f1543e6c732face81161bf9330ea 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,10 @@
 GO ?= $(shell which go)
 GOSRC := $(shell find . -type f -name '*.go' -print)
 GO_FLAGS ?= -buildmode=pie -v -trimpath
+GO_LDFLAGS ?=
 
 gogit: $(GOSRC)
-	$(GO) build $(GO_FLAGS) -o gogit
+	$(GO) build $(GO_FLAGS) -ldflags="$(GO_LDFLAGS)" -o gogit
 
 .PHONY: dev
 dev: