Make image targets allow for more customization

Customize platform, base image and whether CGO is enabled

Signed-off-by: irbekrm <irbekrm@gmail.com>
This commit is contained in:
irbekrm 2021-06-30 09:55:07 +01:00
parent 1ce499a05d
commit 7405fb4e24

View File

@ -12,9 +12,23 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# STANDARD OPTIONS
###############
# Set DOCKER_REGISTRY to customise the image docker repo, e.g. "quay.io/jetstack" # Set DOCKER_REGISTRY to customise the image docker repo, e.g. "quay.io/jetstack"
DOCKER_REGISTRY := DOCKER_REGISTRY :=
# Set APP_VERSION to customize the image tag, eg "v0.0.5-dev"
APP_VERSION := APP_VERSION :=
# Set the target platform to build for. Defaults to linux/amd64
PLATFORM := @io_bazel_rules_go//go/toolchain:linux_amd64
# OPTIONS YOU PROBABLY DON'T NEED TO MODIFY UNLESS DOING SOMETHING VERY SPECIFIC.
###############
# Set an alternative base image https://github.com/jetstack/cert-manager/blob/master/build/BUILD.bazel#L42
BASE_IMAGE := static
# Set to '' to not disable CGO. Disabled by default.
CGO_DISABLED := --@io_bazel_rules_go//go/config:pure
HACK_DIR ?= hack HACK_DIR ?= hack
# Get a list of all binaries to be built # Get a list of all binaries to be built
@ -49,9 +63,9 @@ help:
# #
# Image targets can be run with optional args DOCKER_REGISTRY and APP_VERSION: # Image targets can be run with optional args DOCKER_REGISTRY and APP_VERSION:
# #
# make images DOCKER_REGISTRY=quay.io/yourusername APP_VERSION=v0.11.0-dev.my-feature # All image targets can be run with optional args DOCKER_REGISTRY, APP_VERSION, PLATFORM
# #
# Images can be pushed with optional args DOCKER_REGISTRY and APP_VERSION: # make images DOCKER_REGISTRY=quay.io/yourusername APP_VERSION=v0.11.0-dev.my-feature PLATFORM=@io_bazel_rules_go//go/toolchain:linux_arm64
# #
# make images_push DOCKER_REGISTRY=quay.io/yourusername APP_VERSION=v0.11.0-dev.my-feature # make images_push DOCKER_REGISTRY=quay.io/yourusername APP_VERSION=v0.11.0-dev.my-feature
@ -110,8 +124,9 @@ images:
DOCKER_REGISTRY=$(DOCKER_REGISTRY) \ DOCKER_REGISTRY=$(DOCKER_REGISTRY) \
bazel run \ bazel run \
--stamp \ --stamp \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \ --platforms=$(PLATFORM) \
--@io_bazel_rules_go//go/config:pure \ --define image_type=$(BASE_IMAGE) \
$(CGO_DISABLED) \
//build:server-images //build:server-images
.PHONY: images_push .PHONY: images_push
@ -120,6 +135,7 @@ images_push:
DOCKER_REGISTRY=$(DOCKER_REGISTRY) \ DOCKER_REGISTRY=$(DOCKER_REGISTRY) \
bazel run \ bazel run \
--stamp \ --stamp \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \ --platforms=$(PLATFORM) \
--@io_bazel_rules_go//go/config:pure \ --define image_type=$(BASE_IMAGE) \
$(CGO_DISABLED) \
//:images.push //:images.push