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

Commit

Permalink
Improve our Makefile (#95)
Browse files Browse the repository at this point in the history
* 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 Oleg Sidorov committed May 17, 2019
1 parent 04d2fe3 commit 3584fd5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Makefile
Original file line number Original file line Diff line number Diff line change
@@ -1,19 +1,18 @@
SHIPPER_IMAGE = bookingcom/shipper:latest SHIPPER_IMAGE ?= bookingcom/shipper:latest
METRICS_IMAGE = bookingcom/shipper-state-metrics:latest METRICS_IMAGE ?= bookingcom/shipper-state-metrics:latest
SHIPPER_NAMESPACE = shipper-system SHIPPER_NAMESPACE ?= shipper-system
KUBECTL = kubectl -n $(SHIPPER_NAMESPACE) KUBECTL ?= kubectl -n $(SHIPPER_NAMESPACE)
PKG = pkg/**/* vendor/**/*


.PHONY: shipper shipper: $(PKG) cmd/shipper/* Dockerfile.shipper

shipper:
GOARCH=amd64 CGO_ENABLED=0 GOOS=linux go build -o shipper ./cmd/shipper/*.go 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 build -f Dockerfile.shipper -t $(SHIPPER_IMAGE) --build-arg HTTP_PROXY=$(HTTP_PROXY) --build-arg HTTPS_PROXY=$(HTTPS_PROXY) .
docker push $SHIPPER_IMAGE 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 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 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 push $(METRICS_IMAGE)


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

0 comments on commit 3584fd5

Please sign in to comment.