Skip to content

Commit

Permalink
Merge pull request #138 from nckturner/build-release
Browse files Browse the repository at this point in the history
Makefile target to build and push image for release
  • Loading branch information
k8s-ci-robot authored Nov 13, 2020
2 parents 989c224 + 8827c3c commit 1be8de7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
52 changes: 39 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 The Kubernetes Authors.
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,34 +12,60 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Set by cloudbuild (see cloudbuild.yaml)
# TAG will contain a tag of the form vYYYYMMDD-hash, vYYYYMMDD-tag, or vYYYYMMDD-tag-n-ghash,
# depending on the git tags on your repo. The test-infra docs recommend using $_GIT_TAG
# to tag our images.
# PULL_BASE_REF will contain the base ref that was pushed to - for instance, master or
# release-0.2 for a PR merge, or v0.2 for a tag.

SOURCES := $(shell find . -name '*.go')
GOOS ?= $(shell go env GOOS)
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
LDFLAGS := "-w -s -X 'main.version=${VERSION}'"
GOPROXY ?=
GIT_VERSION := $(shell git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
LDFLAGS := "-w -s -X 'main.version=$(GIT_VERSION)'"
ifneq ($(GOPROXY),)
GOPROXYFLAG := --build-arg GOPROXY=$(GOPROXY)
endif

IMAGE ?= gcr.io/k8s-staging-provider-aws/cloud-controller-manager:$(VERSION)
# Registry and image name
STAGING_REGISTRY := gcr.io/k8s-staging-provider-aws
REGISTRY ?= $(STAGING_REGISTRY)
IMAGE_NAME ?= cloud-controller-manager

# tags
ifneq ($(TAG),)
DEV_TAG = $(TAG)
else
DEV_TAG = $(GIT_VERSION)
endif
IMAGE ?= $(REGISTRY)/$(IMAGE_NAME):$(DEV_TAG)

export GO111MODULE=on
RELEASE_TAG := $(shell git describe --abbrev=0 2>/dev/null)
RELEASE_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME):$(RELEASE_TAG)

aws-cloud-controller-manager: $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build \
CGO111MODULE=on GO_ENABLED=0 GOOS=$(GOOS) go build \
-ldflags $(LDFLAGS) \
-o aws-cloud-controller-manager \
cmd/aws-cloud-controller-manager/main.go

.PHONY: build
build:
docker build $(GOPROXYFLAG) -t $(IMAGE) .
.PHONY: docker-build
docker-build:
docker build --build-arg LDFLAGS=$(LDFLAGS) $(GOPROXYFLAG) -t $(IMAGE) .

.PHONY: push
push: build
.PHONY: docker-push
docker-push:
docker push $(IMAGE)

.PHONY: release-tag
release-tag:
gcloud container images add-tag -q $(IMAGE) $(RELEASE_IMAGE)

.PHONY: release-staging
release-staging:
$(MAKE) docker-build docker-push release-tag

.PHONY: check
check: verify-fmt verify-lint vet

Expand Down
19 changes: 19 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://cloud.google.com/cloud-build/docs/build-config
timeout: 3000s
options:
substitution_option: ALLOW_LOOSE
steps:
# 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20200824-5d057db'
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud@sha256:e9d6b4ff5ef9f7d89fa3dac20b6493ae7cdd1ad44b7c08a762aa7c228d17751c'
entrypoint: make
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
- TAG=$_GIT_TAG
- PULL_BASE_REF=$_PULL_BASE_REF
args:
- release-staging
substitutions:
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
# can be used as a substitution
_GIT_TAG: '12345'
_PULL_BASE_REF: 'dev'

0 comments on commit 1be8de7

Please sign in to comment.