Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2
updates:
# Docker images
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: "chore:"

# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
commit-message:
prefix: "chore:"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
day: "tuesday"
groups:
kubernetes:
patterns: [ "k8s.io/*" ]
ignore:
# Ignore controller-runtime, and Kubernetes major and minor updates. These should be done manually.
- dependency-name: "sigs.k8s.io/controller-runtime"
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
- dependency-name: "k8s.io/*"
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
commit-message:
prefix: "chore:"
79 changes: 23 additions & 56 deletions .github/workflows/build-test-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,74 @@ name: "Build, Test, Lint"
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
go-version: [1.20.x]
goarch: [amd64]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Set up Go matrix
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version: 1.23.x
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
uses: actions/checkout@v4
- name: Build
env:
GOARCH: ${{ matrix.goarch }}
GOOS: ${{ matrix.goos }}
run: task build
run: make build
lint:
runs-on: ubuntu-latest
needs: build
steps:
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.23.x
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
uses: actions/checkout@v4
- name: Lint
run: task lint
run: make lint
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.23.x
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
uses: actions/checkout@v4
- name: Run tests
run: task test
run: make unit-test
build-image:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
run: task image:build
run: make docker-build
go-check:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.23.x
# if this fails, run go mod tidy
- name: Check if module files are consistent with code
run: go mod tidy && git diff --exit-code
coverage:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove coverage ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restored

runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Install Task
uses: arduino/setup-task@v1
uses: actions/setup-go@v5
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
go-version: 1.23.x
- name: Generate coverage report
run: task test
run: make unit-test
- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: network-operator-init-container.cover
file: cover.out
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the image
FROM golang:1.20 as builder
FROM golang:1.23 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -8,18 +8,16 @@ COPY go.sum go.sum
# 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 go mod download
RUN go install github.com/go-task/task/v3/cmd/[email protected]


# Copy the go source
COPY . /workspace

# Build with make to apply all build logic defined in Makefile
RUN task build
RUN make build

# 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-debian11:latest
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/build/network-operator-init-container .

Expand Down
119 changes: 119 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Version information
include Makefile.version

SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
BUILD_DIR := ${PROJECT_DIR}/build

REGISTRY ?= ghcr.io/mellanox
IMAGE_TAG_BASE ?= $(REGISTRY)/network-operator-init-container
IMAGE_TAG ?= latest

# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG)
DOCKERFILE ?= Dockerfile

# which container engine to use for image build/push
DOCKER_CMD ?= docker

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

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

TARGET_OS ?= $(shell go env GOOS)
TARGET_ARCH ?= $(shell go env GOARCH)

# Options for go build command
GO_BUILD_OPTS ?= CGO_ENABLED=0 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH)
# Linker flags for go build command
GO_LDFLAGS = $(VERSION_LDFLAGS)


PKGS = $(or $(PKG),$(shell cd $(PROJECT_DIR) && go list ./...))

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@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)

.PHONY: clean
clean: ## Remove downloaded tools and compiled binaries
@rm -rf $(LOCALBIN)
@rm -rf $(BUILD_DIR)

##@ Development

.PHONY: lint
lint: golangci-lint ## Lint code.
$(GOLANGCILINT) run --timeout 10m

COVERAGE_MODE = atomic
COVER_PROFILE = $(PROJECT_DIR)/cover.out

.PHONY: unit-test
unit-test: envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -covermode=$(COVERAGE_MODE) -coverprofile=$(COVER_PROFILE) $(PKGS)

.PHONY: test
test: lint unit-test

##@ Build

.PHONY: build
build: ## Build binary
$(GO_BUILD_OPTS) go build -ldflags $(GO_LDFLAGS) -o $(BUILD_DIR)/network-operator-init-container ./cmd/network-operator-init-container/main.go

.PHONY: docker-build
docker-build: ## Build docker image with ipam binaries
$(DOCKER_CMD) build -t $(IMG) -f $(DOCKERFILE) .

.PHONY: docker-push
docker-push: ## Push docker image with ipam binaries
$(DOCKER_CMD) push $(IMG)

## Location to install dependencies to
LOCALBIN ?= $(PROJECT_DIR)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

##@ Tools

## Tool Binaries
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCILINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
GOLANGCILINT_VERSION ?= v1.63.4

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): | $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: golangci-lint
golangci-lint: $(GOLANGCILINT) ## Download golangci-lint locally if necessary.
$(GOLANGCILINT): | $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
39 changes: 39 additions & 0 deletions Makefile.version
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# version information
DATE = $(shell date -u --iso-8601=seconds)
VERSION ?=
GIT_TREE_STATE = ""
GIT_TAG = ""
GIT_TAG_LAST = ""
RELEASE_STATUS = ""

NO_GIT = $(shell git version > /dev/null 2>&1 || echo true)
ifeq (,$(NO_GIT))
# get last commit ID
COMMIT = $(shell git rev-parse --verify HEAD)
# Tree state is "dirty" if there are uncommitted changes, untracked files are ignored
GIT_TREE_STATE = $(shell test -n "`git status --porcelain --untracked-files=no`" && echo "dirty" || echo "clean")
# Empty string if we are not building a tag
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null || true)
# Find most recent tag
GIT_TAG_LAST = $(shell git describe --tags --abbrev=0 2>/dev/null || true)
endif

# VERSION override mechanism if needed
ifneq (,$(VERSION))
RELEASE_STATUS = ",released"
endif

ifneq (,$(GIT_TAG))
RELEASE_STATUS = ",released"
endif

ifeq (,$(VERSION))
VERSION = $(GIT_TAG_LAST)
endif

# Add version/commit/date to linker flags
VERSION_LDFLAGS = "-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.version=${VERSION} \
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.commit=${COMMIT} \
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.gitTreeState=${GIT_TREE_STATE} \
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.releaseStatus=${RELEASE_STATUS} \
-X github.com/Mellanox/network-operator-init-container/pkg/utils/version/version.date=${DATE}"
Loading
Loading