Skip to content

Commit 80e866a

Browse files
committed
update build system and lint
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 3d5bbbb commit 80e866a

10 files changed

+205
-50
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor/
22
/azure-keyvault-exporter
3+
/release-assets

.github/workflows/ci-docker.yml .github/workflows/ci-docker.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2
1010

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

1616
- name: Run Golangci lint
1717
uses: golangci/golangci-lint-action@v2
1818
with:
1919
version: latest
20-
args: -E exportloopref,gofmt --timeout=30m
20+
args: --print-resources-usage
2121

2222
- name: Docker meta
2323
id: docker_meta
@@ -39,6 +39,6 @@ jobs:
3939
context: .
4040
file: ./Dockerfile
4141
push: false
42-
platforms: linux/amd64,linux/arm,linux/arm64
42+
platforms: linux/amd64,linux/arm64
4343
tags: ${{ steps.docker_meta.outputs.tags }}
4444
labels: ${{ steps.docker_meta.outputs.labels }}

.github/workflows/release-assets.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Release: assets"
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Set Swap Space
14+
uses: pierotofy/set-swap-space@master
15+
with:
16+
swap-size-gb: 12
17+
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: '1.19'
21+
check-latest: true
22+
23+
- name: Build
24+
run: |
25+
make release-assets
26+
27+
- name: Upload assets to release
28+
uses: svenstaro/upload-release-action@v2
29+
with:
30+
repo_token: ${{ secrets.GITHUB_TOKEN }}
31+
file: ./release-assets/*
32+
tag: ${{ github.ref }}
33+
overwrite: true
34+
file_glob: true

.github/workflows/release-docker.yml .github/workflows/release-docker.yaml

+29-8
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,50 @@ on:
88
- '*.*.*'
99

1010
jobs:
11-
build:
11+
lint:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
1515

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

2121
- name: Run Golangci lint
2222
uses: golangci/golangci-lint-action@v2
2323
with:
2424
version: latest
25-
args: -E exportloopref,gofmt --timeout=30m
25+
args: --print-resources-usage
26+
27+
build:
28+
needs: lint
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
Dockerfile: [Dockerfile]
33+
suffix: [""]
34+
latest: ["auto"]
35+
include: []
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- name: Set Swap Space
41+
uses: pierotofy/set-swap-space@master
42+
with:
43+
swap-size-gb: 12
2644

2745
- name: Docker meta
2846
id: docker_meta
29-
uses: docker/metadata-action@v3
47+
uses: docker/metadata-action@v4
3048
with:
3149
images: ${{ github.repository }},quay.io/${{ github.repository }}
3250
labels: |
3351
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
52+
flavor: |
53+
latest=${{ matrix.latest }}
54+
suffix=${{ matrix.suffix }}
3455
3556
- name: Set up QEMU
3657
uses: docker/setup-qemu-action@v1
@@ -55,8 +76,8 @@ jobs:
5576
uses: docker/build-push-action@v2
5677
with:
5778
context: .
58-
file: ./Dockerfile
59-
platforms: linux/amd64,linux/arm,linux/arm64
79+
file: ./${{ matrix.Dockerfile }}
80+
platforms: linux/amd64,linux/arm64
6081
push: ${{ github.event_name != 'pull_request' }}
6182
tags: ${{ steps.docker_meta.outputs.tags }}
6283
labels: ${{ steps.docker_meta.outputs.labels }}

.github/workflows/scheduled-docker.yml .github/workflows/scheduled-docker.yaml

+29-8
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,50 @@ on:
55
- cron: '0 6 * * 1'
66

77
jobs:
8-
build:
8+
lint:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
1212

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

1818
- name: Run Golangci lint
1919
uses: golangci/golangci-lint-action@v2
2020
with:
2121
version: latest
22-
args: -E exportloopref,gofmt --timeout=30m
22+
args: --print-resources-usage
23+
24+
build:
25+
needs: lint
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
Dockerfile: [Dockerfile]
30+
suffix: [""]
31+
latest: ["auto"]
32+
include: []
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v2
36+
37+
- name: Set Swap Space
38+
uses: pierotofy/set-swap-space@master
39+
with:
40+
swap-size-gb: 12
2341

2442
- name: Docker meta
2543
id: docker_meta
26-
uses: docker/metadata-action@v3
44+
uses: docker/metadata-action@v4
2745
with:
2846
images: ${{ github.repository }},quay.io/${{ github.repository }}
2947
labels: |
3048
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
49+
flavor: |
50+
latest=${{ matrix.latest }}
51+
suffix=${{ matrix.suffix }}
3152
3253
- name: Set up QEMU
3354
uses: docker/setup-qemu-action@v1
@@ -52,8 +73,8 @@ jobs:
5273
uses: docker/build-push-action@v2
5374
with:
5475
context: .
55-
file: ./Dockerfile
56-
platforms: linux/amd64,linux/arm,linux/arm64
76+
file: ./${{ matrix.Dockerfile }}
77+
platforms: linux/amd64,linux/arm64
5778
push: ${{ github.event_name != 'pull_request' }}
5879
tags: ${{ steps.docker_meta.outputs.tags }}
5980
labels: ${{ steps.docker_meta.outputs.labels }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor/
22
/azure-keyvault-exporter
3+
/release-assets

.golangci.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
run:
2+
timeout: 120m
3+
4+
linters:
5+
enable:
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- errorlint
10+
- exportloopref
11+
- gofmt
12+
- goimports
13+
- gosec
14+
15+
linters-settings:
16+
gosec:
17+
excludes: []
18+
confidence: low
19+
config:
20+
global:
21+
audit: true
22+
23+
issues: {}
24+
25+
output:
26+
sort-results: true

Makefile

+57-21
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,90 @@ LDFLAGS := -X "main.gitTag=$(GIT_TAG)" -X "main.gitCommit=$(GIT_COMMIT)" -ext
55

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

109
.PHONY: all
11-
all: build
10+
all: vendor build
1211

1312
.PHONY: clean
1413
clean:
1514
git clean -Xfd .
1615

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

2120
.PHONY: vendor
2221
vendor:
2322
go mod tidy
2423
go mod vendor
2524
go mod verify
2625

26+
.PHONY: build-all
27+
build-all:
28+
GOOS=linux GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME)' .
29+
GOOS=darwin GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).darwin' .
30+
GOOS=windows GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o '$(PROJECT_NAME).exe' .
31+
32+
.PHONY: build
33+
build:
34+
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' -o $(PROJECT_NAME) .
35+
2736
.PHONY: image
28-
image: build
37+
image: image
2938
docker build -t $(PROJECT_NAME):$(GIT_TAG) .
3039

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

35-
.PHONY: test
36-
test:
37-
go test ./...
45+
#######################################
46+
# quality checks
47+
#######################################
3848

39-
.PHONY: dependencies
40-
dependencies:
41-
go mod vendor
49+
.PHONY: check
50+
check: vendor lint test
4251

43-
.PHONY: check-release
44-
check-release: vendor lint gosec test
52+
.PHONY: test
53+
test:
54+
time go test ./...
4555

4656
.PHONY: lint
4757
lint: $(GOLANGCI_LINT_BIN)
48-
$(GOLANGCI_LINT_BIN) run -E exportloopref,gofmt --timeout=30m
49-
50-
.PHONY: gosec
51-
gosec: $(GOSEC_BIN)
52-
$(GOSEC_BIN) ./...
58+
time $(GOLANGCI_LINT_BIN) run --verbose --print-resources-usage
5359

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

57-
$(GOSEC_BIN):
58-
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(FIRST_GOPATH)/bin
63+
#######################################
64+
# release assets
65+
#######################################
66+
67+
RELEASE_ASSETS = \
68+
$(foreach GOARCH,amd64 arm64,\
69+
$(foreach GOOS,linux darwin windows,\
70+
release-assets/$(GOOS).$(GOARCH))) \
71+
72+
word-dot = $(word $2,$(subst ., ,$1))
73+
74+
.PHONY: release-assets
75+
release-assets: clean-release-assets vendor $(RELEASE_ASSETS)
76+
77+
.PHONY: clean-release-assets
78+
clean-release-assets:
79+
rm -rf ./release-assets
80+
mkdir -p ./release-assets
81+
82+
release-assets/windows.%: $(SOURCE)
83+
echo 'build release-assets for windows/$(call word-dot,$*,2)'
84+
GOOS=windows \
85+
GOARCH=$(call word-dot,$*,1) \
86+
CGO_ENABLED=0 \
87+
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).windows.$(call word-dot,$*,1).exe' .
88+
89+
release-assets/%: $(SOURCE)
90+
echo 'build release-assets for $(call word-dot,$*,1)/$(call word-dot,$*,2)'
91+
GOOS=$(call word-dot,$*,1) \
92+
GOARCH=$(call word-dot,$*,2) \
93+
CGO_ENABLED=0 \
94+
time go build -ldflags '$(LDFLAGS)' -o './release-assets/$(PROJECT_NAME).$(call word-dot,$*,1).$(call word-dot,$*,2)' .

config/opts.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ type (
3030
Concurrency int `long:"scrape.concurrency" env:"SCRAPE_CONCURRENCY" description:"Defines who many Keyvaults can be scraped at the same time" default:"10"`
3131
}
3232

33-
// general options
34-
ServerBind string `long:"bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
33+
Server struct {
34+
// general options
35+
Bind string `long:"server.bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
36+
ReadTimeout time.Duration `long:"server.timeout.read" env:"SERVER_TIMEOUT_READ" description:"Server read timeout" default:"5s"`
37+
WriteTimeout time.Duration `long:"server.timeout.write" env:"SERVER_TIMEOUT_WRITE" description:"Server write timeout" default:"10s"`
38+
}
3539
}
3640
)
3741

0 commit comments

Comments
 (0)