Skip to content

Commit

Permalink
Merge pull request #117 from doitintl/v2-main
Browse files Browse the repository at this point in the history
KubeIP v2
  • Loading branch information
alexei-led authored Oct 22, 2023
2 parents 770ff5d + e8470c8 commit 245a5ad
Show file tree
Hide file tree
Showing 58 changed files with 6,195 additions and 2,513 deletions.
116 changes: 79 additions & 37 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: build

on:
workflow_dispatch:
push:
branches:
- '*'
Expand All @@ -18,60 +19,101 @@ on:

jobs:

docker-build:
validate:

runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message,'[skip ci]') }}
container: golang:1.21-alpine
steps:
- name: checkout
uses: actions/checkout@v4

- name: test
shell: sh
env:
CGO_ENABLED: 0
run: |
apk --update add ca-certificates tzdata make git bash
make lint
make test-json
- name: upload test results
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: test-reports
if-no-files-found: ignore
path: |
test-report.out
coverage.out
golangci-lint.out
- name: SonarCloud scan
uses: SonarSource/sonarcloud-github-action@master
if: ${{ always() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}


docker-build:

runs-on: ubuntu-latest
needs: validate
# build only on master branch and tags
if: ${{ !contains(github.event.head_commit.message,'[skip ci]') && (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) }}
steps:
- uses: actions/checkout@v3
- name: checkout
uses: actions/checkout@v4

- name: get short sha
id: short_sha
run: echo ::set-output name=sha::$(git rev-parse --short HEAD)

- name: get version
id: version
run: echo ::set-output name=version::$([[ -z "${{ github.event.pull_request.number }}" ]] && echo "sha-${{ steps.short_sha.outputs.sha }}" || echo "pr-${{ github.event.pull_request.number }}")

- name: set up QEMU
uses: docker/setup-qemu-action@v3

- name: set up Docker buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest

- name: decide on tag
id: prep
run: |
DOCKER_IMAGE=${{ github.repository }}
VERSION=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT

- name: login to DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: prepare meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ github.repository }}-agent
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
github.run.id=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
org.opencontainers.image.title=kubeip-agent
org.opencontainers.image.description=kubeip agent
org.opencontainers.image.vendor=DoiT International
- name: build and push
id: docker_build
uses: docker/build-push-action@v5
with:
build-args: |
VERSION=${{ steps.version.outputs.version }}
COMMIT=${{ steps.short_sha.outputs.sha }}
BRANCH=${{ github.ref_name }}
push: true
platforms: |
linux/amd64
linux/arm64
tags: ${{ steps.prep.outputs.tags }}

- name: image digest
run: echo ${{ steps.docker_build.outputs.digest }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
55 changes: 43 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
# code coverage
.cover
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
.bin

# Test binary, built with `go test -c`
*.test
.run

# Local environment
.env
.in
.out

# Local .terraform directories
**/.terraform/*

# Sonar Scanner
.scannerwork/

# git repo
.git
# .tfstate files
*.tfstate
*.tfstate.*

# IDE customization

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# IDE support files
.idea
.vscode

# binaries
.bin
# MacOS file system metadata
.DS_Store

# env customization
.env
.in
# local credentials
.credentials

# Test binary, build with `go test -c`
*.test
# Keep out some temporary example code and temprary file
example_code/
older/
temp/

# Dependency directories (remove the comment below to include it)
vendor/

tmp/
146 changes: 146 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
run:
# which dirs to skip
skip-dirs:
- mocks
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m
# Exit code when at least one issue was found.
# Default: 1
issues-exit-code: 2
# Include test files or not.
# Default: true
tests: false
# allow parallel run
allow-parallel-runners: true

linters-settings:
govet:
check-shadowing: true
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
ignore-words:
- "cancelled"
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- rangeValCopy
- unnamedResult
- whyNoLint
- wrapperFunc
funlen:
lines: 105
statements: 50

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
# - containedctx
# - contextcheck disabled because of generics
- dupword
- decorder
# - depguard
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
# - exhaustivestruct TODO: check how to fix it
- exportloopref
# - forbidigo TODO: configure forbidden code patterns
# - forcetypeassert
- funlen
- gci
# - gochecknoglobals TODO: remove globals from code
# - gochecknoinits TODO: remove main.init
- gocognit
- goconst
- gocritic
- gocyclo
# - godox
- goerr113
- gofmt
- goimports
- gomnd
# - gomoddirectives
- gosec
- gosimple
- govet
- goprintffuncname
- grouper
- importas
# - ireturn TODO: not sure if it is a good linter
- ineffassign
- interfacebloat
- loggercheck
- maintidx
- makezero
- misspell
- nakedret
# - nestif
- nilerr
- nilnil
# - noctx
- nolintlint
- prealloc
- predeclared
- promlinter
- reassign
- revive
# - rowserrcheck disabled because of generics
# - staticcheck doesn't work with go1.19
# - structcheck disabled because of generics
- stylecheck
- tenv
- testableexamples
- typecheck
- unconvert
- unparam
- unused
# - varnamelen TODO: review naming
# - varcheck depricated 1.49
# - wastedassign disabled because of generics
- whitespace
- wrapcheck
# - wsl

issues:
exclude-rules:
- path: _test\.go
linters:
- funlen
- bodyclose
- gosec
- dupl
- gocognit
- goconst
- gocyclo
exclude:
- Using the variable on range scope `tt` in function literal
Loading

0 comments on commit 245a5ad

Please sign in to comment.