diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2019-07-07 20:44:04 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2019-07-07 23:59:29 +0100 |
commit | 5ed427a4a073a1fce8f36e666daa514c16c0b544 (patch) | |
tree | 4ff87c5d120774dbd88caebaf35b0acd2e68d5d2 | |
parent | 8c12c6939aab9106db14ec2d11d983bc5b29fb2c (diff) |
Statically link cashierd with C libs
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | Makefile | 16 |
2 files changed, 12 insertions, 6 deletions
@@ -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" @@ -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 |