-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from almaslennikov/housekeeping
Housekeeping in the ib-kubernetes
- Loading branch information
Showing
9 changed files
with
736 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: build-images | ||
on: [pull_request] | ||
jobs: | ||
build-images: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set repository as lower-case output variable | ||
id: repo_name | ||
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build container image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: false | ||
tags: ghcr.io/${{ steps.repo_name.outputs.repository }}:latest-amd64 | ||
file: ./Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
on: [push, pull_request] | ||
name: build | ||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
go-version: [1.19.x] | ||
goarch: [amd64] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Build | ||
env: | ||
GOARCH: ${{ matrix.goarch }} | ||
run: make build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: push-main | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build-push-amd64: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set repository as lower-case output variable | ||
id: repo_name | ||
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Docker meta | ||
id: docker_meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ghcr.io/${{ steps.repo_name.outputs.repository }} | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Push to GitHub Container Registry | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: true | ||
tags: | | ||
ghcr.io/${{ steps.repo_name.outputs.repository }}:latest-amd64 | ||
labels: ${{ steps.docker_meta.outputs.labels }} | ||
file: ./Dockerfile | ||
|
||
create-push-manifest: | ||
needs: [build-push-amd64] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set repository as lower-case output variable | ||
id: repo_name | ||
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create manifest for multi-arch images | ||
env: | ||
REPOSITORY: ghcr.io/${{ steps.repo_name.outputs.repository }} | ||
run: | | ||
# Get artifacts from previous steps | ||
docker pull ${{ env.REPOSITORY }}:latest-amd64 | ||
# Create and update manifest | ||
docker manifest create ${{ env.REPOSITORY }}:latest ${{ env.REPOSITORY }}:latest-amd64 | ||
docker manifest annotate ${{ env.REPOSITORY }}:latest ${{ env.REPOSITORY }}:latest-amd64 --arch amd64 | ||
# Push manifest | ||
docker manifest push ${{ env.REPOSITORY }}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: Image push release | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
jobs: | ||
build-push-amd64: | ||
name: Image push/amd64 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set repository as lower-case output variable | ||
id: repo_name | ||
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker meta | ||
id: docker_meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ghcr.io/${{ steps.repo_name.outputs.repository }} | ||
flavor: | | ||
latest=false | ||
- name: Push container image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
push: true | ||
tags: | | ||
ghcr.io/${{ steps.repo_name.outputs.repository }}:stable-amd64 | ||
${{ steps.docker_meta.outputs.tags }}-amd64 | ||
labels: ${{ steps.docker_meta.outputs.labels }} | ||
file: ./Dockerfile | ||
|
||
create-push-manifest: | ||
needs: [build-push-amd64] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set repository as lower-case output variable | ||
id: repo_name | ||
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Docker meta | ||
id: docker_meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ghcr.io/${{ steps.repo_name.outputs.repository }} | ||
flavor: | | ||
latest=false | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create manifest for multi-arch images | ||
env: | ||
REPOSITORY: ghcr.io/${{ steps.repo_name.outputs.repository }} | ||
run: | | ||
# Get artifacts from previous steps | ||
docker pull ${{ steps.docker_meta.outputs.tags }}-amd64 | ||
docker pull ${{ env.REPOSITORY }}:stable-amd64 | ||
# Create and update manifests | ||
docker manifest create ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64 | ||
docker manifest annotate ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64 --arch amd64 | ||
docker manifest create ${{ env.REPOSITORY }}:stable ${{ env.REPOSITORY }}:stable-amd64 | ||
docker manifest annotate ${{ env.REPOSITORY }}:stable ${{ env.REPOSITORY }}:stable-amd64 --arch amd64 | ||
# push manifests | ||
docker manifest push ${{ steps.docker_meta.outputs.tags }} | ||
docker manifest push ${{ env.REPOSITORY }}:stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
on: [push, pull_request] | ||
name: test | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [1.19.x] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: lint | ||
run: make lint | ||
|
||
- name: test | ||
run: make test | ||
|
||
coverage: | ||
runs-on: ubuntu-latest | ||
name: coverage | ||
needs: test | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19.x | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Go test with coverage | ||
run: make test-coverage | ||
|
||
- name: Coveralls | ||
uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
path-to-lcov: build/coverage/lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,14 @@ REPO_PATH=$(ORG_PATH)/$(PACKAGE) | |
GOPATH=$(CURDIR)/.gopath | ||
GOBIN =$(CURDIR)/bin | ||
BUILDDIR=$(CURDIR)/build | ||
COVERAGE_DIR := $(BUILDDIR)/coverage | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
BIN_DIR := $(PROJECT_DIR)/bin | ||
PLUGINSSOURCEDIR=$(CURDIR)/pkg/sm/plugins | ||
PLUGINSBUILDDIR=$(BUILDDIR)/plugins | ||
GOFILES=$(shell find . -name *.go | grep -vE "(\/vendor\/)|(_test.go)") | ||
PKGS := $(shell cd $(PROJECT_DIR) && go list ./... | grep -v mocks) | ||
TESTPKGS := $(shell go list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS)) | ||
|
||
export GOPATH | ||
export GOBIN | ||
|
@@ -43,6 +48,10 @@ GOLANGCI_LINT = $(GOBIN)/golangci-lint | |
TIMEOUT = 15 | ||
Q = $(if $(filter 1,$V),,@) | ||
|
||
ENVTEST := $(BIN_DIR)/setup-envtest | ||
GOCOVMERGE := $(BIN_DIR)/gocovmerge | ||
GCOV2LCOV := $(BIN_DIR)/gcov2lcov | ||
|
||
.PHONY: all | ||
all: build plugins | ||
|
||
|
@@ -83,7 +92,7 @@ plugins: noop-plugin ufm-plugin ; $(info Building plugins...) ## Build plugins | |
|
||
%-plugin: $(PLUGINSBUILDDIR) | ||
@echo Building $* plugin | ||
$Q $(GO) build $(GOFLAGS) -ldflags "-X $(REPO_PATH)/version=1.0" -o $(PLUGINSBUILDDIR)/$*.so -buildmode=plugin -i $(REPO_PATH)/pkg/sm/plugins/$* | ||
$Q $(GO) build $(GOFLAGS) -ldflags "-X $(REPO_PATH)/version=1.0" -o $(PLUGINSBUILDDIR)/$*.so -buildmode=plugin $(REPO_PATH)/pkg/sm/plugins/$* | ||
@echo Done building $* plugin | ||
|
||
TEST_TARGETS := test-bench test-short test-verbose test-race | ||
|
@@ -100,9 +109,27 @@ test: | plugins; $(info running $(NAME:%=% )tests...) @ ## Run tests | |
|
||
COVERAGE_MODE = count | ||
.PHONY: test-coverage test-coverage-tools | ||
test-coverage-tools: | $(GOVERALLS) | ||
test-coverage: test-coverage-tools | plugins; $(info running coverage tests...) @ ## Run coverage tests | ||
$Q $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=coverage.out ./... | ||
test-coverage: | envtest gocovmerge gcov2lcov ## Run coverage tests | ||
mkdir -p $(BUILDDIR)/coverage/pkgs | ||
for pkg in $(TESTPKGS); do \ | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test \ | ||
-covermode=atomic \ | ||
-coverprofile="$(COVERAGE_DIR)/pkgs/`echo $$pkg | tr "/" "-"`.cover" $$pkg ;\ | ||
done | ||
$(GOCOVMERGE) $(COVERAGE_DIR)/pkgs/*.cover > $(COVERAGE_DIR)/profile.out | ||
$(GCOV2LCOV) -infile $(COVERAGE_DIR)/profile.out -outfile $(COVERAGE_DIR)/lcov.info | ||
|
||
.PHONY: envtest | ||
envtest: ## Download envtest if necessary | ||
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) | ||
|
||
.PHONY: gocovmerge | ||
gocovmerge: ## Download gocovmerge if necessary | ||
$(call go-install-tool,$(GOCOVMERGE),github.com/wadey/gocovmerge@latest) | ||
|
||
.PHONY: gcov2lcov | ||
gcov2lcov: ## Download gcov2lcov if necessary | ||
$(call go-install-tool,$(GCOV2LCOV),github.com/jandelgado/[email protected]) | ||
|
||
# Container image | ||
.PHONY: image | ||
|
@@ -123,3 +150,12 @@ clean: ; $(info Cleaning...) ## Cleanup everything | |
help: ## Show this message | ||
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ | ||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
||
# go-get-tool will 'go get' any package $2 and install it to $1. | ||
define go-install-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\ | ||
} | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.