Skip to content

Commit

Permalink
Merge pull request #26 from googleprivate/feaure/gcloud-auth-push
Browse files Browse the repository at this point in the history
Make targets `gcloud docker --authorize-only` and `push`
  • Loading branch information
markmandel authored Dec 13, 2017
2 parents a79bdb7 + 09c0888 commit 469443d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
29 changes: 25 additions & 4 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#

VERSION ?= 0.1
REGISTRY ?= gcr.io/agon-images
CLUSTER_NAME ?= test-cluster
KUBECONFIG ?= $(build_path)/.kube
REPOSITORY ?= gcr.io/agon-images

# Directory that this Makefile is in.
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
Expand All @@ -43,8 +43,8 @@ common_mounts = -v $(build_path)/.config/gcloud:/root/.config/gcloud \
# it automatically rebuilds
build_version := $(shell sha256sum $(build_path)/build-image/Dockerfile | head -c 10)
build_tag = agon-build:$(build_version)
gameserver_tag = $(REPOSITORY)/gameservers-controller:$(VERSION)
sidecar_tag = $(REPOSITORY)/gameservers-sidecar:$(VERSION)
controller_tag = $(REGISTRY)/gameservers-controller:$(VERSION)
sidecar_tag = $(REGISTRY)/gameservers-sidecar:$(VERSION)

# _____ _
# |_ _|_ _ _ __ __ _ ___| |_ ___
Expand All @@ -60,14 +60,21 @@ build: build-gameservers-controller-image build-gameservers-sidecar-image
test: ensure-image
docker run --rm $(common_mounts) --entrypoint=go $(build_tag) test -race $(agon_package)/...

# Push all the images up to $(REGISTRY)
push: push-gameservers-controller-image push-gameservers-sidecar-image

# 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

# Build the image for the gameserver controller
build-gameservers-controller-image: ensure-image build-gameservers-controller-binary
docker build $(agon_path)/gameservers/controller/ --tag=$(gameserver_tag)
docker build $(agon_path)/gameservers/controller/ --tag=$(controller_tag)

# push the gameservers controller image
push-gameservers-controller-image: ensure-image
docker push $(controller_tag)

# build the static binary for the gamesever sidecar
build-gameservers-sidecar-binary: ensure-image
Expand All @@ -78,6 +85,10 @@ build-gameservers-sidecar-binary: ensure-image
build-gameservers-sidecar-image: ensure-image build-gameservers-sidecar-binary
docker build $(agon_path)/gameservers/sidecar/ --tag=$(sidecar_tag)

# push the gameservers sidecar image
push-gameservers-sidecar-image: ensure-image
docker push $(sidecar_tag)

# Generate the sidecar gRPC code
gen-gameservers-sidecar-grpc: ensure-image
docker run --rm $(common_mounts) --entrypoint="/root/gen-grpc-go.sh" $(build_tag)
Expand Down Expand Up @@ -147,6 +158,16 @@ gcloud-auth-cluster:
`grep zone: $(build_path)/gke-test-cluster/deployment.yml | sed 's/zone: //'`
docker run --rm $(common_mounts) --entrypoint="gcloud" $(build_tag) container clusters get-credentials $(CLUSTER_NAME)

# authenticate our docker configuration so that you can do a docker push directly
# to the gcr.io repository
gcloud-auth-docker:
-sudo rm -rf /tmp/gcloud-auth-docker
mkdir -p /tmp/gcloud-auth-docker
-cp ~/.dockercfg /tmp/gcloud-auth-docker
docker run --rm $(common_mounts) -v /tmp/gcloud-auth-docker:/root --entrypoint="gcloud" $(build_tag) docker --authorize-only
sudo mv /tmp/gcloud-auth-docker/.dockercfg ~/
sudo chown $(USER) ~/.dockercfg

# Clean the kubernetes and gcloud configuration
clean-config:
-sudo rm -r $(build_path)/.kube
Expand Down
7 changes: 7 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Build all the images required for Agon
#### `make test`
Run all tests

### `make push`
Pushes all built images up to the `$(REGISTRY)`

### `make shell`
Run a bash shell with the developer tools (go tooling, kubectl, etc) and source code in it.

Expand Down Expand Up @@ -73,3 +76,7 @@ Creates and authenticates a small, 3 node GKE cluster to work against
### `make gcloud-auth-cluster`
Pulls down authentication information for kubectl against a cluster, name can be specified through CLUSTER_NAME
(defaults to 'test-cluster')

### `make gcloud-auth-docker`
Creates a short lived access to Google Cloud container repositories, so that you are able to call
`docker push` directly. Useful when used in combination with `make push` command.

0 comments on commit 469443d

Please sign in to comment.