@@ -13,7 +13,10 @@ IMG_VERSION_OVERRIDE ?= $(IMG_DEFAULT_TAG)
13
13
GOPROXY ?= "https://proxy.golang.org,direct"
14
14
PLATFORM =local
15
15
# check out step 2 in this documentation on how to set the COMPONENTS variable https://github.com/vmware-tanzu/build-tooling-for-integrations/blob/main/docs/build-tooling-getting-started.md
16
- COMPONENTS ?= capabilities/client capabilities/controller.capabilities-controller-manager.capabilities featuregates/client featuregates/controller.featuregates-controller-manager.featuregates
16
+ COMPONENTS ?= capabilities/client \
17
+ capabilities/controller.capabilities-controller-manager.capabilities \
18
+ featuregates/client \
19
+ featuregates/controller.featuregates-controller-manager.featuregates
17
20
18
21
BUILD_TOOLING_CONTAINER_IMAGE ?= ghcr.io/vmware-tanzu/build-tooling
19
22
PACKAGING_CONTAINER_IMAGE ?= ghcr.io/vmware-tanzu/package-tooling
@@ -23,6 +26,9 @@ VERSION ?= v0.0.2
23
26
find_main_go = $(shell find $(1 ) -name main.go)
24
27
check_main_go = $(if $(call find_main_go,$(1 ) ) ,Found,NotFound)
25
28
29
+ # utility function to generate component-specific Dockerfiles
30
+ template_dockerfile = $(shell ./template-dockerfile.sh $(1 ) )
31
+
26
32
# #
27
33
# # Project Initialization Targets
28
34
# #
@@ -99,6 +105,8 @@ package-all: package-bundle-generate-all package-bundle-push-all
99
105
.PHONY : $(COMPONENTS )
100
106
$(COMPONENTS ) :
101
107
$(eval COMPONENT_PATH = $(word 1,$(subst ., ,$@ ) ) )
108
+ @echo " $( call template_dockerfile,$( COMPONENT_PATH) ) "
109
+ $(eval COMPONENT_DOCKERFILE = $(word 1,$(subst /,.,$(COMPONENT_PATH ) ) ) .Dockerfile)
102
110
$(eval IMAGE_NAME = $(word 2,$(subst ., ,$@ ) ) )
103
111
$(eval PACKAGE_PATH = $(word 3,$(subst ., ,$@ ) ) )
104
112
$(eval IMAGE = $(IMAGE_NAME ) :$(IMG_VERSION_OVERRIDE ) )
@@ -111,7 +119,7 @@ $(COMPONENTS):
111
119
$(MAKE ) publish IMAGE=$(IMAGE ) DEFAULT_IMAGE=$(DEFAULT_IMAGE ) PACKAGE_PATH=$(PACKAGE_PATH ) BUILD_BIN=$(BUILD_BIN ) ; \
112
120
fi \
113
121
else \
114
- $(MAKE ) build COMPONENT=$(COMPONENT ) IMAGE_NAME=$(IMAGE_NAME ) IMAGE=$(IMAGE ) PACKAGE_PATH=$(PACKAGE_PATH ) BUILD_BIN=$(BUILD_BIN ) ; \
122
+ $(MAKE ) build COMPONENT=$(COMPONENT ) COMPONENT_DOCKERFILE= $( COMPONENT_DOCKERFILE ) IMAGE_NAME=$(IMAGE_NAME ) IMAGE=$(IMAGE ) PACKAGE_PATH=$(PACKAGE_PATH ) BUILD_BIN=$(BUILD_BIN ) ; \
115
123
fi
116
124
117
125
.PHONY : validate-component
@@ -124,7 +132,7 @@ endif
124
132
125
133
.PHONY : build
126
134
build :
127
- $(MAKE ) COMPONENT=$(COMPONENT ) test
135
+ $(MAKE ) COMPONENT=$(COMPONENT ) COMPONENT_DOCKERFILE= $( COMPONENT_DOCKERFILE ) test
128
136
@if [ " $( call check_main_go,$( COMPONENT) ) " = " Found" ]; then \
129
137
if [ " $( BUILD_BIN) " = " true" ]; then \
130
138
$(MAKE ) COMPONENT=$(COMPONENT ) binary-build; \
@@ -144,37 +152,37 @@ publish:
144
152
lint :
145
153
ifneq ($(strip $(COMPONENT ) ) ,.)
146
154
cp .golangci.yaml $(COMPONENT)
147
- $(DOCKER) build . -f Dockerfile --target lint --build-arg COMPONENT=$(COMPONENT) --build-arg GOPROXY_ARG=$(GOPROXY)
155
+ $(DOCKER) build . -f $(COMPONENT_DOCKERFILE) --target lint --build-arg COMPONENT=$(COMPONENT) --build-arg GOPROXY_ARG=$(GOPROXY)
148
156
rm -rf $(COMPONENT)/.golangci.yaml
149
157
else
150
- $(DOCKER) build . -f Dockerfile --target lint --build-arg COMPONENT=$(COMPONENT) --build-arg GOPROXY_ARG=$(GOPROXY)
158
+ $(DOCKER) build . -f $(COMPONENT_DOCKERFILE) --target lint --build-arg COMPONENT=$(COMPONENT) --build-arg GOPROXY_ARG=$(GOPROXY)
151
159
endif
152
160
153
161
.PHONY : fmt
154
162
# Run go fmt against code
155
163
fmt :
156
- $(DOCKER ) build . -f Dockerfile --target fmt --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
164
+ $(DOCKER ) build . -f $( COMPONENT_DOCKERFILE ) --target fmt --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
157
165
158
166
.PHONY : vet
159
167
# Perform static analysis of code
160
168
vet :
161
- $(DOCKER ) build . -f Dockerfile --target vet --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
169
+ $(DOCKER ) build . -f $( COMPONENT_DOCKERFILE ) --target vet --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
162
170
163
171
.PHONY : test
164
172
# Run tests
165
173
test : fmt vet
166
- $(DOCKER ) build . -f Dockerfile --target test --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
167
- @$(DOCKER ) build . -f Dockerfile --target unit-test-coverage --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY ) --output build/$(COMPONENT ) /coverage
174
+ $(DOCKER ) build . -f $( COMPONENT_DOCKERFILE ) --target test --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
175
+ @$(DOCKER ) build . -f $( COMPONENT_DOCKERFILE ) --target unit-test-coverage --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY ) --output build/$(COMPONENT ) /coverage
168
176
169
177
.PHONY : binary-build
170
178
# Build the binary
171
179
binary-build :
172
- $(DOCKER ) build . -f Dockerfile --build-arg LD_FLAGS=" $( LD_FLAGS) " --target bin --output build/$(COMPONENT ) /bin --platform ${PLATFORM} --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
180
+ $(DOCKER ) build . -f $( COMPONENT_DOCKERFILE ) --build-arg LD_FLAGS=" $( LD_FLAGS) " --target bin --output build/$(COMPONENT ) /bin --platform ${PLATFORM} --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
173
181
174
182
.PHONY : docker-build
175
183
# Build docker image
176
184
docker-build :
177
- $(DOCKER ) build . -t $(IMAGE ) -f Dockerfile --target image --platform linux/amd64 --build-arg LD_FLAGS=" $( LD_FLAGS) " --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
185
+ $(DOCKER ) build . -t $(IMAGE ) -f $( COMPONENT_DOCKERFILE ) --target image --platform linux/amd64 --build-arg LD_FLAGS=" $( LD_FLAGS) " --build-arg COMPONENT=$(COMPONENT ) --build-arg GOPROXY_ARG=$(GOPROXY )
178
186
179
187
.PHONY : docker-publish
180
188
# Publish docker image
0 commit comments