Skip to content

Commit a1acea4

Browse files
committed
Implement Versioning for dev and release
When working in development, images and go binaries will be versioned with the git hash. On release the version can be overwritten in the `build/Makefile` to explicitly set the version. Closes agones-dev#21
1 parent 0c61acb commit a1acea4

5 files changed

Lines changed: 82 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This software is currenty alpha, and subject to change. Not to be used in produc
2020
## Installation
2121
`kubectl apply -f install.yaml`
2222

23-
If you are running your own Docker repository, make a local copy of install.yaml
23+
If you are running your own Docker repository or want to install a specific version, make a local copy of install.yaml
2424
and edit to match your settings.
2525

2626
## Usage

build/Makefile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,22 @@
2323
# \_/ \__,_|_| |_|\__,_|_.__/|_|\___|___/
2424
#
2525

26-
VERSION ?= 0.1
26+
# base version target. This is usually the next release.
27+
base_version = 0.1
28+
29+
#
30+
# All of the following can be overwritten with environemt variables
31+
# or passed through directly when invoking the relevent Make targets
32+
#
33+
34+
# Version defaults to the short hash of the latest commit
35+
VERSION ?= $(base_version)-$(shell git rev-parse --short HEAD)
36+
# The registry that is being used to store docker images
2737
REGISTRY ?= gcr.io/agon-images
28-
CLUSTER_NAME ?= test-cluster
38+
# Where the kubectl configuration files are being stored
2939
KUBECONFIG ?= $(build_path)/.kube
40+
# The (gcloud) test cluster that is being worked against
41+
CLUSTER_NAME ?= test-cluster
3042

3143
# Directory that this Makefile is in.
3244
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
@@ -46,6 +58,8 @@ build_tag = agon-build:$(build_version)
4658
controller_tag = $(REGISTRY)/gameservers-controller:$(VERSION)
4759
sidecar_tag = $(REGISTRY)/gameservers-sidecar:$(VERSION)
4860

61+
go_version_flags = -ldflags "-X github.com/agonio/agon/pkg.Version=$(VERSION)"
62+
4963
# _____ _
5064
# |_ _|_ _ _ __ __ _ ___| |_ ___
5165
# | |/ _` | '__/ _` |/ _ \ __/ __|
@@ -63,10 +77,16 @@ test: ensure-image
6377
# Push all the images up to $(REGISTRY)
6478
push: push-gameservers-controller-image push-gameservers-sidecar-image
6579

80+
# install the development version of Agon
81+
install:
82+
cp $(build_path)/install.yaml $(build_path)/.install.yaml
83+
sed -i -e 's!$${REGISTRY}!$(REGISTRY)!g' -e 's!$${VERSION}!$(VERSION)!g' $(build_path)/.install.yaml
84+
docker run --rm $(common_mounts) --entrypoint=kubectl $(build_tag) apply -f $(mount_path)/build/.install.yaml
85+
6686
# Build a static binary for the gameserver controller
6787
build-gameservers-controller-binary: ensure-image
6888
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) --entrypoint=go $(build_tag) build \
69-
-o $(mount_path)/gameservers/controller/bin/controller -a -installsuffix cgo $(agon_package)/gameservers/controller
89+
-o $(mount_path)/gameservers/controller/bin/controller -a $(go_version_flags) -installsuffix cgo $(agon_package)/gameservers/controller
7090

7191
# Build the image for the gameserver controller
7292
build-gameservers-controller-image: ensure-image build-gameservers-controller-binary
@@ -79,7 +99,7 @@ push-gameservers-controller-image: ensure-image
7999
# build the static binary for the gamesever sidecar
80100
build-gameservers-sidecar-binary: ensure-image
81101
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) --entrypoint=go $(build_tag) build \
82-
-o $(mount_path)/gameservers/sidecar/bin/sidecar -a -installsuffix cgo $(agon_package)/gameservers/sidecar
102+
-o $(mount_path)/gameservers/sidecar/bin/sidecar -a $(go_version_flags) -installsuffix cgo $(agon_package)/gameservers/sidecar
83103

84104
# Build the image for the gameserver sidecar
85105
build-gameservers-sidecar-image: ensure-image build-gameservers-sidecar-binary

build/install.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
# Install with development settings - suggest using `make install` to run
16+
17+
apiVersion: apiextensions.k8s.io/v1beta1
18+
kind: CustomResourceDefinition
19+
metadata:
20+
name: gameservers.stable.agon.io
21+
spec:
22+
group: stable.agon.io
23+
version: v1alpha1
24+
scope: Namespaced
25+
names:
26+
kind: GameServer
27+
plural: gameservers
28+
shortNames:
29+
- gs
30+
singular: gameserver
31+
---
32+
apiVersion: extensions/v1beta1
33+
kind: Deployment
34+
metadata:
35+
name: gameservers-controller
36+
spec:
37+
replicas: 1
38+
strategy:
39+
type: Recreate
40+
template:
41+
metadata:
42+
labels:
43+
stable.agon.io/role: controller
44+
spec:
45+
containers:
46+
- name: gameservers-controller
47+
image: ${REGISTRY}/gameservers-controller:${VERSION}
48+
imagePullPolicy: Always
49+
env:
50+
- name: ALWAYS_PULL_SIDECAR # set the sidecar imagePullPolicy to Always
51+
value: "true"
52+
- name: SIDECAR # overwrite the GameServer sidecar image that is used
53+
value: ${REGISTRY}/gameservers-sidecar:${VERSION}

install.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ spec:
4141
stable.agon.io/role: controller
4242
spec:
4343
containers:
44-
- name: gameservers-controller
44+
- nameW: gameservers-controller
4545
image: gcr.io/agon-images/gameservers-controller:0.1
46-
imagePullPolicy: Always # remove/set to IfNotPresent for production
4746
env:
48-
- name: ALWAYS_PULL_SIDECAR
49-
value: "true" # set to false for production
5047
# - name: SIDECAR # overwrite the GameServer sidecar image that is used
5148
# value: gcr.io/agon-images/gameservers-sidecar:0.1

pkg/version.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
package pkg
1616

17-
const (
17+
var (
1818
// Version is the global version for all binaries
19-
Version = "0.1"
19+
// This is set at compile time by the build process
20+
Version string = "dev"
2021
)

0 commit comments

Comments
 (0)