Skip to content

Commit a294f44

Browse files
committed
Docker based build pipeline.
Container provides gcloud, kubectl, and go with related tooling (dep and gometalinter). These should be a good start on tools for developing the first version of this project.
1 parent 20f6ab7 commit a294f44

6 files changed

Lines changed: 251 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Agon is a library for running dedicated game servers on [Kubernetes](https://kub
1212
- Simple example code
1313
- Documentation of the above
1414

15+
## Development
16+
See the tools in the [build](build/README.md) directory for testing and building Agon.
17+
1518
## Licence
1619

1720
Apache 2.0

build/Makefile

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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

build/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Build
2+
3+
Tooling for building and developing against Agon, with only dependency being [Docker](https://www.docker.com).
4+
5+
Rather than installing all the dependencies locally, you can test and build Agon using the Docker image that can
6+
be build from the Dockerfile based image in this directory. There is an accompanying Makefile for all the common
7+
tasks you may wish to accomplish.
8+
9+
## Make Targets
10+
11+
### `make shell`
12+
Run a bash shell with the developer tools ad source code in it.
13+
Also creates the image if it doesn't exist
14+
15+
### `make clean-config`
16+
Cleans the kubernetes and gcloud configurations
17+
18+
### `make clean-image`
19+
Deletes the local build docker image
20+
21+
### `make build-image`
22+
Creates the build docker image
23+
24+
## Google Cloud Platform
25+
26+
A set of utilities for setting up a Container Engine cluster on Google Cloud Platform,
27+
since it's an easy way to get a test cluster working with Kubernetes.
28+
29+
### `make gcloud-init`
30+
Initialise the gcloud login and project configuration, if you are working with GCP
31+
32+
### `make gcloud-test-cluster`
33+
Creates and authenticates a small, 3 node GKE cluster to work against
34+
35+
### `make gcloud-auth-cluster`
36+
Pulls down authentication information for kubectl against a cluster, name can be specified through CLUSTER_NAME
37+
(defaults to 'test-cluster')

build/build-image/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
FROM golang:1.9.1
16+
17+
RUN apt-get update && apt-get install -y wget unzip bash-completion
18+
19+
WORKDIR /
20+
21+
# install gcloud + kubectl, because it's an easy way to test/dev against kubernetes.
22+
RUN wget -q https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.zip && unzip -q google-cloud-sdk.zip && rm google-cloud-sdk.zip
23+
RUN /google-cloud-sdk/install.sh --usage-reporting=true --path-update=true --bash-completion=true --rc-path=/root/.bashrc
24+
ENV PATH /google-cloud-sdk/bin:$PATH
25+
26+
RUN gcloud components update && gcloud components install kubectl
27+
RUN echo "source <(kubectl completion bash)" >> /root/.bashrc
28+
29+
# install go tooling for building and testing
30+
RUN go get -u github.com/golang/dep/cmd/dep && \
31+
go get -u github.com/alecthomas/gometalinter && \
32+
/go/bin/gometalinter --install && \
33+
mv /go/bin/* /usr/local/bin/ && \
34+
rm -r /go/src/* && \
35+
rm -r /go/pkg
36+
37+
# make sure we keep the path to go
38+
RUN echo "export PATH=/usr/local/go/bin:\$PATH" >> /root/.bashrc
39+
40+
ENTRYPOINT kubectl
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{#
2+
Copyright 2017 Google Inc. All rights reserved.
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+
resources:
17+
- name: test-cluster
18+
type: container.v1.cluster
19+
properties:
20+
zone: {{ properties["zone"] }}
21+
cluster:
22+
name: test-cluster
23+
description: Test cluster for Agon
24+
nodePools:
25+
- name: "default"
26+
initialNodeCount: 3
27+
config:
28+
machineType: n1-standard-4
29+
tags:
30+
- game-server
31+
oauthScopes:
32+
- https://www.googleapis.com/auth/devstorage.read_only
33+
- https://www.googleapis.com/auth/compute
34+
- https://www.googleapis.com/auth/cloud-platform
35+
masterAuth:
36+
username: admin
37+
password: supersecret
38+
- name: game-server-firewall
39+
type: compute.v1.firewall
40+
properties:
41+
name: game-server
42+
targetTags:
43+
- "game-server"
44+
allowed:
45+
- IPProtocol: udp
46+
ports:
47+
- "7000-8000"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
imports:
16+
- path: cluster.yml.jinja
17+
18+
resources:
19+
- name: test-cluster
20+
type: cluster.yml.jinja
21+
properties:
22+
zone: us-west1-c

0 commit comments

Comments
 (0)