bouncer/Makefile

167 lines
5.0 KiB
Makefile
Raw Normal View History

2023-04-24 20:52:12 +02:00
LINT_ARGS ?= --timeout 5m
GORELEASER_VERSION ?= v1.13.1
GORELEASER_ARGS ?= release --snapshot --rm-dist
GITCHLOG_ARGS ?=
SHELL := /bin/bash
BOUNCER_VERSION ?=
2023-06-30 04:13:56 +02:00
GIT_COMMIT := $(shell git rev-parse --short HEAD)
2023-04-24 20:52:12 +02:00
DATE_VERSION := $(shell date +%Y.%-m.%-d)
2023-06-30 04:13:56 +02:00
FULL_VERSION := v$(DATE_VERSION)-$(GIT_COMMIT)$(if $(shell git diff --stat),-dirty,)
2023-04-24 20:52:12 +02:00
2023-06-30 04:13:56 +02:00
DOCKER_IMAGE_NAME ?= reg.cadoles.com/cadoles/bouncer
2023-04-24 20:52:12 +02:00
DOCKER_IMAGE_TAG ?= $(FULL_VERSION)
GOTEST_ARGS ?= -short
OPENWRT_DEVICE ?= 192.168.1.1
2024-02-15 15:17:28 +01:00
SIEGE_URLS_FILE ?= misc/siege/urls.txt
SIEGE_CONCURRENCY ?= 50
SIEGE_DURATION ?= 1M
2024-02-15 15:17:28 +01:00
data/bootstrap.d/dummy.yml:
mkdir -p data/bootstrap.d
cp misc/bootstrap.d/dummy.yml data/bootstrap.d/dummy.yml
watch: tools/modd/bin/modd deps data/bootstrap.d/dummy.yml ## Watching updated files - live reload
2023-04-24 20:52:12 +02:00
( set -o allexport && source .env && set +o allexport && tools/modd/bin/modd )
.PHONY: test
test: test-go ## Executing tests
test-go: deps
( set -o allexport && source .env && set +o allexport && go test -v -count=1 $(GOTEST_ARGS) ./... )
build: build-bouncer ## Build artefacts
build-bouncer: deps ## Build executable
CGO_ENABLED=0 go build \
-v \
-ldflags "\
-X 'main.GitRef=$(shell git rev-parse --short HEAD)' \
-X 'main.ProjectVersion=$(FULL_VERSION)' \
-X 'main.BuildDate=$(shell date --utc --rfc-3339=seconds)' \
" \
-o ./bin/bouncer \
./cmd/bouncer
.env:
cp -f .env.dist .env
config.yml:
bin/bouncer config dump > config.yml
run: .env
( set -o allexport && source .env && set +o allexport && bin/bouncer $(BOUNCER_CMD))
.PHONY: deps
deps: .env
.PHONY: goreleaser
goreleaser: deps
2024-06-05 15:54:00 +02:00
( set -o allexport && source .env && set +o allexport && curl -sfL https://goreleaser.com/static/run | VERSION=$(GORELEASER_VERSION) GORELEASER_CURRENT_TAG="$(FULL_VERSION)" bash /dev/stdin $(GORELEASER_ARGS) )
2023-04-24 20:52:12 +02:00
.PHONY: start-release
start-release:
if [ -z "$(BOUNCER_VERSION)" ]; then echo "You must define environment variable BOUNCER_VERSION"; exit 1; fi
git flow release start $(BOUNCER_VERSION)
# Update package.json version
jq '.version = "$(BOUNCER_VERSION)"' package.json | sponge package.json
git add package.json
git commit -m "chore: bump to version $(BOUNCER_VERSION)" --allow-empty
echo "Commit you additional modifications then execute 'make finish-release'"
.PHONY: finish-release
finish-release:
git flow release finish -m "v$(BOUNCER_VERSION)"
git push --all
git push --tags
docker-build:
docker build --pull -t $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) .
docker tag $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) $(DOCKER_IMAGE_NAME):latest
2023-04-24 20:52:12 +02:00
docker-release:
docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
docker push $(DOCKER_IMAGE_NAME):latest
2023-04-24 20:52:12 +02:00
gitea-release: tools/gitea-release/bin/gitea-release.sh goreleaser
mkdir -p .gitea-release
rm -rf .gitea-release/*
cp dist/*.tar.gz .gitea-release/
cp dist/*.apk .gitea-release/
cp dist/*.deb .gitea-release/
cp dist/*.rpm .gitea-release/
GITEA_RELEASE_PROJECT="bouncer" \
GITEA_RELEASE_ORG="Cadoles" \
GITEA_RELEASE_BASE_URL="https://forge.cadoles.com" \
GITEA_RELEASE_VERSION="$(FULL_VERSION)" \
GITEA_RELEASE_NAME="$(FULL_VERSION)" \
2023-06-30 04:13:56 +02:00
GITEA_RELEASE_COMMITISH_TARGET="$(GIT_COMMIT)" \
2023-04-24 20:52:12 +02:00
GITEA_RELEASE_IS_DRAFT="false" \
GITEA_RELEASE_BODY="" \
GITEA_RELEASE_ATTACHMENTS="$$(find .gitea-release/* -type f)" \
tools/gitea-release/bin/gitea-release.sh
grafterm: tools/grafterm/bin/grafterm
tools/grafterm/bin/grafterm -c ./misc/grafterm/dashboard.json -v job=bouncer-proxy -r 5s
siege:
2024-02-15 15:17:28 +01:00
$(eval TMP := $(shell mktemp))
cat $(SIEGE_URLS_FILE) | envsubst > $(TMP)
siege -R ./misc/siege/siege.conf -i -b -c $(SIEGE_CONCURRENCY) -t $(SIEGE_DURATION) -f $(TMP)
2024-02-15 15:17:28 +01:00
rm -rf $(TMP)
2023-04-24 20:52:12 +02:00
tools/gitea-release/bin/gitea-release.sh:
mkdir -p tools/gitea-release/bin
curl --output tools/gitea-release/bin/gitea-release.sh https://forge.cadoles.com/Cadoles/Jenkins/raw/branch/master/resources/com/cadoles/gitea/gitea-release.sh
chmod +x tools/gitea-release/bin/gitea-release.sh
tools/modd/bin/modd:
mkdir -p tools/modd/bin
GOBIN=$(PWD)/tools/modd/bin go install github.com/cortesi/modd/cmd/modd@latest
tools/grafterm/bin/grafterm:
mkdir -p tools/grafterm/bin
GOBIN=$(PWD)/tools/grafterm/bin go install github.com/slok/grafterm/cmd/grafterm@v0.2.0
bench:
go test -bench=. -run '^$$' ./internal/bench
tools/benchstat/bin/benchstat:
mkdir -p tools/benchstat/bin
GOBIN=$(PWD)/tools/benchstat/bin go install golang.org/x/perf/cmd/benchstat@latest
2023-04-24 20:52:12 +02:00
full-version:
@echo $(FULL_VERSION)
.bouncer-token:
bin/bouncer auth create-token --role writer --subject dev-writer > .bouncer-token
run-redis:
docker kill bouncer-redis || exit 0
docker run --rm -t \
--name bouncer-redis \
-v $(PWD)/data/redis:/data \
-p 6379:6379 \
redis:alpine3.17 \
redis-server --save 60 1 --loglevel debug
2023-04-24 20:52:12 +02:00
redis-shell:
docker exec -it \
bouncer-redis \
redis-cli
run-prometheus:
docker kill bouncer-prometheus || exit 0
docker run --rm -t \
--name bouncer-prometheus \
--network host \
-v $(PWD)/misc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus