emissary/Makefile

145 lines
4.7 KiB
Makefile
Raw Normal View History

2023-02-02 10:55:24 +01:00
LINT_ARGS ?= --timeout 5m
GORELEASER_VERSION ?= v1.13.1
2023-03-22 18:33:23 +01:00
GORELEASER_ARGS ?= release --snapshot --rm-dist
2023-02-02 10:55:24 +01:00
GITCHLOG_ARGS ?=
SHELL := /bin/bash
EMISSARY_VERSION ?=
2023-03-22 18:33:23 +01:00
GIT_VERSION := $(shell git describe --always)
DATE_VERSION := $(shell date +%Y.%-m.%-d)
FULL_VERSION := v$(DATE_VERSION)-$(GIT_VERSION)$(if $(shell git diff --stat),-dirty,)
2023-02-02 10:55:24 +01:00
DOCKER_IMAGE_NAME ?= bornholm/emissary
2023-03-22 18:33:23 +01:00
DOCKER_IMAGE_TAG ?= $(FULL_VERSION)
2023-02-02 10:55:24 +01:00
GOTEST_ARGS ?= -short
OPENWRT_DEVICE ?= 192.168.1.1
watch: deps ## Watching updated files - live reload
( set -o allexport && source .env && set +o allexport && go run -mod=readonly github.com/cortesi/modd/cmd/modd@latest )
.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) ./... )
test-install-script: tools/bin/bash_unit
tools/bin/bash_unit ./misc/script/test_install.sh
tools/bin/bash_unit:
mkdir -p tools/bin
cd tools/bin && bash <(curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh)
lint: ## Lint sources code
golangci-lint run --enable-all $(LINT_ARGS)
build: build-emissary ## Build artefacts
build-emissary: build-emissary-server build-emissary-agent
build-emissary-%: deps ## Build executable
CGO_ENABLED=0 go build \
-v \
-ldflags "\
-X 'main.GitRef=$(shell git rev-parse --short HEAD)' \
2023-03-22 18:33:23 +01:00
-X 'main.ProjectVersion=$(FULL_VERSION)' \
2023-02-02 10:55:24 +01:00
-X 'main.BuildDate=$(shell date --utc --rfc-3339=seconds)' \
" \
-o ./bin/$* \
./cmd/$*
.env:
cp -f .env.dist .env
tmp/server.yml:
mkdir -p tmp
bin/server server config dump > tmp/server.yml
tmp/agent.yml:
mkdir -p tmp
bin/agent agent config dump > tmp/agent.yml
run-emissary-%: .env
( set -o allexport && source .env && set +o allexport && bin/$* $(EMISSARY_CMD))
.PHONY: deps
deps: .env
.PHONY: dump-config
dump-config: build-emissary
mkdir -p tmp
./bin/emissary config dump > tmp/config.yml
.PHONY: goreleaser
goreleaser: deps
2023-03-22 18:33:23 +01:00
( set -o allexport && source .env && set +o allexport && VERSION=$(GORELEASER_VERSION) curl -sfL https://goreleaser.com/static/run | GORELEASER_CURRENT_TAG="$(FULL_VERSION)" bash /dev/stdin $(GORELEASER_ARGS) )
2023-02-02 10:55:24 +01:00
.PHONY: start-release
start-release:
if [ -z "$(EMISSARY_VERSION)" ]; then echo "You must define environment variable FAQD_VERSION"; exit 1; fi
git flow release start $(EMISSARY_VERSION)
# Update package.json version
jq '.version = "$(EMISSARY_VERSION)"' package.json | sponge package.json
git add package.json
git commit -m "chore: bump to version $(EMISSARY_VERSION)" --allow-empty
echo "Commit you additional modifications then execute 'make finish-release'"
.PHONY: finish-release
finish-release:
git flow release finish -m "v$(EMISSARY_VERSION)"
git push --all
git push --tags
install-git-hooks:
git config core.hooksPath .githooks
docker-build:
docker build -t $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) .
docker-release:
docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
deploy-openwrt-agent:
$(MAKE) GOARCH="arm" GORELEASER_ARGS='build --single-target --snapshot --clean' goreleaser
ssh root@$(OPENWRT_DEVICE) mkdir -p /etc/emissary
ssh root@$(OPENWRT_DEVICE) mkdir -p /var/lib/emissary
scp misc/packaging/common/config-agent.yml root@$(OPENWRT_DEVICE):/etc/emissary/agent.yml
scp misc/packaging/openwrt/emissary-agent.init.sh root@$(OPENWRT_DEVICE):/etc/init.d/emissary-agent
ssh root@$(OPENWRT_DEVICE) chmod +x /etc/init.d/emissary-agent
ssh root@$(OPENWRT_DEVICE) mkdir -p /usr/share/emissary
ssh root@$(OPENWRT_DEVICE) /etc/init.d/emissary-agent enable
ssh root@$(OPENWRT_DEVICE) /etc/init.d/emissary-agent stop
scp dist/emissary-agent_linux_arm_6/emissary root@$(OPENWRT_DEVICE):/usr/bin/emissary
ssh root@$(OPENWRT_DEVICE) /etc/init.d/emissary-agent start
gitea-release: tools/gitea-release/bin/gitea-release.sh goreleaser
mkdir -p .gitea-release
rm -rf .gitea-release/*
cp dist/*.tar.gz .gitea-release/
GITEA_RELEASE_PROJECT="emissary" \
GITEA_RELEASE_ORG="arcad" \
GITEA_RELEASE_BASE_URL="https://forge.cadoles.com" \
2023-03-22 18:33:23 +01:00
GITEA_RELEASE_VERSION="$(FULL_VERSION)" \
GITEA_RELEASE_NAME="$(FULL_VERSION)" \
2023-02-02 10:55:24 +01:00
GITEA_RELEASE_COMMITISH_TARGET="$(GIT_VERSION)" \
GITEA_RELEASE_IS_DRAFT="false" \
GITEA_RELEASE_BODY="" \
GITEA_RELEASE_ATTACHMENTS="$(shell find .gitea-release/* -type f)" \
tools/gitea-release/bin/gitea-release.sh
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
.emissary-token:
2023-03-13 10:44:58 +01:00
$(MAKE) run-emissary-server EMISSARY_CMD="--debug --config tmp/server.yml server auth create-token --role writer > .emissary-token"