aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2019-07-07 20:44:04 +0100
committerNiall Sheridan <nsheridan@gmail.com>2019-07-07 23:59:29 +0100
commit5ed427a4a073a1fce8f36e666daa514c16c0b544 (patch)
tree4ff87c5d120774dbd88caebaf35b0acd2e68d5d2
parent8c12c6939aab9106db14ec2d11d983bc5b29fb2c (diff)
Statically link cashierd with C libs
-rw-r--r--Dockerfile2
-rw-r--r--Makefile16
2 files changed, 12 insertions, 6 deletions
diff --git a/Dockerfile b/Dockerfile
index 33f1b34..b9ab104 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -5,7 +5,7 @@ COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
-RUN CGO_ENABLED=0 GOOS=linux make install-cashierd
+RUN CGO_ENABLED=1 GOOS=linux make install-cashierd
FROM gcr.io/distroless/static
LABEL maintainer="nsheridan@gmail.com"
diff --git a/Makefile b/Makefile
index db969b8..278ed8d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,10 @@
CASHIER_CMD := ./cmd/cashier
CASHIERD_CMD := ./cmd/cashierd
SRC_FILES = $(shell find * -type f -name '*.go' -not -path 'vendor/*' -not -name 'a_*-packr.go')
-VERSION_PKG := "github.com/nsheridan/cashier/lib.Version"
+VERSION_PKG := github.com/nsheridan/cashier/lib.Version
VERSION := $(shell git describe --tags --always --dirty)
+STATIC_LINKER_FLAGS ?= -linkmode external -extldflags -static -w
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CGO_ENABLED ?= $(shell go env CGO_ENABLED)
@@ -22,15 +23,20 @@ lint: dep
@[ -z "`git status --porcelain`" ] || (echo "unexpected files: `git status --porcelain`" && exit 1)
build: cashier cashierd
+install: install-cashierd install-cashier
+cashier: cashier-bin
+cashierd: cashierd-bin
generate:
go generate ./...
-%-cmd:
- CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags="-X $(VERSION_PKG)=$(VERSION)" -o $* ./cmd/$*
-
+%-bin:
+ CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags="-X $(VERSION_PKG)=$(VERSION) $(STATIC_LINKER_FLAGS)" ./cmd/$*
install-%: generate
- CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go install -ldflags="-X $(VERSION_PKG)=$(VERSION)" ./cmd/$*
+ CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) go install -ldflags="-X $(VERSION_PKG)=$(VERSION) $(STATIC_LINKER_FLAGS)" ./cmd/$*
+
+docker-image:
+ docker build -f Dockerfile .
clean:
rm -f cashier cashierd