Skip to content

Commit

Permalink
Implement Versioning for dev and release
Browse files Browse the repository at this point in the history
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 #21
  • Loading branch information
markmandel committed Dec 14, 2017
1 parent 0c61acb commit a1acea4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This software is currenty alpha, and subject to change. Not to be used in produc
## Installation
`kubectl apply -f install.yaml`

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

## Usage
Expand Down
28 changes: 24 additions & 4 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@
# \_/ \__,_|_| |_|\__,_|_.__/|_|\___|___/
#

VERSION ?= 0.1
# base version target. This is usually the next release.
base_version = 0.1

#
# All of the following can be overwritten with environemt variables
# or passed through directly when invoking the relevent Make targets
#

# Version defaults to the short hash of the latest commit
VERSION ?= $(base_version)-$(shell git rev-parse --short HEAD)
# The registry that is being used to store docker images
REGISTRY ?= gcr.io/agon-images
CLUSTER_NAME ?= test-cluster
# Where the kubectl configuration files are being stored
KUBECONFIG ?= $(build_path)/.kube
# The (gcloud) test cluster that is being worked against
CLUSTER_NAME ?= test-cluster

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

go_version_flags = -ldflags "-X github.com/agonio/agon/pkg.Version=$(VERSION)"

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
# | |/ _` | '__/ _` |/ _ \ __/ __|
Expand All @@ -63,10 +77,16 @@ test: ensure-image
# Push all the images up to $(REGISTRY)
push: push-gameservers-controller-image push-gameservers-sidecar-image

# install the development version of Agon
install:
cp $(build_path)/install.yaml $(build_path)/.install.yaml
sed -i -e 's!$${REGISTRY}!$(REGISTRY)!g' -e 's!$${VERSION}!$(VERSION)!g' $(build_path)/.install.yaml
docker run --rm $(common_mounts) --entrypoint=kubectl $(build_tag) apply -f $(mount_path)/build/.install.yaml

# Build a static binary for the gameserver controller
build-gameservers-controller-binary: ensure-image
docker run --rm -e "CGO_ENABLED=0" $(common_mounts) --entrypoint=go $(build_tag) build \
-o $(mount_path)/gameservers/controller/bin/controller -a -installsuffix cgo $(agon_package)/gameservers/controller
-o $(mount_path)/gameservers/controller/bin/controller -a $(go_version_flags) -installsuffix cgo $(agon_package)/gameservers/controller

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

# Build the image for the gameserver sidecar
build-gameservers-sidecar-image: ensure-image build-gameservers-sidecar-binary
Expand Down
53 changes: 53 additions & 0 deletions build/install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Install with development settings - suggest using `make install` to run

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: gameservers.stable.agon.io
spec:
group: stable.agon.io
version: v1alpha1
scope: Namespaced
names:
kind: GameServer
plural: gameservers
shortNames:
- gs
singular: gameserver
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: gameservers-controller
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
stable.agon.io/role: controller
spec:
containers:
- name: gameservers-controller
image: ${REGISTRY}/gameservers-controller:${VERSION}
imagePullPolicy: Always
env:
- name: ALWAYS_PULL_SIDECAR # set the sidecar imagePullPolicy to Always
value: "true"
- name: SIDECAR # overwrite the GameServer sidecar image that is used
value: ${REGISTRY}/gameservers-sidecar:${VERSION}
5 changes: 1 addition & 4 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ spec:
stable.agon.io/role: controller
spec:
containers:
- name: gameservers-controller
- nameW: gameservers-controller

This comment has been minimized.

Copy link
@dzlier-gcp

dzlier-gcp Dec 20, 2017

Contributor

Was this W on purpose? I get a validation error when trying to run it with this.

This comment has been minimized.

Copy link
@markmandel

markmandel Dec 20, 2017

Author Member

Whoops! That's a bug. That W should not be there.

image: gcr.io/agon-images/gameservers-controller:0.1
imagePullPolicy: Always # remove/set to IfNotPresent for production
env:
- name: ALWAYS_PULL_SIDECAR
value: "true" # set to false for production
# - name: SIDECAR # overwrite the GameServer sidecar image that is used
# value: gcr.io/agon-images/gameservers-sidecar:0.1
5 changes: 3 additions & 2 deletions pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

package pkg

const (
var (
// Version is the global version for all binaries
Version = "0.1"
// This is set at compile time by the build process
Version string = "dev"
)

0 comments on commit a1acea4

Please sign in to comment.