From 1f2a67a2de341dfa6a72f75b32e681be9f4fd00a Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Fri, 8 Mar 2024 15:44:22 +0100 Subject: [PATCH] Enable local selection of dependencies Signed-off-by: Carlos Eduardo Arango Gutierrez --- .github/workflows/golang.yaml | 13 +++++++++--- Makefile | 15 ++++++++++++- deployments/container/Dockerfile.devel | 29 ++++++++++++++++++++++++++ versions.mk | 9 ++++++-- 4 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 deployments/container/Dockerfile.devel diff --git a/.github/workflows/golang.yaml b/.github/workflows/golang.yaml index e58d8865..a7718467 100644 --- a/.github/workflows/golang.yaml +++ b/.github/workflows/golang.yaml @@ -68,6 +68,13 @@ jobs: steps: - uses: actions/checkout@v4 name: Checkout code - - - name: Build - run: make docker-build + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk ) + echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GOLANG_VERSION }} + - run: make build diff --git a/Makefile b/Makefile index a6abee63..6205ec97 100644 --- a/Makefile +++ b/Makefile @@ -30,12 +30,13 @@ CMDS := $(patsubst ./cmd/%/,%,$(sort $(dir $(wildcard ./cmd/*/)))) CMD_TARGETS := $(patsubst %,cmd-%, $(CMDS)) CHECK_TARGETS := golangci-lint -MAKE_TARGETS := binaries build check fmt lint-internal test examples cmds coverage generate vendor check-vendor $(CHECK_TARGETS) +MAKE_TARGETS := binaries build build-image check fmt lint-internal test examples cmds coverage generate vendor check-vendor $(CHECK_TARGETS) TARGETS := $(MAKE_TARGETS) $(CMD_TARGETS) DOCKER_TARGETS := $(patsubst %,docker-%, $(TARGETS)) .PHONY: $(TARGETS) $(DOCKER_TARGETS) +DOCKERFILE_DEVEL := $(CURDIR)/deployments/container/Dockerfile.devel GOOS ?= linux ifeq ($(VERSION),) @@ -139,6 +140,18 @@ generate-clientset: .remove-clientset .remove-deepcopy .remove-crds .remove-clientset: rm -rf $(CURDIR)/$(PKG_BASE)/clientset +build-image: $(DOCKERFILE_DEVEL) + $(DOCKER) build \ + --progress=plain \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --build-arg CLIENT_GEN_VERSION="$(CLIENT_GEN_VERSION)" \ + --build-arg CONTROLLER_GEN_VERSION="$(CONTROLLER_GEN_VERSION)" \ + --build-arg GOLANGCI_LINT_VERSION="$(GOLANGCI_LINT_VERSION)" \ + --build-arg MOQ_VERSION="$(MOQ_VERSION)" \ + --tag $(BUILDIMAGE) \ + -f $(DOCKERFILE_DEVEL) \ + . + $(DOCKER_TARGETS): docker-%: @echo "Running 'make $(*)' in container image $(BUILDIMAGE)" $(DOCKER) run \ diff --git a/deployments/container/Dockerfile.devel b/deployments/container/Dockerfile.devel new file mode 100644 index 00000000..c385aeb6 --- /dev/null +++ b/deployments/container/Dockerfile.devel @@ -0,0 +1,29 @@ +# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +ARG GOLANG_VERSION=x.x.x +FROM golang:${GOLANG_VERSION} + +ARG CLIENT_GEN_VERSION=v0.26.1 +ARG CONTROLLER_GEN_VERSION=v0.9.2 +ARG GOLANGCI_LINT_VERSION=v1.52.0 +ARG MOQ_VERSION=v0.3.4 + +RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} \ + && go install k8s.io/code-generator/cmd/client-gen@${CLIENT_GEN_VERSION} \ + && go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} \ + && go install github.com/matryer/moq@${MOQ_VERSION} \ + +# We need to set the /work directory as a safe directory. +# This allows git commands to run in the container. +RUN git config --file=/.gitconfig --add safe.directory /work diff --git a/versions.mk b/versions.mk index b187aad3..305d5a8a 100644 --- a/versions.mk +++ b/versions.mk @@ -24,7 +24,12 @@ vVERSION := v$(VERSION:v%=%) GOLANG_VERSION ?= 1.20.4 CUDA_VERSION ?= 11.8.0 -BUILDIMAGE_TAG ?= devel-go$(GOLANG_VERSION) -BUILDIMAGE ?= ghcr.io/nvidia/k8s-test-infra:$(BUILDIMAGE_TAG) +CLIENT_GEN_VERSION ?= v0.26.1 +CONTROLLER_GEN_VERSION ?= v0.9.2 +# golangci-lint and moq are only needed when building a local image +GOLANGCI_LINT_VERSION ?= v1.52.0 +MOQ_VERSION ?= v0.3.4 + +BUILDIMAGE ?= ghcr.io/nvidia/k8s-test-infra:devel-go$(GOLANG_VERSION) GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "")