Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 8530cd0

Browse files
committed
Fix image manifest generation
1 parent e142ebd commit 8530cd0

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

Makefile

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.PHONY: vendor test manager clusterctl run install deploy manifests generate fmt vet run
22

3+
GIT_VERSION?=$(shell git log -1 --format="%h")
4+
RELEASE_TAG ?= $(shell git tag --points-at HEAD)
5+
36
# BUILDARCH is the host architecture
47
# ARCH is the target architecture
58
# we need to keep track of them separately
@@ -30,7 +33,9 @@ OS ?= $(BUILDOS)
3033

3134

3235
# Image URL to use all building/pushing image targets
33-
IMG ?= packethost/cluster-api-provider-packet:latest
36+
BUILD_IMAGE ?= packethost/cluster-api-provider-packet
37+
BUILD_IMAGE_TAG ?= $(BUILD_IMAGE):latest
38+
PUSH_IMAGE_TAG ?= $(BUILD_IMAGE):$(IMAGETAG)
3439
PROVIDERYAML ?= provider-components.yaml.template
3540
CLUSTERCTL ?= bin/clusterctl-$(OS)-$(ARCH)
3641
MANAGER ?= bin/manager-$(OS)-$(ARCH)
@@ -45,6 +50,25 @@ vendor:
4550
$(GO) mod vendor
4651
./hack/update-vendor.sh
4752

53+
ci: fmt vet test image
54+
55+
imagetag:
56+
ifndef IMAGETAG
57+
$(error IMAGETAG is undefined - run using make <target> IMAGETAG=X.Y.Z)
58+
endif
59+
60+
tag-image: imagetag
61+
docker tag $(BUILD_IMAGE_TAG) $(PUSH_IMAGE_TAG)
62+
63+
confirm:
64+
ifndef CONFIRM
65+
$(error CONFIRM is undefined - run using make <target> CONFIRM=true)
66+
endif
67+
68+
cd: confirm
69+
$(MAKE) tag-image push IMAGETAG=$(GIT_VERSION)
70+
71+
4872
# Run tests
4973
test: vendor generate fmt vet manifests
5074
$(GO) test -mod=vendor ./pkg/... ./cmd/... -coverprofile cover.out
@@ -75,7 +99,18 @@ deploy: manifests $(CLUSTERCTL)
7599
# Generate manifests e.g. CRD, RBAC etc.
76100
manifests: $(PROVIDERYAML)
77101
$(PROVIDERYAML):
102+
# which image do we patch in? BUILD_IMAGE_TAG or PUSH_IMAGE_TAG? Depends on if it is set
103+
ifdef IMAGETAG
104+
$(eval PATCH_IMAGE_TAG := $(PUSH_IMAGE_TAG))
105+
else
106+
$(eval PATCH_IMAGE_TAG := $(BUILD_IMAGE_TAG))
107+
endif
108+
# generate
78109
$(GO) run -mod=vendor vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all
110+
# patch the particular image tag we will want to deploy
111+
@echo "updating kustomize image patch file for manager resource"
112+
sed -i'' -e 's@PATCH_ME_IMAGE@image: '"$(PATCH_IMAGE_TAG)"'@' ./config/default/manager_image_patch.yaml
113+
# create the manifests
79114
$(KUBECTL) kustomize vendor/sigs.k8s.io/cluster-api/config/default/ > $(PROVIDERYAML)
80115
echo "---" >> $(PROVIDERYAML)
81116
$(KUBECTL) kustomize config/ >> $(PROVIDERYAML)
@@ -97,14 +132,13 @@ endif
97132
$(GO) generate -mod=vendor ./pkg/... ./cmd/...
98133

99134
# Build the docker image
135+
image: docker-build
100136
docker-build: test
101-
docker build . -t ${IMG}
102-
@echo "updating kustomize image patch file for manager resource"
103-
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
137+
docker build -t $(BUILD_IMAGE_TAG) .
104138

105139
# Push the docker image
106-
docker-push:
107-
docker push ${IMG}
140+
push:
141+
docker push $(PUSH_IMAGE_TAG)
108142

109-
image-name:
110-
@echo ${IMG}
143+
image-tag:
144+
@echo $(PUSH_IMAGE_TAG)

config/default/manager_image_patch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ spec:
77
template:
88
spec:
99
containers:
10-
- image: packethost/cluster-api-provider-packet:latest
10+
- image: PATCH_ME_IMAGE
1111
name: manager

0 commit comments

Comments
 (0)