Skip to content

Commit 71c40be

Browse files
authored
Simplify controllers local build system (#509)
3 years ago we added a mechanism to build controllers using local module files for both `ack-generate`, controller binaries and container images. However, those turned out to be very complex to manage and more importantly to maintain... the only use case we've seen over the years is the need to build a controller using a local runtime repository... Now that we want to start running e2e tests against runtime repositories, we need a simplified way to build controller images using the local runtime repository, only! This patch removes all the never-used tooling around `go.local.mod` and keeps `local-build-controller-image` for prow testing purposes. Signed-off-by: Amine Hilaly <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent f429bd9 commit 71c40be

File tree

5 files changed

+12
-1364
lines changed

5 files changed

+12
-1364
lines changed

Dockerfile.local

+9-5
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ ENV VERSION_PKG=github.com/aws-controllers-k8s/$service_alias-controller/pkg/ver
2929
# Copy the Go Modules manifests and LICENSE/ATTRIBUTION
3030
COPY $service_alias-controller/LICENSE $work_dir/LICENSE
3131
COPY $service_alias-controller/ATTRIBUTION.md $work_dir/ATTRIBUTION.md
32-
# use local mod files
33-
COPY $service_alias-controller/go.local.mod $work_dir/go.local.mod
34-
COPY $service_alias-controller/go.local.sum $work_dir/go.local.sum
32+
# Copy the go.mod and go.sum files for the service controller
3533
COPY $service_alias-controller/go.mod $work_dir/go.mod
34+
COPY $service_alias-controller/go.sum $work_dir/go.sum
3635

37-
# for local development, copy local runtime repo
36+
# Copy local runtime code to the container
3837
COPY runtime/pkg $work_dir/../runtime/pkg
3938
COPY runtime/apis $work_dir/../runtime/apis
4039
COPY runtime/go.mod $work_dir/../runtime/go.mod
4140
COPY runtime/go.sum $work_dir/../runtime/go.sum
4241

42+
# Replace the runtime module with the local runtime code
43+
RUN echo "replace github.com/aws-controllers-k8s/runtime => ../runtime" >> $work_dir/go.mod
44+
45+
# TODO: Add a mechanism to inject more replacements for the go.mod file.
46+
# For now we don't have any real use case for this.
47+
4348
# cache deps before building and copying source so that we don't need to re-download as much
4449
# and so that source changes don't invalidate our downloaded layer
4550
WORKDIR $work_dir/../runtime
@@ -58,7 +63,6 @@ RUN GIT_VERSION=$service_controller_git_version && \
5863
go build -ldflags="-X ${VERSION_PKG}.GitVersion=${GIT_VERSION} \
5964
-X ${VERSION_PKG}.GitCommit=${GIT_COMMIT} \
6065
-X ${VERSION_PKG}.BuildDate=${BUILD_DATE}" \
61-
-modfile="${work_dir}/go.local.mod" \
6266
-a -o $work_dir/bin/controller $work_dir/cmd/controller/main.go
6367

6468
FROM $base_image

Makefile

+2-13
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ GO_LDFLAGS=-ldflags "-X $(IMPORT_PATH)/pkg/version.Version=$(VERSION) \
1717
# We need to use the codegen tag when building and testing because the
1818
# aws-sdk-go/private/model/api package is gated behind a build tag "codegen"...
1919
GO_CMD_FLAGS=-tags codegen
20-
GO_CMD_LOCAL_FLAGS=-modfile=go.local.mod $(GO_CMD_FLAGS)
2120

22-
.PHONY: all local-build-ack-generate build-ack-generate local-build-controller \
23-
build-controller test local-test build-controller-image \
21+
.PHONY: all build-ack-generate test \
22+
build-controller build-controller-image \
2423
local-build-controller-image lint-shell
2524

2625
all: test
@@ -30,20 +29,13 @@ build-ack-generate: ## Build ack-generate binary
3029
@go build ${GO_CMD_FLAGS} ${GO_LDFLAGS} -o bin/ack-generate cmd/ack-generate/main.go
3130
@echo "ok."
3231

33-
local-build-ack-generate: ## Build ack-generate binary using the local go.mod
34-
@echo -n "building ack-generate ... "
35-
@go build ${GO_CMD_LOCAL_FLAGS} ${GO_LDFLAGS} -o bin/ack-generate cmd/ack-generate/main.go
36-
@echo "ok."
37-
3832
build-controller: build-ack-generate ## Generate controller code for SERVICE
3933
@./scripts/install-controller-gen.sh
4034
@echo "==== building $(AWS_SERVICE)-controller ===="
4135
@./scripts/build-controller.sh $(AWS_SERVICE)
4236
@echo "==== building $(AWS_SERVICE)-controller release artifacts ===="
4337
@./scripts/build-controller-release.sh $(AWS_SERVICE)
4438

45-
local-build-controller: local-build-ack-generate build-controller ## Generate controller code for SERVICE using the local go.mod
46-
4739
build-controller-image: export LOCAL_MODULES = false
4840
build-controller-image: ## Build container image for SERVICE
4941
@./scripts/build-controller-image.sh $(AWS_SERVICE)
@@ -55,9 +47,6 @@ local-build-controller-image: ## Build container image for SERVICE allowing loca
5547
test: ## Run code tests
5648
go test ${GO_CMD_FLAGS} ./...
5749

58-
local-test: ## Run code tests using the local go.mod
59-
go test ${GO_CMD_LOCAL_FLAGS} ./...
60-
6150
lint-shell: ## Run linters against all of the bash scripts
6251
@find . -type f -name "*.sh" | xargs shellcheck -e SC1091
6352

go.local.mod

-92
This file was deleted.

0 commit comments

Comments
 (0)