Skip to content

Commit

Permalink
chore: simplifies build
Browse files Browse the repository at this point in the history
- removes obsolete format make target
- layers container build so that both deps and tools are cached
  • Loading branch information
bartoszmajsak committed Dec 5, 2023
1 parent d458bf5 commit af3d593
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"]
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit af3d593

Please sign in to comment.