From 97bc9925e44db8caab9af44f1bf597df73828958 Mon Sep 17 00:00:00 2001 From: Hector <hector@hjs.dev> Date: Mon, 19 Jun 2023 19:23:45 +0100 Subject: [PATCH 1/3] rewrite makefile --- .gitlab-ci.yml | 72 ++++++++++++++++++++++++++------------------------ Makefile | 43 ++++++++++++++---------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b0bd63a..600f802 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,37 +2,39 @@ stages: - test - build -.go_template: - image: golang:latest - before_script: - - make go/dependencies +# .go_template: +# image: golang:latest +# before_script: +# - make download -.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: + stage: build + script: + - make build # build: # extends: .go_template @@ -49,21 +51,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 diff --git a/Makefile b/Makefile index 12434b7..6a7830d 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,27 @@ -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: + mkdir -p 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 build/fail2ban_exporter \ + exporter.go From fc2b16a678ee749f239d569fc8da54566b139b53 Mon Sep 17 00:00:00 2001 From: Hector <hector@hjs.dev> Date: Mon, 19 Jun 2023 19:26:57 +0100 Subject: [PATCH 2/3] use golang image for cicd --- .gitlab-ci.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 600f802..a6c8c04 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,10 +2,8 @@ stages: - test - build -# .go_template: -# image: golang:latest -# before_script: -# - make download +.go_template: + image: golang:latest # .docker_template: # image: docker:stable @@ -17,24 +15,32 @@ stages: # - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY dependencies: + extends: .go_template stage: test script: - make check/dependencies format: + extends: .go_template stage: test script: - make check/fmt test: + extends: .go_template stage: test script: - make test build: + extends: .go_template stage: build script: - make build + artifacts: + paths: + - build/* + expire_in: 1 day # build: # extends: .go_template From 52f93a1b2bd99948abbee476340660a2825b3e12 Mon Sep 17 00:00:00 2001 From: Hector <hector@hjs.dev> Date: Mon, 19 Jun 2023 19:34:06 +0100 Subject: [PATCH 3/3] update manual build path --- .gitlab-ci.yml | 2 +- Makefile | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a6c8c04..7bb7dce 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,7 +39,7 @@ build: - make build artifacts: paths: - - build/* + - fail2ban_exporter expire_in: 1 day # build: diff --git a/Makefile b/Makefile index 6a7830d..ea25c46 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ check/fmt: download test -z $(shell gofmt -l .) build: - mkdir -p build/ go build \ -ldflags "\ -X main.version=${shell git describe --tags} \ @@ -23,5 +22,5 @@ build: -X main.date=${shell date --iso-8601=seconds} \ -X main.builtBy=manual \ " \ - -o build/fail2ban_exporter \ + -o fail2ban_exporter \ exporter.go