Skip to content

Commit a3e57c2

Browse files
authored
Merge pull request #5 from ykulazhenkov/pr-maintenance
Repo maintenance
2 parents 16ed235 + 32fe554 commit a3e57c2

File tree

12 files changed

+397
-452
lines changed

12 files changed

+397
-452
lines changed

.github/dependabot.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: 2
2+
updates:
3+
# Docker images
4+
- package-ecosystem: "docker"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"
8+
commit-message:
9+
prefix: "chore:"
10+
11+
# GitHub Actions
12+
- package-ecosystem: "github-actions"
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
day: "monday"
17+
commit-message:
18+
prefix: "chore:"
19+
20+
- package-ecosystem: "gomod"
21+
directory: "/"
22+
schedule:
23+
interval: "weekly"
24+
day: "tuesday"
25+
groups:
26+
kubernetes:
27+
patterns: [ "k8s.io/*" ]
28+
ignore:
29+
# Ignore controller-runtime, and Kubernetes major and minor updates. These should be done manually.
30+
- dependency-name: "sigs.k8s.io/controller-runtime"
31+
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
32+
- dependency-name: "k8s.io/*"
33+
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
34+
commit-message:
35+
prefix: "chore:"

.github/workflows/build-test-lint.yaml

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,74 @@ name: "Build, Test, Lint"
22
on: [push, pull_request]
33
jobs:
44
build:
5-
strategy:
6-
matrix:
7-
go-version: [1.20.x]
8-
goarch: [amd64]
9-
os: [ubuntu-latest]
10-
runs-on: ${{ matrix.os }}
5+
runs-on: ubuntu-latest
116
steps:
127
- name: Set up Go matrix
13-
uses: actions/setup-go@v4
8+
uses: actions/setup-go@v5
149
with:
15-
go-version: ${{ matrix.go-version }}
10+
go-version: 1.23.x
1611
- name: Check out code into the Go module directory
17-
uses: actions/checkout@v3
18-
- name: Install Task
19-
uses: arduino/setup-task@v1
20-
with:
21-
version: 3.x
22-
repo-token: ${{ secrets.GITHUB_TOKEN }}
12+
uses: actions/checkout@v4
2313
- name: Build
24-
env:
25-
GOARCH: ${{ matrix.goarch }}
26-
GOOS: ${{ matrix.goos }}
27-
run: task build
14+
run: make build
2815
lint:
2916
runs-on: ubuntu-latest
3017
needs: build
3118
steps:
3219
- name: Set up Go
33-
uses: actions/setup-go@v4
20+
uses: actions/setup-go@v5
3421
with:
35-
go-version: 1.20.x
22+
go-version: 1.23.x
3623
- name: Check out code into the Go module directory
37-
uses: actions/checkout@v3
38-
- name: Install Task
39-
uses: arduino/setup-task@v1
40-
with:
41-
version: 3.x
42-
repo-token: ${{ secrets.GITHUB_TOKEN }}
24+
uses: actions/checkout@v4
4325
- name: Lint
44-
run: task lint
26+
run: make lint
4527
test:
4628
runs-on: ubuntu-latest
4729
needs: build
4830
steps:
4931
- name: Set up Go
50-
uses: actions/setup-go@v4
32+
uses: actions/setup-go@v5
5133
with:
52-
go-version: 1.20.x
34+
go-version: 1.23.x
5335
- name: Check out code into the Go module directory
54-
uses: actions/checkout@v3
55-
- name: Install Task
56-
uses: arduino/setup-task@v1
57-
with:
58-
version: 3.x
59-
repo-token: ${{ secrets.GITHUB_TOKEN }}
36+
uses: actions/checkout@v4
6037
- name: Run tests
61-
run: task test
38+
run: make unit-test
6239
build-image:
6340
runs-on: ubuntu-latest
6441
steps:
6542
- name: Check out code into the Go module directory
66-
uses: actions/checkout@v3
43+
uses: actions/checkout@v4
6744
with:
6845
fetch-depth: 0
69-
- name: Install Task
70-
uses: arduino/setup-task@v1
71-
with:
72-
version: 3.x
73-
repo-token: ${{ secrets.GITHUB_TOKEN }}
7446
- name: Build image
75-
run: task image:build
47+
run: make docker-build
7648
go-check:
7749
runs-on: ubuntu-latest
7850
needs: build
7951
steps:
80-
- uses: actions/checkout@v3
52+
- uses: actions/checkout@v4
8153
- name: Set up Go
82-
uses: actions/setup-go@v4
54+
uses: actions/setup-go@v5
8355
with:
84-
go-version: 1.20.x
56+
go-version: 1.23.x
8557
# if this fails, run go mod tidy
8658
- name: Check if module files are consistent with code
8759
run: go mod tidy && git diff --exit-code
8860
coverage:
8961
runs-on: ubuntu-latest
9062
needs: build
9163
steps:
92-
- uses: actions/checkout@v3
64+
- uses: actions/checkout@v4
9365
- name: Set up Go
94-
uses: actions/setup-go@v4
95-
with:
96-
go-version: 1.20.x
97-
- name: Install Task
98-
uses: arduino/setup-task@v1
66+
uses: actions/setup-go@v5
9967
with:
100-
version: 3.x
101-
repo-token: ${{ secrets.GITHUB_TOKEN }}
68+
go-version: 1.23.x
10269
- name: Generate coverage report
103-
run: task test
70+
run: make unit-test
10471
- name: Upload to Coveralls
10572
uses: coverallsapp/github-action@v2
10673
with:
10774
github-token: ${{ secrets.GITHUB_TOKEN }}
108-
file: network-operator-init-container.cover
75+
file: cover.out

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the image
2-
FROM golang:1.20 as builder
2+
FROM golang:1.23 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests
@@ -8,18 +8,16 @@ COPY go.sum go.sum
88
# cache deps before building and copying source so that we don't need to re-download as much
99
# and so that source changes don't invalidate our downloaded layer
1010
RUN go mod download
11-
RUN go install github.com/go-task/task/v3/cmd/[email protected]
12-
1311

1412
# Copy the go source
1513
COPY . /workspace
1614

1715
# Build with make to apply all build logic defined in Makefile
18-
RUN task build
16+
RUN make build
1917

2018
# Use distroless as minimal base image to package the manager binary
2119
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22-
FROM gcr.io/distroless/static-debian11:latest
20+
FROM gcr.io/distroless/static:nonroot
2321
WORKDIR /
2422
COPY --from=builder /workspace/build/network-operator-init-container .
2523

Makefile

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Version information
2+
include Makefile.version
3+
4+
SHELL = /usr/bin/env bash -o pipefail
5+
.SHELLFLAGS = -ec
6+
7+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
8+
BUILD_DIR := ${PROJECT_DIR}/build
9+
10+
REGISTRY ?= ghcr.io/mellanox
11+
IMAGE_TAG_BASE ?= $(REGISTRY)/network-operator-init-container
12+
IMAGE_TAG ?= latest
13+
14+
# Image URL to use all building/pushing image targets
15+
IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG)
16+
DOCKERFILE ?= Dockerfile
17+
18+
# which container engine to use for image build/push
19+
DOCKER_CMD ?= docker
20+
21+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
22+
ENVTEST_K8S_VERSION = 1.31.0
23+
24+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
25+
ifeq (,$(shell go env GOBIN))
26+
GOBIN=$(shell go env GOPATH)/bin
27+
else
28+
GOBIN=$(shell go env GOBIN)
29+
endif
30+
31+
TARGET_OS ?= $(shell go env GOOS)
32+
TARGET_ARCH ?= $(shell go env GOARCH)
33+
34+
# Options for go build command
35+
GO_BUILD_OPTS ?= CGO_ENABLED=0 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH)
36+
# Linker flags for go build command
37+
GO_LDFLAGS = $(VERSION_LDFLAGS)
38+
39+
40+
PKGS = $(or $(PKG),$(shell cd $(PROJECT_DIR) && go list ./...))
41+
42+
.PHONY: all
43+
all: build
44+
45+
##@ General
46+
47+
# The help target prints out all targets with their descriptions organized
48+
# beneath their categories. The categories are represented by '##@' and the
49+
# target descriptions by '##'. The awk commands is responsible for reading the
50+
# entire set of makefiles included in this invocation, looking for lines of the
51+
# file as xyz: ## something, and then pretty-format the target and help. Then,
52+
# if there's a line with ##@ something, that gets pretty-printed as a category.
53+
# More info on the usage of ANSI control characters for terminal formatting:
54+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
55+
# More info on the awk command:
56+
# http://linuxcommand.org/lc3_adv_awk.php
57+
58+
.PHONY: help
59+
help: ## Display this help.
60+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
61+
62+
.PHONY: clean
63+
clean: ## Remove downloaded tools and compiled binaries
64+
@rm -rf $(LOCALBIN)
65+
@rm -rf $(BUILD_DIR)
66+
67+
##@ Development
68+
69+
.PHONY: lint
70+
lint: golangci-lint ## Lint code.
71+
$(GOLANGCILINT) run --timeout 10m
72+
73+
COVERAGE_MODE = atomic
74+
COVER_PROFILE = $(PROJECT_DIR)/cover.out
75+
76+
.PHONY: unit-test
77+
unit-test: envtest ## Run tests.
78+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -covermode=$(COVERAGE_MODE) -coverprofile=$(COVER_PROFILE) $(PKGS)
79+
80+
.PHONY: test
81+
test: lint unit-test
82+
83+
##@ Build
84+
85+
.PHONY: build
86+
build: ## Build binary
87+
$(GO_BUILD_OPTS) go build -ldflags $(GO_LDFLAGS) -o $(BUILD_DIR)/network-operator-init-container ./cmd/network-operator-init-container/main.go
88+
89+
.PHONY: docker-build
90+
docker-build: ## Build docker image with ipam binaries
91+
$(DOCKER_CMD) build -t $(IMG) -f $(DOCKERFILE) .
92+
93+
.PHONY: docker-push
94+
docker-push: ## Push docker image with ipam binaries
95+
$(DOCKER_CMD) push $(IMG)
96+
97+
## Location to install dependencies to
98+
LOCALBIN ?= $(PROJECT_DIR)/bin
99+
$(LOCALBIN):
100+
mkdir -p $(LOCALBIN)
101+
102+
##@ Tools
103+
104+
## Tool Binaries
105+
ENVTEST ?= $(LOCALBIN)/setup-envtest
106+
GOLANGCILINT ?= $(LOCALBIN)/golangci-lint
107+
108+
## Tool Versions
109+
GOLANGCILINT_VERSION ?= v1.63.4
110+
111+
.PHONY: envtest
112+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
113+
$(ENVTEST): | $(LOCALBIN)
114+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
115+
116+
.PHONY: golangci-lint
117+
golangci-lint: $(GOLANGCILINT) ## Download golangci-lint locally if necessary.
118+
$(GOLANGCILINT): | $(LOCALBIN)
119+
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)

Makefile.version

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# version information
2+
DATE = $(shell date -u --iso-8601=seconds)
3+
VERSION ?=
4+
GIT_TREE_STATE = ""
5+
GIT_TAG = ""
6+
GIT_TAG_LAST = ""
7+
RELEASE_STATUS = ""
8+
9+
NO_GIT = $(shell git version > /dev/null 2>&1 || echo true)
10+
ifeq (,$(NO_GIT))
11+
# get last commit ID
12+
COMMIT = $(shell git rev-parse --verify HEAD)
13+
# Tree state is "dirty" if there are uncommitted changes, untracked files are ignored
14+
GIT_TREE_STATE = $(shell test -n "`git status --porcelain --untracked-files=no`" && echo "dirty" || echo "clean")
15+
# Empty string if we are not building a tag
16+
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null || true)
17+
# Find most recent tag
18+
GIT_TAG_LAST = $(shell git describe --tags --abbrev=0 2>/dev/null || true)
19+
endif
20+
21+
# VERSION override mechanism if needed
22+
ifneq (,$(VERSION))
23+
RELEASE_STATUS = ",released"
24+
endif
25+
26+
ifneq (,$(GIT_TAG))
27+
RELEASE_STATUS = ",released"
28+
endif
29+
30+
ifeq (,$(VERSION))
31+
VERSION = $(GIT_TAG_LAST)
32+
endif
33+
34+
# Add version/commit/date to linker flags
35+
VERSION_LDFLAGS = "-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.version=${VERSION} \
36+
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.commit=${COMMIT} \
37+
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.gitTreeState=${GIT_TREE_STATE} \
38+
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.releaseStatus=${RELEASE_STATUS} \
39+
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.date=${DATE}"

0 commit comments

Comments
 (0)