Skip to content

Commit

Permalink
Makefile add arguments for img building and pushing
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>
  • Loading branch information
ArangoGutierrez committed Feb 22, 2022
1 parent 21194b5 commit 1cedd70
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG BUILDER_IMAGE
ARG BASE_IMAGE
# Build the manager binary
FROM golang:1.17 as builder
FROM ${BUILDER_IMAGE} as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -17,9 +19,7 @@ COPY pkg/ pkg/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
FROM ${BASE_IMAGE}
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
Expand Down
35 changes: 27 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION := $(shell git describe --tags --dirty --always)
# Image URL to use all building/pushing image targets
IMG ?= kueue:latest
IMAGE_BUILD_CMD ?= docker build
IMAGE_PUSH_CMD ?= docker push
IMAGE_BUILD_EXTRA_OPTS ?=
# TODO: Add kueue to k8s gcr registry
IMAGE_REGISTRY ?= gcr.io/k8s-staging-kueue
IMAGE_NAME := kueue
IMAGE_TAG_NAME ?= $(VERSION)
IMAGE_REPO ?= $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_TAG ?= $(IMAGE_REPO):$(IMAGE_TAG_NAME)

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
BASE_IMAGE ?= gcr.io/distroless/static:nonroot
BUILDER_IMAGE ?= golang:1.17

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23

Expand Down Expand Up @@ -105,13 +120,17 @@ build: generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
$(GO_CMD) run ./main.go

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
# Build the container image
.PHONY: image-build
image-build:
$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
$(IMAGE_BUILD_EXTRA_OPTS) ./

.PHONY: image-pushpush
image-push:
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)

##@ Deployment

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ API proposal and a high-level description of how it operates; while [bit.ly/kueu
You can run Kueue with the following command:

```sh
IMG=registry.example.com/kueue:latest make docker-build docker-push deploy
IMAGE_REGISTRY=registry.example.com/<your-account> make image-build image-push deploy
```

The controller will run in the `kueue-system` namespace.
Expand Down

0 comments on commit 1cedd70

Please sign in to comment.