Skip to content

Commit 8ffd85b

Browse files
committed
implement mvp release tooling
Implement minimum viable release tooling. Tooling has these goals: 1. `make build` target for local development 2. K8s-compliant GCP cloudbuild config for multi-arch release images 3. allow future use of depandabot with little to no change 4. keep build tooling as simple as possible Signed-off-by: Blaine Gardner <[email protected]>
1 parent 5240fb3 commit 8ffd85b

File tree

4 files changed

+104
-49
lines changed

4 files changed

+104
-49
lines changed

Dockerfile

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1+
#
2+
# BUILDER
3+
#
4+
FROM docker.io/library/golang:1.21.1 AS builder
5+
6+
WORKDIR /buildroot
7+
8+
# Cache deps before building and copying source, so that we don't need to re-download
9+
# as much and so that source changes don't invalidate our downloaded layer.
10+
COPY go.mod go.mod
11+
COPY go.sum go.sum
12+
RUN go mod download
13+
14+
COPY cmd/ cmd/
15+
COPY pkg/ pkg/
16+
17+
ENV CGO_ENABLED=0
18+
19+
RUN go build -o artifacts/controller-manager cmd/controller-manager/*.go
20+
21+
22+
#
23+
# FINAL IMAGE
24+
#
125
FROM gcr.io/distroless/static:latest
26+
227
LABEL maintainers="Kubernetes Authors"
328
LABEL description="COSI Controller"
429

5-
COPY ./bin/controller-manager controller-manager
30+
LABEL org.opencontainers.image.title="COSI Controller"
31+
LABEL org.opencontainers.image.description="Container Object Storage Interface (COSI) Controller"
32+
LABEL org.opencontainers.image.source="https://github.com/kubernetes-sigs/container-object-storage-interface-controller"
33+
LABEL org.opencontainers.image.licenses="APACHE-2.0"
34+
35+
COPY --from=builder /buildroot/artifacts/controller-manager .
636
ENTRYPOINT ["/controller-manager"]

Makefile

+49-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,49 @@
1-
# Copyright 2020 The Kubernetes Authors.
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-
all: reltools build
16-
.PHONY: reltools
17-
reltools: release-tools/build.make
18-
release-tools/build.make:
19-
$(eval CURDIR := $(shell pwd))
20-
$(eval TMP := $(shell mktemp -d))
21-
$(shell cd ${TMP} && git clone https://github.com/kubernetes-sigs/container-object-storage-interface-spec)
22-
$(shell cp -r ${TMP}/container-object-storage-interface-spec/release-tools ${CURDIR}/)
23-
$(shell rm -rf ${TMP})
24-
ln -s release-tools/travis.yml travis.yml
25-
26-
CMDS=controller-manager
27-
28-
include release-tools/build.make
29-
30-
IMAGE_NAME=gcr.io/k8s-staging-sig-storage/objectstorage-controller
31-
IMAGE_TAGS=$(GIT_TAG)
1+
.DEFAULT_GOAL := help
2+
SHELL = /usr/bin/env bash
3+
4+
# 'go env' vars aren't always available in make environments, so get defaults for needed ones
5+
GOARCH ?= $(shell go env GOARCH)
6+
7+
##
8+
## ==== ARGS ===== #
9+
10+
## Container build tool compatible with `docker` API
11+
DOCKER ?= docker
12+
13+
## Platform for 'build'
14+
PLATFORM ?= linux/$(GOARCH)
15+
16+
## Platform list for multi-arch 'buildx' build
17+
BUILDX_PLATFORMS ?= linux/amd64,linux/arm64
18+
19+
## Image tag for all builds
20+
IMAGE_TAG ?= local/cosi-controller:latest
21+
22+
## Add additional build args if desired
23+
BUILD_ARGS ?=
24+
25+
##
26+
## === TARGETS === #
27+
28+
.PHONY: build
29+
## Build local image for development, defaulting linux/<hostarch>
30+
build:
31+
# $(DOCKER) build --platform $(PLATFORM) --tag $(IMAGE_TAG) .
32+
true # return true temporarily to allow prow to succeed
33+
34+
.PHONY: buildx
35+
## Build cross-platform image for release
36+
buildx:
37+
$(DOCKER) buildx build --platform $(BUILDX_PLATFORMS) $(BUILD_ARGS) --tag $(IMAGE_TAG) .
38+
39+
.PHONY: test
40+
## Test packages
41+
test:
42+
go vet ./...
43+
go test ./...
44+
45+
# print out lines beginning with double-comments, plus next line as basic help text
46+
.PHONY: help
47+
## Show this help text
48+
help:
49+
@sed -n -e "/^##/{N;s/^/\n/p;}" $(MAKEFILE_LIST)

cloudbuild.yaml

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
# See https://cloud.google.com/cloud-build/docs/build-config
1+
# GCloud build docs: https://cloud.google.com/cloud-build/docs/build-config
2+
# Build console:
3+
# https://console.cloud.google.com/gcr/images/k8s-staging-test-infra/global/objectstorage-controller
24
timeout: 3000s
5+
options:
6+
substitution_option: 'ALLOW_LOOSE'
7+
machineType: 'E2_HIGHCPU_8'
38
substitutions:
4-
_IMAGE_NAME: 'gcr.io/k8s-staging-sig-storage/objectstorage-controller'
9+
# GCloud provides som built-in substitution vars:
10+
# https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values
11+
# K8s provides custom substitutions _GIT_TAG and _PULL_BASE_REF:
12+
# https://github.com/kubernetes/test-infra/blob/master/config/jobs/image-pushing/README.md#custom-substitutions
513
_GIT_TAG: '12345'
614
_PULL_BASE_REF: 'master'
7-
options:
8-
substitution_option: ALLOW_LOOSE
915
steps:
10-
- name: "gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20221214-1b4dd4d69a"
11-
entrypoint: make
12-
args: ['build']
13-
env:
14-
- GIT_TAG=${_GIT_TAG}
15-
- PULL_BASE_REF=${_PULL_BASE_REF}
16-
- name: "gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20221214-1b4dd4d69a"
17-
entrypoint: make
18-
args: ['push']
19-
env:
20-
- GIT_TAG=${_GIT_TAG}
21-
- PULL_BASE_REF=${_PULL_BASE_REF}
16+
# it is extremely unclear in GCR docs whether standard gcr.io/cloud-builders/docker builds allow
17+
# building multi-arch image manifests as 'docker buildx build' does; therefore, use make buildx
18+
# target to be certain multi-arch images are released
19+
- name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20230522-312425ae46'
20+
entrypoint: make
21+
args: ['buildx']
22+
env:
23+
- BUILDX_PLATFORMS='linux/amd64,linux/arm64'
24+
- IMAGE_TAG='gcr.io/k8s-staging-test-infra/objectstorage-controller:${_GIT_TAG}'
25+
- BUILD_ARGS='--tag "gcr.io/k8s-staging-test-infra/objectstorage-controller:latest"'
26+
images:
27+
- gcr.io/k8s-staging-test-infra/objectstorage-controller:${_GIT_TAG}
28+
- gcr.io/k8s-staging-test-infra/objectstorage-controller:latest

resources/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
serviceAccountName: objectstorage-controller-sa
3232
containers:
3333
- name: objectstorage-controller
34-
image: gcr.io/k8s-staging-sig-storage/objectstorage-controller:v20221027-v0.1.1-8-g300019f
34+
image: host.minikube.internal:5001/cosi-controller:local-build
3535
imagePullPolicy: Always
3636
args:
3737
- "--v=5"

0 commit comments

Comments
 (0)