Skip to content
Permalink
Browse files

Improve our Makefile (#95)

* Makefile: fix usage of variables

Using variables like $SHIPPER_IMAGE instead of $(SHIPPER_IMAGE) causes
errors like this:

	/bin/sh: HIPPER_IMAGE: command not found

It appears make interpolates variables like $(THIS) instead of like $THIS.

* Makefile: track dependencies of shipper binaries

First of all, "shipper" is not a phony target [1]: it actually generates
a binary called "shipper". I suppose it was declared as phony so `make
shipper` would always be executed, instead of bailing out with "make:
`shipper' is up to date."

If we declare our dependencies correctly, though, it'll always execute
if the dependencies are changed, which is most likely what we actually
want, so let's do that.

[1] https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html

* Makefile: allow variables to be overridden by the environment

It's very useful to be able to override names of images and commands
executed by the Makefile during testing. I can have my own image
registry, put shipper in any namespace I want, and I can also teach it
to work with microk8s.kubectl without having to resort to symlinks :)

* Makefile: depend on nested dirs inside pkg/ vendor/

Silly me, pkg/* doesn't actually go deeper than 1 level, pkg/**/* is
needed for that. Without it, modifying any files inside any directory in
pkg/ or vendor/ and then calling `make shipper` wouldn't actually result
in the task being executed.
  • Loading branch information...
juliogreff authored and icanhazbroccoli committed May 17, 2019
1 parent 04d2fe3 commit 3584fd589014d942fef17098f2f3957eb3267992
Showing with 11 additions and 12 deletions.
  1. +11 −12 Makefile
@@ -1,19 +1,18 @@
SHIPPER_IMAGE = bookingcom/shipper:latest
METRICS_IMAGE = bookingcom/shipper-state-metrics:latest
SHIPPER_NAMESPACE = shipper-system
KUBECTL = kubectl -n $(SHIPPER_NAMESPACE)
SHIPPER_IMAGE ?= bookingcom/shipper:latest
METRICS_IMAGE ?= bookingcom/shipper-state-metrics:latest
SHIPPER_NAMESPACE ?= shipper-system
KUBECTL ?= kubectl -n $(SHIPPER_NAMESPACE)
PKG = pkg/**/* vendor/**/*

.PHONY: shipper

shipper:
shipper: $(PKG) cmd/shipper/* Dockerfile.shipper
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o shipper ./cmd/shipper/*.go
docker build -f Dockerfile.shipper -t $SHIPPER_IMAGE --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg HTTPS_PROXY=$(HTTPS_PROXY) .
docker push $SHIPPER_IMAGE
docker build -f Dockerfile.shipper -t $(SHIPPER_IMAGE) --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg HTTPS_PROXY=$(HTTPS_PROXY) .
docker push $(SHIPPER_IMAGE)

shipper-state-metrics:
shipper-state-metrics: $(PKG) cmd/shipper-state-metrics/* Dockerfile.shipper-state-metrics
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o shipper-state-metrics ./cmd/shipper-state-metrics/*.go
docker build -f Dockerfile.shipper-state-metrics -t $METRICS_IMAGE --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg HTTPS_PROXY=$(HTTPS_PROXY) .
docker push $METRICS_IMAGE
docker build -f Dockerfile.shipper-state-metrics -t $(METRICS_IMAGE) --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg HTTPS_PROXY=$(HTTPS_PROXY) .
docker push $(METRICS_IMAGE)

restart:
# Delete all Pods in namespace, to force the ReplicaSet to spawn new ones

0 comments on commit 3584fd5

Please sign in to comment.
You can’t perform that action at this time.