From a416de51e05697cd3d97c8a83dcfcee34352c57c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 17 Jul 2024 13:28:42 +0200 Subject: [PATCH 1/2] [no-relnote] Add tooling to update golang using dependabot Signed-off-by: Evan Lezar --- .github/dependabot.yml | 13 +++++++++ .github/workflows/golang.yaml | 50 ++++++++++++++++++++--------------- Makefile | 15 +++++++++-- deployments/devel/Dockerfile | 27 +++++++++++++++++++ deployments/devel/Makefile | 37 ++++++++++++++++++++++++++ deployments/devel/go.mod | 10 +++++++ deployments/devel/go.sum | 10 +++++++ deployments/devel/tools.go | 25 ++++++++++++++++++ hack/golang-version.sh | 22 +++++++++++++++ versions.mk | 4 +-- 10 files changed, 188 insertions(+), 25 deletions(-) create mode 100644 deployments/devel/Dockerfile create mode 100644 deployments/devel/Makefile create mode 100644 deployments/devel/go.mod create mode 100644 deployments/devel/go.sum create mode 100644 deployments/devel/tools.go create mode 100755 hack/golang-version.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2f904f95..bb0913a5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -27,3 +27,16 @@ updates: directory: "/" schedule: interval: "daily" + + - package-ecosystem: "gomod" + target-branch: main + directory: "deployments/devel" + schedule: + interval: "weekly" + day: "sunday" + + - package-ecosystem: "docker" + target-branch: main + directory: "/deployments/devel" + schedule: + interval: "daily" diff --git a/.github/workflows/golang.yaml b/.github/workflows/golang.yaml index 86040145..3cbdd482 100644 --- a/.github/workflows/golang.yaml +++ b/.github/workflows/golang.yaml @@ -36,7 +36,7 @@ jobs: - name: Get Golang version id: vars run: | - GOLANG_VERSION=$( grep "GOLANG_VERSION :=" versions.mk ) + GOLANG_VERSION=$(./hack/golang-version.sh) echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION := }" >> $GITHUB_ENV - name: Install Go uses: actions/setup-go@v5 @@ -51,26 +51,34 @@ jobs: - name: Check golang modules run: make check-vendor test: - name: Unit test - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - 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 test + name: Unit test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$(./hack/golang-version.sh) + 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 test build: + name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - name: Checkout code - - - name: Build - run: make docker-build + - name: Checkout code + uses: actions/checkout@v4 + - name: Get Golang version + id: vars + run: | + GOLANG_VERSION=$(./hack/golang-version.sh) + 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 af5b121e..fdfc16e2 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,17 @@ coverage: test generate: go generate $(MODULE)/... +# Generate an image for containerized builds +# Note: This image is local only +.PHONY: .build-image +.build-image: + make -f deployments/devel/Makefile .build-image + +ifeq ($(BUILD_DEVEL_IMAGE),yes) +$(DOCKER_TARGETS): .build-image +.shell: .build-image +endif + $(DOCKER_TARGETS): docker-%: @echo "Running 'make $(*)' in container image $(BUILDIMAGE)" $(DOCKER) run \ @@ -121,8 +132,8 @@ PHONY: .shell DEPLOYMENT_DIR = deployments/container DEPLOYMENT_TARGETS = ubuntu20.04 ubi8 -BUILD_DEPLOYMENT_TARGETS := $(patsubst %, build-%, $(DEPLOYMENT_TARGETS)) -PUSH_DEPLOYMENT_TARGETS := $(patsubst %, push-%, $(DEPLOYMENT_TARGETS)) +BUILD_DEPLOYMENT_TARGETS := $(patsubst %,build-%,$(DEPLOYMENT_TARGETS)) +PUSH_DEPLOYMENT_TARGETS := $(patsubst %,push-%,$(DEPLOYMENT_TARGETS)) .PHONY: $(DEPLOYMENT_TARGETS) $(BUILD_DEPLOYMENT_TARGETS) $(PUSH_DEPLOYMENT_TARGETS) $(BUILD_DEPLOYMENT_TARGETS): build-%: diff --git a/deployments/devel/Dockerfile b/deployments/devel/Dockerfile new file mode 100644 index 00000000..206bcf2a --- /dev/null +++ b/deployments/devel/Dockerfile @@ -0,0 +1,27 @@ +# 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. + +# This Dockerfile is also used to define the golang version used in this project +# This allows dependabot to manage this version in addition to other images. +FROM golang:1.22.5 + +WORKDIR /work +COPY * . + +RUN make install-tools + +# 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/deployments/devel/Makefile b/deployments/devel/Makefile new file mode 100644 index 00000000..f224db3c --- /dev/null +++ b/deployments/devel/Makefile @@ -0,0 +1,37 @@ +# Copyright 2024 NVIDIA CORPORATION +# +# 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. + +download: + @echo Download go.mod dependencies + @go mod download + +install-tools: download + @echo Installing tools from tools.go + @cat tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install % + + +DOCKER ?= docker +-include $(CURDIR)/versions.mk + +DOCKERFILE_DEVEL = deployments/devel/Dockerfile +DOCKERFILE_CONTEXT = deployments/devel + +.PHONY: .build-image +.build-image: + $(DOCKER) build \ + --progress=plain \ + --build-arg GOLANG_VERSION=$(GOLANG_VERSION) \ + --tag $(BUILDIMAGE) \ + -f $(DOCKERFILE_DEVEL) \ + $(DOCKERFILE_CONTEXT) diff --git a/deployments/devel/go.mod b/deployments/devel/go.mod new file mode 100644 index 00000000..13cb2360 --- /dev/null +++ b/deployments/devel/go.mod @@ -0,0 +1,10 @@ +module devel + +go 1.22 + +require github.com/matryer/moq v0.3.4 + +require ( + golang.org/x/mod v0.14.0 // indirect + golang.org/x/tools v0.17.0 // indirect +) diff --git a/deployments/devel/go.sum b/deployments/devel/go.sum new file mode 100644 index 00000000..7c2fe382 --- /dev/null +++ b/deployments/devel/go.sum @@ -0,0 +1,10 @@ +github.com/matryer/moq v0.3.4 h1:czCFIos9rI2tyOehN9ktc/6bQ76N9J4xQ2n3dk063ac= +github.com/matryer/moq v0.3.4/go.mod h1:wqm9QObyoMuUtH81zFfs3EK6mXEcByy+TjvSROOXJ2U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= diff --git a/deployments/devel/tools.go b/deployments/devel/tools.go new file mode 100644 index 00000000..9ed772bd --- /dev/null +++ b/deployments/devel/tools.go @@ -0,0 +1,25 @@ +//go:build tools +// +build tools + +/** +# Copyright 2024 NVIDIA CORPORATION +# +# 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. +**/ + +package main + +// Define the tooling required to build the device plugin. +import ( + _ "github.com/matryer/moq" +) diff --git a/hack/golang-version.sh b/hack/golang-version.sh new file mode 100755 index 00000000..b655afc6 --- /dev/null +++ b/hack/golang-version.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Copyright 2024 NVIDIA CORPORATION +# +# 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. + +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +DOCKERFILE_ROOT=${SCRIPTS_DIR}/../deployments/devel + +GOLANG_VERSION=$(grep -E "^FROM golang:.*$" ${DOCKERFILE_ROOT}/Dockerfile | grep -oE "[0-9\.]+") + +echo $GOLANG_VERSION diff --git a/versions.mk b/versions.mk index 2cfa0ce8..ed40220b 100644 --- a/versions.mk +++ b/versions.mk @@ -17,10 +17,10 @@ VERSION ?= v0.8.0 vVERSION := v$(VERSION:v%=%) -GOLANG_VERSION := 1.22.5 +GOLANG_VERSION := $(shell ./hack/golang-version.sh) BUILDIMAGE_TAG ?= devel-go$(GOLANG_VERSION) -BUILDIMAGE ?= ghcr.io/nvidia/k8s-test-infra:$(BUILDIMAGE_TAG) +BUILDIMAGE ?= k8s-mig-manager:$(BUILDIMAGE_TAG) GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "") From ff38a4c35e4f52300683ceb2b3332714731987c9 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 17 Jul 2024 13:46:20 +0200 Subject: [PATCH 2/2] [no-relnote] Specify container-toolkit version in Dockerfile Signed-off-by: Evan Lezar --- deployments/devel/Dockerfile | 2 ++ hack/container-toolkit-version.sh | 23 +++++++++++++++++++++++ versions.mk | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 hack/container-toolkit-version.sh diff --git a/deployments/devel/Dockerfile b/deployments/devel/Dockerfile index 206bcf2a..ff78bf7e 100644 --- a/deployments/devel/Dockerfile +++ b/deployments/devel/Dockerfile @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +FROM nvcr.io/nvidia/k8s/container-toolkit:v1.16.0 AS container-toolkit + # This Dockerfile is also used to define the golang version used in this project # This allows dependabot to manage this version in addition to other images. FROM golang:1.22.5 diff --git a/hack/container-toolkit-version.sh b/hack/container-toolkit-version.sh new file mode 100755 index 00000000..fad85fcf --- /dev/null +++ b/hack/container-toolkit-version.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Copyright 2024 NVIDIA CORPORATION +# +# 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. + +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +DOCKERFILE_ROOT=${SCRIPTS_DIR}/../deployments/devel + +COMPONENT=container-toolkit +VERSION=$(grep -E "^FROM .*${COMPONENT}:.*$" ${DOCKERFILE_ROOT}/Dockerfile | sed "s#FROM .*${COMPONENT}:##g" | grep -oE "v?[0-9\.]+" ) + +echo $VERSION diff --git a/versions.mk b/versions.mk index ed40220b..77f10f09 100644 --- a/versions.mk +++ b/versions.mk @@ -24,4 +24,4 @@ BUILDIMAGE ?= k8s-mig-manager:$(BUILDIMAGE_TAG) GIT_COMMIT ?= $(shell git describe --match="" --dirty --long --always --abbrev=40 2> /dev/null || echo "") -NVIDIA_CTK_VERSION := v1.16.0 +NVIDIA_CTK_VERSION := $(shell ./hack/container-toolkit-version.sh)