-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (64 loc) · 2.83 KB
/
Makefile
File metadata and controls
80 lines (64 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Short name: Short name, following [a-zA-Z_], used all over the place.
# Some uses for short name:
# - Docker image name
# - Kubernetes service, rc, pod, secret, volume names
SHORT_NAME := example
# Enable vendor/ directory support.
export GO15VENDOREXPERIMENT=1
# SemVer with build information is defined in the SemVer 2 spec, but Docker
# doesn't allow +, so we use -.
VERSION := 0.0.1-$(shell date "+%Y%m%d%H%M%S")
# Common flags passed into Go's linker.
LDFLAGS := "-s -X main.version=${VERSION}"
# Docker Root FS
BINDIR := ./rootfs
# Legacy support for DEV_REGISTRY, plus new support for DEIS_REGISTRY.
DEV_REGISTRY ?= $(eval docker-machine ip deis):5000
DEIS_REGISTY ?= ${DEV_REGISTRY}
# Kubernetes-specific information for RC, Service, and Image.
RC := manifests/deis-${SHORT_NAME}-rc.yaml
SVC := manifests/deis-${SHORT_NAME}-service.yaml
IMAGE := ${DEIS_REGISTRY}/deis/${SHORT_NAME}:${VERSION}
all:
@echo "Use a Makefile to control top-level building of the project."
# This illustrates a two-stage Docker build. docker-compile runs inside of
# the Docker environment. Other alternatives are cross-compiling, doing
# the build as a `docker build`.
build:
mkdir -p ${BINDIR}/bin
docker run --rm -v ${PWD}:/app -w /app golang:1.5.1 make docker-compile
build-bpb:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/builder cli/builder.go || exit 1
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/fetcher fetcher/fetcher.go || exit 1
@$(call check-static-binary,$(BINARY_DEST_DIR)/builder)
@$(call check-static-binary,$(BINARY_DEST_DIR)/fetcher)
for i in $(BINARIES); do \
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o $(BINARY_DEST_DIR)/$$i src/$$i.go || exit 1; \
done
@for i in $(BINARIES); do \
$(call check-static-binary,$(BINARY_DEST_DIR)/$$i); \
done
docker build -t $(IMAGE) rootfs
# For cases where build is run inside of a container.
docker-compile:
go build -o ${BINDIR}/bin/boot -a -installsuffix cgo -ldflags ${LDFLAGS} boot.go
# For cases where we're building from local
# We also alter the RC file to set the image name.
docker-build:
docker build --rm -t ${IMAGE} rootfs
perl -pi -e "s|[a-z0-9.:]+\/deis\/${SHORT_NAME}:[0-9a-z-.]+|${IMAGE}|g" ${RC}
# Push to a registry that Kubernetes can access.
docker-push:
docker push ${IMAGE}
# Deploy is a Kubernetes-oriented target
deploy: kube-service kube-rc
# Some things, like services, have to be deployed before pods. This is an
# example target. Others could perhaps include kube-secret, kube-volume, etc.
kube-service:
kubectl create -f ${SVC}
# When possible, we deploy with RCs.
kube-rc:
kubectl create -f ${RC}
kube-clean:
kubectl delete rc deis-example
.PHONY: all build docker-compile kube-up kube-down deploy