Commit 728618a5da
Verified · cmc
Makefile added +58
| @@ -0,0 +1,58 @@ | ||
| 1 | # gitbay build and deploy. | |
| 2 | # | |
| 3 | # make test run the full suite | |
| 4 | # make deploy build the server, push it to HOST, rebuild the local CLI | |
| 5 | # make deploy-runner update the CI runner on HOST (only when cmd/gitbay-runner changed) | |
| 6 | # | |
| 7 | # Override the target host with: make deploy HOST=example.org PORT=22 | |
| 8 | ||
| 9 | HOST ?= 155.138.253.199 | |
| 10 | PORT ?= 2222 | |
| 11 | CLI_DEST ?= /opt/homebrew/bin/gitbay | |
| 12 | ||
| 13 | CROSS := CGO_ENABLED=0 GOOS=linux GOARCH=amd64 | |
| 14 | LDFLAGS := -s -w | |
| 15 | SERVER_BIN := dist/gitbayd-linux-amd64 | |
| 16 | RUNNER_BIN := dist/gitbay-runner-linux-amd64 | |
| 17 | ||
| 18 | .PHONY: help test server cli deploy deploy-runner preflight | |
| 19 | ||
| 20 | help: | |
| 21 | @sed -n 's/^# //p' $(MAKEFILE_LIST) | |
| 22 | ||
| 23 | test: | |
| 24 | go test ./... -count=1 | |
| 25 | ||
| 26 | # Fail in seconds on an unreachable host or a wedged ssh-agent, rather | |
| 27 | # than hanging on a credential prompt mid-deploy. | |
| 28 | preflight: | |
| 29 | @echo "==> checking $(HOST):$(PORT)" | |
| 30 | @ssh -p $(PORT) -o BatchMode=yes -o ConnectTimeout=10 root@$(HOST) true \ | |
| 31 | || { echo "cannot reach root@$(HOST):$(PORT) without a prompt." >&2; \ | |
| 32 | echo "if ssh-add -l says 'invalid format', the agent is wedged: killall ssh-agent" >&2; \ | |
| 33 | exit 1; } | |
| 34 | ||
| 35 | server: | |
| 36 | @echo "==> building $(SERVER_BIN)" | |
| 37 | $(CROSS) go build -trimpath -ldflags='$(LDFLAGS)' -o $(SERVER_BIN) ./cmd/gitbayd | |
| 38 | ||
| 39 | cli: | |
| 40 | @echo "==> installing CLI to $(CLI_DEST)" | |
| 41 | go build -o $(CLI_DEST) ./cmd/gitbay | |
| 42 | ||
| 43 | deploy: preflight server | |
| 44 | @echo "==> pushing to $(HOST) (~24MB, then restart)" | |
| 45 | ./deploy/install.sh $(HOST) $(PORT) | |
| 46 | @$(MAKE) --no-print-directory cli | |
| 47 | @echo "==> deployed $$(git rev-parse --short HEAD)" | |
| 48 | ||
| 49 | deploy-runner: preflight | |
| 50 | @echo "==> building $(RUNNER_BIN)" | |
| 51 | $(CROSS) go build -trimpath -ldflags='$(LDFLAGS)' -o $(RUNNER_BIN) ./cmd/gitbay-runner | |
| 52 | @echo "==> pushing runner to $(HOST)" | |
| 53 | scp -P $(PORT) $(RUNNER_BIN) root@$(HOST):/usr/local/bin/gitbay-runner.new | |
| 54 | ssh -p $(PORT) root@$(HOST) 'set -eu; \ | |
| 55 | chmod 755 /usr/local/bin/gitbay-runner.new; \ | |
| 56 | mv /usr/local/bin/gitbay-runner.new /usr/local/bin/gitbay-runner; \ | |
| 57 | systemctl restart gitbay-runner; \ | |
| 58 | systemctl --no-pager --lines=3 status gitbay-runner' | |