|
1 | | -include ../includes.mk |
| 1 | +# Short name: Short name, following [a-zA-Z_], used all over the place. |
| 2 | +# Some uses for short name: |
| 3 | +# - Docker image name |
| 4 | +# - Kubernetes service, rc, pod, secret, volume names |
| 5 | +SHORT_NAME := example |
2 | 6 |
|
3 | | -repo_path = github.com/deis/deis/pkg |
| 7 | +# Enable vendor/ directory support. |
| 8 | +export GO15VENDOREXPERIMENT=1 |
4 | 9 |
|
5 | | -GO_PACKAGES = prettyprint time |
6 | | -GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES)) |
| 10 | +# SemVer with build information is defined in the SemVer 2 spec, but Docker |
| 11 | +# doesn't allow +, so we use -. |
| 12 | +VERSION := 0.0.1-$(shell date "+%Y%m%d%H%M%S") |
7 | 13 |
|
8 | | -test: test-style test-unit |
| 14 | +# Common flags passed into Go's linker. |
| 15 | +LDFLAGS := "-s -X main.version=${VERSION}" |
9 | 16 |
|
10 | | -test-style: |
11 | | -# display output, then check |
12 | | - $(GOFMT) $(GO_PACKAGES) |
13 | | - @$(GOFMT) $(GO_PACKAGES) | read; if [ $$? == 0 ]; then echo "gofmt check failed."; exit 1; fi |
14 | | - $(GOVET) $(GO_PACKAGES_REPO_PATH) |
15 | | - $(GOLINT) ./... |
| 17 | +# Docker Root FS |
| 18 | +BINDIR := ./rootfs |
16 | 19 |
|
17 | | -test-unit: |
18 | | - $(GOTEST) ./... |
| 20 | +# Legacy support for DEV_REGISTRY, plus new support for DEIS_REGISTRY. |
| 21 | +DEV_REGISTRY ?= $(eval docker-machine ip deis):5000 |
| 22 | +DEIS_REGISTY ?= ${DEV_REGISTRY} |
| 23 | + |
| 24 | +# Kubernetes-specific information for RC, Service, and Image. |
| 25 | +RC := manifests/deis-${SHORT_NAME}-rc.yaml |
| 26 | +SVC := manifests/deis-${SHORT_NAME}-service.yaml |
| 27 | +IMAGE := ${DEIS_REGISTRY}/deis/${SHORT_NAME}:${VERSION} |
| 28 | + |
| 29 | +all: |
| 30 | + @echo "Use a Makefile to control top-level building of the project." |
| 31 | + |
| 32 | +# This illustrates a two-stage Docker build. docker-compile runs inside of |
| 33 | +# the Docker environment. Other alternatives are cross-compiling, doing |
| 34 | +# the build as a `docker build`. |
| 35 | +build: |
| 36 | + mkdir -p ${BINDIR}/bin |
| 37 | + docker run --rm -v ${PWD}:/app -w /app golang:1.5.1 make docker-compile |
| 38 | + |
| 39 | +# For cases where build is run inside of a container. |
| 40 | +docker-compile: |
| 41 | + go build -o ${BINDIR}/bin/boot -a -installsuffix cgo -ldflags ${LDFLAGS} boot.go |
| 42 | + |
| 43 | +# For cases where we're building from local |
| 44 | +# We also alter the RC file to set the image name. |
| 45 | +docker-build: |
| 46 | + docker build --rm -t ${IMAGE} rootfs |
| 47 | + perl -pi -e "s|[a-z0-9.:]+\/deis\/${SHORT_NAME}:[0-9a-z-.]+|${IMAGE}|g" ${RC} |
| 48 | + |
| 49 | +# Push to a registry that Kubernetes can access. |
| 50 | +docker-push: |
| 51 | + docker push ${IMAGE} |
| 52 | + |
| 53 | +# Deploy is a Kubernetes-oriented target |
| 54 | +deploy: kube-service kube-rc |
| 55 | + |
| 56 | +# Some things, like services, have to be deployed before pods. This is an |
| 57 | +# example target. Others could perhaps include kube-secret, kube-volume, etc. |
| 58 | +kube-service: |
| 59 | + kubectl create -f ${SVC} |
| 60 | + |
| 61 | +# When possible, we deploy with RCs. |
| 62 | +kube-rc: |
| 63 | + kubectl create -f ${RC} |
| 64 | + |
| 65 | +kube-clean: |
| 66 | + kubectl delete rc deis-example |
| 67 | + |
| 68 | +.PHONY: all build docker-compile kube-up kube-down deploy |
0 commit comments