1+ # Copyright 2017 Google Inc. All Rights Reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ #
16+ # Makefile for building, testing and developing Agon
17+ #
18+
19+ # __ __ _ _ _
20+ # \ \ / /_ _ _ __(_) __ _| |__ | | ___ ___
21+ # \ \ / / _` | '__| |/ _` | '_ \| |/ _ \ __|
22+ # \ V / (_| | | | | (_| | |_) | | __\__ \
23+ # \_/ \__,_|_| |_|\__,_|_.__/|_|\___|___/
24+ #
25+
26+ NAME = agon-build
27+ VERSION = 0.1
28+ TAG = $(NAME ) :$(VERSION )
29+ CLUSTER_NAME = test-cluster
30+ KUBECONFIG = $(build_path ) /.kube
31+
32+ # Directory that this Makefile is in.
33+ mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST ) ) )
34+ build_path := $(dir $(mkfile_path ) )
35+ agon_path := $(realpath $(build_path ) /..)
36+
37+ mount_path = /go/src/github.com/agonio/agon
38+ common_mounts = -v $(build_path ) /.config/gcloud:/root/.config/gcloud \
39+ -v $(KUBECONFIG ) :/root/.kube \
40+ -v $(agon_path ) :$(mount_path )
41+
42+ # _____ _
43+ # |_ _|_ _ _ __ __ _ ___| |_ ___
44+ # | |/ _` | '__/ _` |/ _ \ __/ __|
45+ # | | (_| | | | (_| | __/ |_\__ \
46+ # |_|\__,_|_| \__, |\___|\__|___/
47+ # |___/
48+
49+ # Run a bash shell with the developer tools in it. (Creates the image if it doesn't exist)
50+ # Can use ARGS for extra arguments.
51+ shell : ensure-image
52+ docker run -it --rm \
53+ $(common_mounts ) \
54+ -w $(mount_path ) \
55+ $(ARGS ) \
56+ --entrypoint=bash $(TAG ) -l
57+
58+ .PHONY : build-image
59+
60+ # Creates the build docker image
61+ build-image :
62+ docker build --tag=$(TAG ) $(build_path ) /build-image
63+
64+ # Deletes the local build docker image
65+ clean-image :
66+ docker rmi $(TAG )
67+
68+ ensure-config :
69+ -mkdir -p $(build_path ) /.kube
70+ -mkdir -p $(build_path ) /.config/gcloud
71+
72+ ensure-image : ensure-config
73+ @if [ -z $$ (docker images -q $( TAG) ) ]; then\
74+ echo " Could not find $( TAG) image. Building..." ; \
75+ $(MAKE ) build-image; \
76+ fi
77+
78+ # Initialise the gcloud login and project configuration, if you are working with GCP
79+ gcloud-init : ensure-config
80+ docker run --rm -it \
81+ $(common_mounts ) \
82+ --entrypoint=" gcloud" $(TAG ) init
83+
84+ # Creates and authenticates a small, 3 node GKE cluster to work against
85+ gcloud-test-cluster :
86+ docker run --rm -it $(common_mounts ) \
87+ --entrypoint=" gcloud" $(TAG ) \
88+ deployment-manager deployments create test-cluster --config=$(mount_path ) /build/gke-test-cluster/deployment.yml
89+ $(MAKE ) gcloud-auth-cluster
90+
91+ # Pulls down authentication information for kubectl against a cluster, name can be specified through CLUSTER_NAME
92+ # (defaults to 'test-cluster')
93+ gcloud-auth-cluster :
94+ docker run --rm $(common_mounts ) --entrypoint=" gcloud" $(TAG ) config set container/cluster $(CLUSTER_NAME )
95+ docker run --rm $(common_mounts ) --entrypoint=" gcloud" $(TAG ) config set compute/zone \
96+ ` grep zone: $( build_path) /gke-test-cluster/deployment.yml | sed ' s/zone: //' `
97+ docker run --rm $(common_mounts ) --entrypoint=" gcloud" $(TAG ) container clusters get-credentials $(CLUSTER_NAME )
98+
99+ # Clean the kubernetes and gcloud configuration
100+ clean-config :
101+ -sudo rm -r $(build_path ) /.kube
102+ -sudo rm -r $(build_path ) /.config
0 commit comments