Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
build: Add support to strip the agent golang binary
Browse files Browse the repository at this point in the history
This provide a flag "STRIP=yes" to strip the golang binary
After make STRIP=yes
24757576 kata-agent.nostrip*
19651136 kata-agent.striped*
It reduces the golang binary size ~5MB

Fixes: #739
Signed-off-by: Jia He <[email protected]>
  • Loading branch information
justin-he committed Feb 24, 2020
1 parent 36b37f6 commit cfc96dd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ INIT := no
# Set to "yes" if agent should support OpenTracing with http://jaegertracing.io.
TRACE := no

# Set to "yes“ if binary stripping is needed.
STRIP := no

# Tracing cannot currently be supported when running the agent as PID 1 since
# the tracing requires additional services to be started _before_ the agent
# process starts.
Expand Down Expand Up @@ -85,6 +88,11 @@ else
BUILDFLAGS := -buildmode=pie
endif

# whether stipping the binary
ifeq ($(STRIP),yes)
KATA_LDFLAGS += -w -s
endif

# args for building agent image
BUILDARGS := $(if $(http_proxy), --build-arg http_proxy=$(http_proxy))
BUILDARGS += $(if $(https_proxy), --build-arg https_proxy=$(https_proxy))
Expand All @@ -94,7 +102,7 @@ AGENT_TAG := $(if $(COMMIT_NO_SHORT),$(COMMIT_NO_SHORT),dev)

$(TARGET): $(GENERATED_FILES) $(SOURCES) $(VERSION_FILE)
go build $(BUILDFLAGS) -tags "$(BUILDTAGS)" -o $@ \
-ldflags "-X main.version=$(VERSION_COMMIT) -X main.seccompSupport=$(SECCOMP) $(LDFLAGS)"
-ldflags "-X main.version=$(VERSION_COMMIT) -X main.seccompSupport=$(SECCOMP) $(LDFLAGS) $(KATA_LDFLAGS)"

install: $(TARGET)
install -D $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
Expand Down

0 comments on commit cfc96dd

Please sign in to comment.