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

View file

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