Skip to content

Commit

Permalink
update build system and lint
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Sep 17, 2022
1 parent 3d5bbbb commit 80e866a
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 50 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/azure-keyvault-exporter
/release-assets
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Run Gosec Security Scanner
uses: securego/gosec@master
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
args: ./...
swap-size-gb: 12

- name: Run Golangci lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: -E exportloopref,gofmt --timeout=30m
args: --print-resources-usage

- name: Docker meta
id: docker_meta
Expand All @@ -39,6 +39,6 @@ jobs:
context: .
file: ./Dockerfile
push: false
platforms: linux/amd64,linux/arm,linux/arm64
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
34 changes: 34 additions & 0 deletions .github/workflows/release-assets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Release: assets"

on:
release:
types: [created]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 12

- uses: actions/setup-go@v2
with:
go-version: '1.19'
check-latest: true

- name: Build
run: |
make release-assets
- name: Upload assets to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./release-assets/*
tag: ${{ github.ref }}
overwrite: true
file_glob: true
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,50 @@ on:
- '*.*.*'

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run Gosec Security Scanner
uses: securego/gosec@master
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
args: ./...
swap-size-gb: 12

- name: Run Golangci lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: -E exportloopref,gofmt --timeout=30m
args: --print-resources-usage

build:
needs: lint
strategy:
fail-fast: false
matrix:
Dockerfile: [Dockerfile]
suffix: [""]
latest: ["auto"]
include: []
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 12

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: ${{ github.repository }},quay.io/${{ github.repository }}
labels: |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
flavor: |
latest=${{ matrix.latest }}
suffix=${{ matrix.suffix }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -55,8 +76,8 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64
file: ./${{ matrix.Dockerfile }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,50 @@ on:
- cron: '0 6 * * 1'

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run Gosec Security Scanner
uses: securego/gosec@master
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
args: ./...
swap-size-gb: 12

- name: Run Golangci lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: -E exportloopref,gofmt --timeout=30m
args: --print-resources-usage

build:
needs: lint
strategy:
fail-fast: false
matrix:
Dockerfile: [Dockerfile]
suffix: [""]
latest: ["auto"]
include: []
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 12

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: ${{ github.repository }},quay.io/${{ github.repository }}
labels: |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
flavor: |
latest=${{ matrix.latest }}
suffix=${{ matrix.suffix }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand All @@ -52,8 +73,8 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64
file: ./${{ matrix.Dockerfile }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/azure-keyvault-exporter
/release-assets
26 changes: 26 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
run:
timeout: 120m

linters:
enable:
- asciicheck
- bidichk
- bodyclose
- errorlint
- exportloopref
- gofmt
- goimports
- gosec

linters-settings:
gosec:
excludes: []
confidence: low
config:
global:
audit: true

issues: {}

output:
sort-results: true
78 changes: 57 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,90 @@ LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -ext

FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
GOSEC_BIN := $(FIRST_GOPATH)/bin/gosec

.PHONY: all
all: build
all: vendor build

.PHONY: clean
clean:
git clean -Xfd .

.PHONY: build
build:
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -a -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
#######################################
# builds
#######################################

.PHONY: vendor
vendor:
go mod tidy
go mod vendor
go mod verify

.PHONY: build-all
build-all:
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME)' .
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).darwin' .
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).exe' .

.PHONY: build
build:
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .

.PHONY: image
image: build
image: image
docker build -t $(PROJECT_NAME):$(GIT_TAG) .

.PHONY: build-push-development
build-push-development:
docker buildx create --use
docker buildx build -t webdevops/$(PROJECT_NAME):development --platform linux/amd64,linux/arm,linux/arm64 --push .

.PHONY: test
test:
go test ./...
#######################################
# quality checks
#######################################

.PHONY: dependencies
dependencies:
go mod vendor
.PHONY: check
check: vendor lint test

.PHONY: check-release
check-release: vendor lint gosec test
.PHONY: test
test:
time go test ./...

.PHONY: lint
lint: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN) run -E exportloopref,gofmt --timeout=30m

.PHONY: gosec
gosec: $(GOSEC_BIN)
$(GOSEC_BIN) ./...
time $(GOLANGCI_LINT_BIN) run --verbose --print-resources-usage

$(GOLANGCI_LINT_BIN):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin

$(GOSEC_BIN):
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin
#######################################
# release assets
#######################################

RELEASE_ASSETS = \
$(foreach GOARCH,amd64 arm64,\
$(foreach GOOS,linux darwin windows,\
release-assets/$(GOOS).$(GOARCH))) \

word-dot = $(word $2,$(subst ., ,$1))

.PHONY: release-assets
release-assets: clean-release-assets vendor $(RELEASE_ASSETS)

.PHONY: clean-release-assets
clean-release-assets:
rm -rf ./release-assets
mkdir -p ./release-assets

release-assets/windows.%: $(SOURCE)
echo 'build release-assets for windows/$(call word-dot,$*,2)'
GOOS=windows \
GOARCH=$(call word-dot,$*,1) \
CGO_ENABLED=0 \
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).windows.$(call word-dot,$*,1).exe' .

release-assets/%: $(SOURCE)
echo 'build release-assets for $(call word-dot,$*,1)/$(call word-dot,$*,2)'
GOOS=$(call word-dot,$*,1) \
GOARCH=$(call word-dot,$*,2) \
CGO_ENABLED=0 \
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).$(call word-dot,$*,1).$(call word-dot,$*,2)' .
8 changes: 6 additions & 2 deletions config/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ type (
Concurrency int `long:"scrape.concurrency" env:"SCRAPE_CONCURRENCY" description:"Defines who many Keyvaults can be scraped at the same time" default:"10"`
}

// general options
ServerBind string `long:"bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
Server struct {
// general options
Bind string `long:"server.bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
ReadTimeout time.Duration `long:"server.timeout.read" env:"SERVER_TIMEOUT_READ" description:"Server read timeout" default:"5s"`
WriteTimeout time.Duration `long:"server.timeout.write" env:"SERVER_TIMEOUT_WRITE" description:"Server write timeout" default:"10s"`
}
}
)

Expand Down
Loading

0 comments on commit 80e866a

Please sign in to comment.