From ed5e78472e024f7a79d3e8b697952a1b7dfd1941 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 29 Mar 2021 16:54:35 -0700 Subject: [PATCH] Copy all licenses into the container image --- .gitignore | 1 + Dockerfile.in | 8 ++++++-- Makefile | 13 +++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1cc7010..1e41697 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.container-* /.dockerfile-* /.qemu-initialized +/.licenses diff --git a/Dockerfile.in b/Dockerfile.in index ea107d1..95b28f6 100644 --- a/Dockerfile.in +++ b/Dockerfile.in @@ -85,6 +85,10 @@ USER 65533:65533 ENV HOME=/tmp WORKDIR /tmp -# Just dump the binary in the root. -ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN} +# Add the platform-specific binary. +COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN} + +# Add third-party licenses. +COPY .licenses/ /LICENSES/ + ENTRYPOINT ["/{ARG_BIN}"] diff --git a/Makefile b/Makefile index 68c6710..4e995b8 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,7 @@ build: bin/$(OS)_$(ARCH)/$(BIN) BUILD_DIRS := \ bin/$(OS)_$(ARCH) \ + bin/tools \ .go/bin/$(OS)_$(ARCH) \ .go/cache @@ -119,8 +120,16 @@ $(OUTBIN): .go/$(OUTBIN).stamp # Used to track state in hidden files. DOTFILE_IMAGE = $(subst /,_,$(IMAGE))-$(TAG) +LICENSES = .licenses + +$(LICENSES): bin/$(OS)_$(ARCH)/$(BIN) + @go build -o ./bin/tools github.com/google/go-licenses + @rm -rf $(LICENSES) + @./bin/tools/go-licenses save ./... --save_path=$(LICENSES) + @chmod -R a+rx $(LICENSES) + container: .container-$(DOTFILE_IMAGE) container-name -.container-$(DOTFILE_IMAGE): bin/$(OS)_$(ARCH)/$(BIN) Dockerfile.in +.container-$(DOTFILE_IMAGE): bin/$(OS)_$(ARCH)/$(BIN) $(LICENSES) Dockerfile.in @sed \ -e 's|{ARG_BIN}|$(BIN)|g' \ -e 's|{ARG_ARCH}|$(ARCH)|g' \ @@ -203,7 +212,7 @@ $(BUILD_DIRS): clean: container-clean bin-clean container-clean: - rm -rf .container-* .dockerfile-* .push-* .qemu-initialized + rm -rf .container-* .dockerfile-* .push-* .qemu-initialized $(LICENSES) bin-clean: rm -rf .go bin