David K. Bainbridge | 528b318 | 2017-01-23 08:51:59 -0800 | [diff] [blame^] | 1 | IMAGE_NAME=cord-provisioner |
| 2 | BINARY=entry-point |
| 3 | BUILD_TAG=build |
| 4 | PACKAGE_TAG=candidate |
| 5 | |
| 6 | .PHONY: help |
| 7 | help: |
| 8 | @echo "build - create the binary" |
| 9 | @echo "package - package the binary into a docker container" |
| 10 | @echo "clean - remove tempory files and build artifacts" |
| 11 | @echo "help - this message" |
| 12 | |
| 13 | BUILD_DATE=$(shell date -u +%Y-%m-%dT%TZ) |
| 14 | VCS_REF=$(shell git log --pretty=format:%H -n 1) |
| 15 | VCS_REF_DATE=$(shell git log --pretty=format:%cd --date=format:%FT%T%z -n 1) |
| 16 | BRANCHES=$(shell repo --color=never --no-pager branches 2>/dev/null | wc -l) |
| 17 | STATUS=$(shell repo --color=never --no-pager status . | tail -n +2 | wc -l) |
| 18 | MODIFIED=$(shell test $(BRANCHES) -eq 0 && test $(STATUS) -eq 0 || echo "[modified]") |
| 19 | BRANCH=$(shell repo --color=never --no-pager info -l -o | grep 'Manifest branch:' | awk '{print $$NF}') |
| 20 | VERSION=$(BRANCH)$(MODIFIED) |
| 21 | |
| 22 | .PHONY: build |
| 23 | build: |
| 24 | docker build -t $(IMAGE_NAME):$(BUILD_TAG) . |
| 25 | |
| 26 | .PHONY: package |
| 27 | package: |
| 28 | $(eval BUILD_ID := $(shell docker create $(IMAGE_NAME):$(BUILD_TAG))) |
| 29 | $(eval BINDIR := $(shell mktemp -d)) |
| 30 | docker cp $(BUILD_ID):/service/$(BINARY) $(BINDIR)/$(BINARY) |
| 31 | cp Dockerfile.release ssh-config $(BINDIR) |
| 32 | docker build -f $(BINDIR)/Dockerfile.release -t $(IMAGE_NAME):$(PACKAGE_TAG) --label org.label-schema.build-date=$(BUILD_DATE) --label org.label-schema.vcs-ref=$(VCS_REF) --label org.label-schema.vcs-ref-date=$(VCS_REF_DATE) --label org.label-schema.version=$(VERSION) $(BINDIR) |
| 33 | docker rm -f $(BUILD_ID) |
| 34 | rm -r $(BINDIR) |
| 35 | |
| 36 | .PHONY: clean |
| 37 | clean: |
| 38 | @echo "" |