From d59cc42e2222d02c70ad8e3486ef662c6b45caeb Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 26 May 2020 21:07:09 +0200 Subject: [PATCH] Add target to create smaller binary --- Dockerfile | 3 ++- Makefile | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9c2e550..c6602bb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM golang as builder +RUN apt-get update && apt-get install upx ADD . /luet -RUN cd /luet && make build +RUN cd /luet && make build-small FROM scratch ENV LUET_NOLOCK=true diff --git a/Makefile b/Makefile index aef1487b..fac5c31f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # go tool nm ./luet | grep Commit -LDFLAGS += -X "github.com/mudler/luet/cmd.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')" -LDFLAGS += -X "github.com/mudler/luet/cmd.BuildCommit=$(shell git rev-parse HEAD)" +override LDFLAGS += -X "github.com/mudler/luet/cmd.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')" +override LDFLAGS += -X "github.com/mudler/luet/cmd.BuildCommit=$(shell git rev-parse HEAD)" NAME ?= luet PACKAGE_NAME ?= $(NAME) @@ -9,7 +9,6 @@ PACKAGE_CONFLICT ?= $(PACKAGE_NAME)-beta REVISION := $(shell git rev-parse --short HEAD || echo dev) VERSION := $(shell git describe --tags || echo $(REVISION)) VERSION := $(shell echo $(VERSION) | sed -e 's/^v//g') -ITTERATION := $(shell date +%s) BUILD_PLATFORMS ?= -osarch="linux/amd64" -osarch="linux/386" -osarch="linux/arm" ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) @@ -66,6 +65,11 @@ deps: build: CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' +.PHONY: build-small +build-small: + @$(MAKE) LDFLAGS+="-s -w" build + upx --brute $(NAME) + .PHONY: image image: docker build --rm -t luet/base .