From adae27b8d1ba86a02898a9af4a550af0e70e0b20 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 20 Jun 2017 12:06:58 +0100 Subject: [PATCH] Simplify Makefiles for Packages These now inherit from a top-level package.mk Options like use of the network can be enabled on a per package basis This removes a lot of duplicate code and make the maintenace of these Makefiles much easier Signed-off-by: Dave Tucker --- pkg/binfmt/Makefile | 15 ++------------- pkg/ca-certificates/Makefile | 14 +------------- pkg/containerd/Makefile | 15 ++------------- pkg/dhcpcd/Makefile | 15 ++------------- pkg/docker-ce/Makefile | 15 ++------------- pkg/format/Makefile | 15 ++------------- pkg/getty/Makefile | 15 ++------------- pkg/init/Makefile | 15 ++------------- pkg/metadata/Makefile | 15 ++------------- pkg/mkimage/Makefile | 15 ++------------- pkg/mount/Makefile | 15 ++------------- pkg/node_exporter/Makefile | 14 +------------- pkg/open-vm-tools/Makefile | 14 +------------- pkg/openntpd/Makefile | 15 ++------------- pkg/package.mk | 17 +++++++++++++++++ pkg/qemu-ga/Makefile | 13 +------------ pkg/rngd/Makefile | 14 +------------- pkg/runc/Makefile | 15 ++------------- pkg/sshd/Makefile | 15 ++------------- pkg/swap/Makefile | 15 ++------------- pkg/sysctl/Makefile | 15 ++------------- pkg/sysfs/Makefile | 15 ++------------- pkg/vpnkit-forwarder/Makefile | 16 +++------------- pkg/vsudd/Makefile | 16 +++------------- 24 files changed, 60 insertions(+), 298 deletions(-) create mode 100644 pkg/package.mk diff --git a/pkg/binfmt/Makefile b/pkg/binfmt/Makefile index 8b2506aa7..7dc7bb840 100644 --- a/pkg/binfmt/Makefile +++ b/pkg/binfmt/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=binfmt -DEPS=Dockerfile Makefile main.go $(wildcard etc/binmft.d/*) - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=main.go $(wildcard etc/binmft.d/*) diff --git a/pkg/ca-certificates/Makefile b/pkg/ca-certificates/Makefile index 4c1c33359..adf066a16 100644 --- a/pkg/ca-certificates/Makefile +++ b/pkg/ca-certificates/Makefile @@ -1,15 +1,3 @@ -.PHONY: tag push +include ../package.mk -ORG?=linuxkit IMAGE=ca-certificates - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -default: push - -tag: Dockerfile - docker build --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/pkg/containerd/Makefile b/pkg/containerd/Makefile index 8ef90ce89..3363f4072 100644 --- a/pkg/containerd/Makefile +++ b/pkg/containerd/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push +include ../package.mk -ORG?=linuxkit IMAGE=containerd - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -default: push - -tag: Dockerfile - docker build -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +NETWORK=1 diff --git a/pkg/dhcpcd/Makefile b/pkg/dhcpcd/Makefile index 1daa183bf..deb630d1a 100644 --- a/pkg/dhcpcd/Makefile +++ b/pkg/dhcpcd/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=dhcpcd -DEPS=Dockerfile Makefile dhcpcd.conf usr/lib/dhcpcd/dhcpcd-hooks/10-mtu - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=dhcpcd.conf $(wildcard usr/lib/dhcpcd/dhcpcd-hooks/*) diff --git a/pkg/docker-ce/Makefile b/pkg/docker-ce/Makefile index 84499a10f..59b105664 100644 --- a/pkg/docker-ce/Makefile +++ b/pkg/docker-ce/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=docker-ce -DEPS=Dockerfile - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +NETWORK=1 diff --git a/pkg/format/Makefile b/pkg/format/Makefile index 24ede284f..136df48f5 100644 --- a/pkg/format/Makefile +++ b/pkg/format/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=format -DEPS=Dockerfile format.sh - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=format.sh diff --git a/pkg/getty/Makefile b/pkg/getty/Makefile index b8dfa8c5f..b0486239c 100644 --- a/pkg/getty/Makefile +++ b/pkg/getty/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=getty -DEPS=Dockerfile usr/bin/rungetty.sh - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=usr/bin/rungetty.sh $(wildcard etc/*) $(wildcard etc/init.d/*) diff --git a/pkg/init/Makefile b/pkg/init/Makefile index 058c4487a..9f1469350 100644 --- a/pkg/init/Makefile +++ b/pkg/init/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=init -DEPS=Dockerfile init $(wildcard etc/*) $(wildcard etc/init.d/*) usermode-helper.c - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=init usermode-helper.c $(wildcard etc/*) $(wildcard etc/init.d/*) diff --git a/pkg/metadata/Makefile b/pkg/metadata/Makefile index 5cbad34a9..12d180d42 100644 --- a/pkg/metadata/Makefile +++ b/pkg/metadata/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=metadata -DEPS=Dockerfile Makefile $(wildcard *.go) - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=$(wildcard *.go) diff --git a/pkg/mkimage/Makefile b/pkg/mkimage/Makefile index c6be6905c..3d51151d9 100644 --- a/pkg/mkimage/Makefile +++ b/pkg/mkimage/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=mkimage -DEPS=Dockerfile mkimage.sh - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=mkimage.sh diff --git a/pkg/mount/Makefile b/pkg/mount/Makefile index bb4571c82..1f721de94 100644 --- a/pkg/mount/Makefile +++ b/pkg/mount/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=mount -DEPS=Dockerfile mount.sh - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=mount.sh diff --git a/pkg/node_exporter/Makefile b/pkg/node_exporter/Makefile index 137c58fb7..60e928077 100644 --- a/pkg/node_exporter/Makefile +++ b/pkg/node_exporter/Makefile @@ -1,15 +1,3 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=node_exporter -DEPS=Dockerfile - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/pkg/open-vm-tools/Makefile b/pkg/open-vm-tools/Makefile index d0108b63e..a67cd6a5d 100644 --- a/pkg/open-vm-tools/Makefile +++ b/pkg/open-vm-tools/Makefile @@ -1,15 +1,3 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=open-vm-tools -DEPS=Dockerfile Makefile - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/pkg/openntpd/Makefile b/pkg/openntpd/Makefile index 2ed1be291..23be6b1b3 100644 --- a/pkg/openntpd/Makefile +++ b/pkg/openntpd/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=openntpd -DEPS=Dockerfile etc/ntpd.conf - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=etc/ntpd.conf diff --git a/pkg/package.mk b/pkg/package.mk new file mode 100644 index 000000000..4ef4f57c0 --- /dev/null +++ b/pkg/package.mk @@ -0,0 +1,17 @@ +.PHONY: tag push +default: push + +ORG?=linuxkit +HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') +BASE_DEPS=Dockerfile Makefile + +tag: $(BASE_DEPS) $(DEPS) +ifndef $(NETWORK) + docker build -t $(ORG)/$(IMAGE):$(HASH) . +else + docker build --network=none -t $(ORG)/$(IMAGE):$(HASH) . +endif + +push: tag + DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ + DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/pkg/qemu-ga/Makefile b/pkg/qemu-ga/Makefile index d87500b3d..7ac52f099 100644 --- a/pkg/qemu-ga/Makefile +++ b/pkg/qemu-ga/Makefile @@ -1,14 +1,3 @@ -.PHONY: tag push +include ../package.mk -ORG?=linuxkit IMAGE=qemu-ga - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -default: push - -tag: Dockerfile - docker build --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - docker pull $(ORG)/$(IMAGE):$(HASH) || docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/pkg/rngd/Makefile b/pkg/rngd/Makefile index f574cc8f1..ef32b17e3 100644 --- a/pkg/rngd/Makefile +++ b/pkg/rngd/Makefile @@ -1,15 +1,3 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=rngd -DEPS=Dockerfile - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) diff --git a/pkg/runc/Makefile b/pkg/runc/Makefile index 18a37fbe7..85859130c 100644 --- a/pkg/runc/Makefile +++ b/pkg/runc/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push +include ../package.mk -ORG?=linuxkit IMAGE=runc - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -default: push - -tag: Dockerfile - docker build -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +NETWORK=1 diff --git a/pkg/sshd/Makefile b/pkg/sshd/Makefile index 01b08e8fa..1f77441c3 100644 --- a/pkg/sshd/Makefile +++ b/pkg/sshd/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=sshd -DEPS=Dockerfile etc/motd etc/ssh/sshd_config usr/bin/ssh.sh - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=etc/motd etc/ssh/sshd_config usr/bin/ssh.sh diff --git a/pkg/swap/Makefile b/pkg/swap/Makefile index 558acbf9d..587703a0d 100644 --- a/pkg/swap/Makefile +++ b/pkg/swap/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=swap -DEPS=Dockerfile swap.sh - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=swap.sh diff --git a/pkg/sysctl/Makefile b/pkg/sysctl/Makefile index c23d22151..75d3cb32a 100644 --- a/pkg/sysctl/Makefile +++ b/pkg/sysctl/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=sysctl -DEPS=Dockerfile Makefile main.go - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=main.go diff --git a/pkg/sysfs/Makefile b/pkg/sysfs/Makefile index 4ac3947fc..2db2d8ecd 100644 --- a/pkg/sysfs/Makefile +++ b/pkg/sysfs/Makefile @@ -1,15 +1,4 @@ -.PHONY: tag push -default: push +include ../package.mk -ORG?=linuxkit IMAGE=sysfs -DEPS=Dockerfile Makefile main.go - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache --network=none -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) +DEPS=main.go diff --git a/pkg/vpnkit-forwarder/Makefile b/pkg/vpnkit-forwarder/Makefile index a952a6a53..bad19185d 100644 --- a/pkg/vpnkit-forwarder/Makefile +++ b/pkg/vpnkit-forwarder/Makefile @@ -1,15 +1,5 @@ -default: push +include ../package.mk -ORG?=linuxkit IMAGE=vpnkit-forwarder -DEPS=$(wildcard *.go) Makefile Dockerfile - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) - +DEPS=$(wildcard *.go) +NETWORK=1 diff --git a/pkg/vsudd/Makefile b/pkg/vsudd/Makefile index d1815bd3a..9307bb65d 100644 --- a/pkg/vsudd/Makefile +++ b/pkg/vsudd/Makefile @@ -1,15 +1,5 @@ -default: push +include ../package.mk -ORG?=linuxkit IMAGE=vsudd -DEPS=$(wildcard *.go) Makefile Dockerfile - -HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') - -tag: $(DEPS) - docker build --squash --no-cache -t $(ORG)/$(IMAGE):$(HASH) . - -push: tag - DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(HASH) || \ - DOCKER_CONTENT_TRUST=1 docker push $(ORG)/$(IMAGE):$(HASH) - +DEPS=$(wildcard *.go) +NETWORK=1