2023-02-02 10:55:24 +01:00
LINT_ARGS ?= --timeout 5m
2023-11-30 19:47:00 +01:00
GORELEASER_ARGS ?= release --snapshot --clean
2023-02-02 10:55:24 +01:00
GITCHLOG_ARGS ?=
SHELL := /bin/bash
EMISSARY_VERSION ?=
2023-10-30 20:05:00 +01:00
DOCKER_IMAGE_NAME ?= reg.cadoles.com/cadoles/emissary
2023-08-25 17:56:28 +02:00
DOCKER_IMAGE_TAG ?= $( MKT_PROJECT_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-08-25 17:56:28 +02:00
-X 'main.ProjectVersion=$(MKT_PROJECT_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
2023-08-25 17:56:28 +02:00
deps : .env .mktools
2023-02-02 10:55:24 +01:00
.PHONY : dump -config
dump-config : build -emissary
mkdir -p tmp
./bin/emissary config dump > tmp/config.yml
.PHONY : goreleaser
2023-10-30 20:05:00 +01:00
goreleaser : .env .mktools
( set -o allexport && source .env && set +o allexport && curl -sfL https://goreleaser.com/static/run | GORELEASER_CURRENT_TAG = " $( MKT_PROJECT_VERSION) " bash /dev/stdin $( GORELEASER_ARGS) )
2023-02-02 10:55:24 +01:00
install-git-hooks :
git config core.hooksPath .githooks
2023-10-30 20:05:00 +01:00
docker-build : docker -build -agent docker -build -server
2023-02-02 10:55:24 +01:00
2023-10-30 20:05:00 +01:00
docker-build-% :
docker build --target emissary-$* -t $( DOCKER_IMAGE_NAME) -$* :latest .
docker-release : docker -release -agent docker -release -server
docker-release-% :
docker tag $( DOCKER_IMAGE_NAME) -$* :latest $( DOCKER_IMAGE_NAME) -$* :$( DOCKER_IMAGE_TAG)
docker push $( DOCKER_IMAGE_NAME) -$* :latest
docker push $( DOCKER_IMAGE_NAME) -$* :$( DOCKER_IMAGE_TAG)
2023-02-02 10:55:24 +01:00
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
2023-08-25 18:20:42 +02:00
gitea-release : .mktools tools /gitea -release /bin /gitea -release .sh goreleaser changelog
2023-02-02 10:55:24 +01:00
mkdir -p .gitea-release
rm -rf .gitea-release/*
cp dist/*.tar.gz .gitea-release/
2023-03-26 18:58:18 +02:00
cp dist/*.apk .gitea-release/
cp dist/*.deb .gitea-release/
2023-08-25 18:20:42 +02:00
cp CHANGELOG.md .gitea-release/
2023-02-02 10:55:24 +01:00
GITEA_RELEASE_PROJECT = "emissary" \
GITEA_RELEASE_ORG = "arcad" \
GITEA_RELEASE_BASE_URL = "https://forge.cadoles.com" \
2023-08-25 17:56:28 +02:00
GITEA_RELEASE_VERSION = " $( MKT_PROJECT_VERSION) " \
GITEA_RELEASE_NAME = " $( MKT_PROJECT_VERSION) " \
2023-02-02 10:55:24 +01:00
GITEA_RELEASE_COMMITISH_TARGET = " $( GIT_VERSION) " \
GITEA_RELEASE_IS_DRAFT = "false" \
GITEA_RELEASE_BODY = "" \
2023-03-31 14:29:10 +02:00
GITEA_RELEASE_ATTACHMENTS = " $$ (find .gitea-release/* -type f) " \
2023-02-02 10:55:24 +01:00
tools/gitea-release/bin/gitea-release.sh
2023-03-07 23:10:42 +01:00
.emissary-token :
2024-02-26 18:20:40 +01:00
$( MAKE) run-emissary-server EMISSARY_CMD = "--debug --config tmp/server.yml server auth create-token --role writer --output .emissary-token --tenant '00000000-0000-0000-0000-000000000000'"
2023-03-28 20:43:45 +02:00
AGENT_ID ?= 1
2024-02-26 18:20:40 +01:00
claim-agent :
go run ./cmd/server api agent claim --agent-thumbprint $( shell go run ./cmd/agent agent show-thumbprint)
2023-03-28 20:43:45 +02:00
load-sample-specs :
2024-02-26 18:20:40 +01:00
cat misc/spec-samples/app.emissary.cadoles.com.json | go run ./cmd/server api agent spec update -a $( AGENT_ID) --no-patch --spec-data - --spec-name app.emissary.cadoles.com
cat misc/spec-samples/proxy.emissary.cadoles.com.json | go run ./cmd/server api agent spec update -a $( AGENT_ID) --no-patch --spec-data - --spec-name proxy.emissary.cadoles.com
cat misc/spec-samples/mdns.emissary.cadoles.com.json | go run ./cmd/server api agent spec update -a $( AGENT_ID) --no-patch --spec-data - --spec-name mdns.emissary.cadoles.com
cat misc/spec-samples/uci.emissary.cadoles.com.json | go run ./cmd/server api agent spec update -a $( AGENT_ID) --no-patch --spec-data - --spec-name uci.emissary.cadoles.com
2023-03-31 14:29:10 +02:00
2023-08-25 17:56:28 +02:00
version : .mktools
@echo $( MKT_PROJECT_VERSION)
2023-04-06 20:56:43 +02:00
update-edge-lib :
git pull --rebase
2023-11-30 19:13:05 +01:00
go clean -modcache
GONOPROXY = forge.cadoles.com/arcad/edge GOPRIVATE = forge.cadoles.com/arcad/edge go get -v -u forge.cadoles.com/arcad/edge
2023-04-06 20:56:43 +02:00
go mod tidy
2023-04-11 12:06:16 +02:00
$( MAKE) test
2023-04-06 20:56:43 +02:00
git add go.mod go.sum
git commit -m "feat: update arcad/edge dependency"
2023-08-25 17:56:28 +02:00
git push
.PHONY : changelog
changelog : .mktools
2023-08-25 18:45:15 +02:00
$( MAKE) MKT_GIT_CHGLOG_ARGS = '--next-tag $(MKT_PROJECT_VERSION) --tag-filter-pattern $(MKT_PROJECT_VERSION_CHANNEL) --output CHANGELOG.md' mkt-changelog
2023-08-25 17:56:28 +02:00
.PHONY : mktools
mktools :
rm -rf .mktools
curl -q https://forge.cadoles.com/Cadoles/mktools/raw/branch/master/install.sh | $( SHELL)
.mktools :
$( MAKE) mktools
- i n c l u d e . m k t o o l s / * . m k