diff --git a/Dockerfile b/Dockerfile index 3bb8a48..04e6d9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,15 +4,20 @@ FROM golang:${GOLANG_VERSION} as builder WORKDIR /workspace # Copy the Go Modules manifests -COPY go.* /workspace/odh-project-controller/ +COPY go.* /workspace/ # cache deps before building and copying source so that we don't need to re-download as much # and so that source changes don't invalidate our downloaded layer -RUN cd /workspace/odh-project-controller && go mod download +RUN go mod download -COPY . /workspace/odh-project-controller +# Ensure we have tools installed in the separate layer, +# so we don't have to re-run every time when there is just a code change +COPY func.mk . +COPY Makefile . +RUN make tools -WORKDIR /workspace/odh-project-controller +# Copy the rest of the project +COPY . /workspace/ # Allows to pass other targets, such as go-build. # go-build simply compiles the binary assuming all the prerequisites are provided. @@ -24,5 +29,5 @@ RUN make $BUILD_TARGET -e LDFLAGS="$LDFLAGS" FROM registry.access.redhat.com/ubi8/ubi-minimal:8.9 WORKDIR / -COPY --from=builder /workspace/odh-project-controller/bin/manager . +COPY --from=builder /workspace/bin/manager . ENTRYPOINT ["/manager"] diff --git a/Makefile b/Makefile index 12b2e9b..eac4b82 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,6 @@ generate: tools ## Generates required resources for the controller to work prope SRC_DIRS:=./controllers ./test SRCS:=$(shell find ${SRC_DIRS} -name "*.go") -.PHONY: format -format: $(SRCS) ## Removes unneeded imports and formats source code - $(call header,"Formatting code") - $(LOCALBIN)/goimports -l -w -e $(SRC_DIRS) $(TEST_DIRS) - .PHONY: lint lint: tools ## Concurrently runs a whole bunch of static analysis tools $(call header,"Running a whole bunch of static analysis tools") @@ -75,16 +70,12 @@ deps: go mod download && go mod tidy .PHONY: build -build: tools format generate go-build ## Build manager binary. +build: lint test go-build ## Build manager binary. .PHONY: go-build go-build: ${GOBUILD} go build -ldflags "${LDFLAGS}" -o bin/manager main.go -.PHONY: run -run: format generate ## Run a controller from your host. - go run ./main.go - ##@ Container images # Prefer to use podman if not explicitly set CONTAINER_ENGINE ?= docker @@ -106,9 +97,7 @@ image-build: ## Build container image .PHONY: image-push image-push: ## Push container image - ${CONTAINER_ENGINE} tag ${IMG}:${TAG} ${IMG}:latest ${CONTAINER_ENGINE} push ${IMG}:${TAG} - ${CONTAINER_ENGINE} push ${IMG}:latest .PHONY: image image: image-build image-push ## Build and push docker image with the manager. @@ -133,7 +122,6 @@ LOCALBIN ?= $(shell pwd)/bin $(shell mkdir -p $(LOCALBIN)) .PHONY: tools -tools: deps tools: $(LOCALBIN)/controller-gen $(LOCALBIN)/kustomize ## Installs required tools in local ./bin folder tools: $(LOCALBIN)/setup-envtest $(LOCALBIN)/ginkgo tools: $(LOCALBIN)/goimports $(LOCALBIN)/golangci-lint