Skip to content

Commit d615914

Browse files
authored
Merge pull request #273 from justaugustus/img-build
Add GCB config for image building
2 parents e2abc57 + 2438a34 commit d615914

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

Makefile

+20-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ all: build
1818
-include $(CONFIG)
1919
-include $(CONFIG)-token
2020

21-
DOCKER_REPO ?= k8s-publishing-bot
21+
GIT_TAG ?= $(shell git describe --tags --always --dirty)
22+
23+
# Image variables
24+
IMG_REGISTRY ?= gcr.io/k8s-staging-publishing-bot
25+
IMG_NAME = publishing-bot
26+
27+
IMG_VERSION ?= v0.0.0-1
28+
29+
# TODO(image): Consider renaming this variable
30+
DOCKER_REPO ?= $(IMG_REGISTRY)/$(IMG_NAME)
2231
NAMESPACE ?=
2332
TOKEN ?=
2433
KUBECTL ?= kubectl
@@ -44,12 +53,21 @@ build:
4453
.PHONY: build
4554

4655
build-image: build
47-
docker build -t $(DOCKER_REPO) .
56+
docker build \
57+
-t $(DOCKER_REPO):$(GIT_TAG) \
58+
-t $(DOCKER_REPO):$(IMG_VERSION) \
59+
-t $(DOCKER_REPO):latest \
60+
.
4861
.PHONY: build-image
4962

5063
push-image:
64+
docker push $(DOCKER_REPO):$(GIT_TAG)
65+
docker push $(DOCKER_REPO):$(IMG_VERSION)
5166
docker push $(DOCKER_REPO):latest
5267

68+
build-and-push-image: build-image push-image
69+
.PHONY: build-and-push-image
70+
5371
clean:
5472
rm -rf _output
5573
.PHONY: clean

cloudbuild.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Google Cloud Build configuration: https://cloud.google.com/cloud-build/docs/build-config
2+
# Image building process: https://git.k8s.io/test-infra/config/jobs/image-pushing/README.md
3+
4+
# this must be specified in seconds. If omitted, defaults to 600s (10 mins)
5+
timeout: 1200s
6+
7+
options:
8+
substitution_option: ALLOW_LOOSE
9+
# TODO(image): Consider a smaller machine type
10+
machineType: N1_HIGHCPU_32
11+
12+
steps:
13+
- name: 'gcr.io/k8s-staging-releng/k8s-ci-builder:latest-default'
14+
entrypoint: make
15+
env:
16+
- GIT_TAG=$_GIT_TAG
17+
- PULL_BASE_REF=$_PULL_BASE_REF
18+
- IMG_REGISTRY=gcr.io/$PROJECT_ID
19+
- IMG_VERSION=$_IMG_VERSION
20+
args:
21+
- build-and-push-image
22+
23+
# TODO(image): Consider adding a container structure test
24+
#- name: 'gcr.io/gcp-runtimes/container-structure-test'
25+
# id: structure-test
26+
# args:
27+
# - test
28+
# - --image=gcr.io/$PROJECT_ID/publishing-bot:$_GIT_TAG
29+
# - --config=container-structure.yaml
30+
31+
substitutions:
32+
# _GIT_TAG will be filled with a git-based tag for the image, of the form
33+
# vYYYYMMDD-hash, and can be used as a substitution
34+
_GIT_TAG: '12345'
35+
_PULL_BASE_REF: 'dev'
36+
_IMG_REGISTRY: 'null-registry'
37+
_IMG_VERSION: 'v0.0.0-1'
38+
39+
tags:
40+
- 'publishing-bot'
41+
- ${_GIT_TAG}
42+
- ${_PULL_BASE_REF}
43+
- ${_IMG_REGISTRY}
44+
- ${_IMG_VERSION}
45+
46+
images:
47+
- 'gcr.io/$PROJECT_ID/publishing-bot:$_GIT_TAG'
48+
- 'gcr.io/$PROJECT_ID/publishing-bot:$_IMG_VERSION'
49+
- 'gcr.io/$PROJECT_ID/publishing-bot:latest'

0 commit comments

Comments
 (0)