chore: rewrite make commands

This commit is contained in:
Hector 2023-06-19 18:37:27 +00:00
parent 95f9c821ff
commit 8ff64467db
2 changed files with 57 additions and 53 deletions

View File

@ -4,35 +4,43 @@ stages:
.go_template:
image: golang:latest
before_script:
- make go/dependencies
.docker_template:
image: docker:stable
services:
- docker:dind
before_script:
- apk add git
- apk add make
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# .docker_template:
# image: docker:stable
# services:
# - docker:dind
# before_script:
# - apk add git
# - apk add make
# - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
dependencies:
extends: .go_template
stage: test
script:
- make go/checkDependencies
- make check/dependencies
format:
extends: .go_template
stage: test
script:
- make go/checkFmt
- make check/fmt
test:
extends: .go_template
stage: test
script:
- make go/test
- make test
build:
extends: .go_template
stage: build
script:
- make build
artifacts:
paths:
- fail2ban_exporter
expire_in: 1 day
# build:
# extends: .go_template
@ -49,21 +57,21 @@ test:
# - dist/checksums.txt
# expire_in: 1 day
docker/gitlab:
extends: .docker_template
stage: build
only:
- tags
script:
- make docker/build/latest
- make docker/build/tag
- docker push registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter
# docker/gitlab:
# extends: .docker_template
# stage: build
# only:
# - tags
# script:
# - make docker/build/latest
# - make docker/build/tag
# - docker push registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter
docker/gitlab/nightly:
extends: .docker_template
stage: build
only:
- main
script:
- make docker/build/nightly
- docker push registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter
# docker/gitlab/nightly:
# extends: .docker_template
# stage: build
# only:
# - main
# script:
# - make docker/build/nightly
# - docker push registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter

View File

@ -1,30 +1,26 @@
go/dependencies:
download:
go mod download
# Make sure no unnecessary dependencies are present
go/checkDependencies:
test: download
go test ./... -v -race
fmt: download
go fmt ./...
check/dependencies: download
go mod tidy -v
git diff-index --quiet HEAD
# Standard go test
go/test:
go test ./... -v -race
go/fmt:
go fmt ./...
go/checkFmt:
check/fmt: download
test -z $(shell gofmt -l .)
build/docker:
go build -o fail2ban_exporter \
-ldflags '-X main.version=$(shell git describe --tags) -X main.commit=${shell git rev-parse HEAD} -X "main.date=${shell date --rfc-3339=seconds}" -X main.builtBy=docker' exporter.go
docker/build/latest:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:latest .
docker/build/nightly:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:nightly .
docker/build/tag:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:$(shell git describe --tags) .
build:
go build \
-ldflags "\
-X main.version=${shell git describe --tags} \
-X main.commit=${shell git rev-parse HEAD} \
-X main.date=${shell date --iso-8601=seconds} \
-X main.builtBy=manual \
" \
-o fail2ban_exporter \
exporter.go