Makefile

92a519ae8ad2301869b17704fe0c334e1039e8b2
gitbay/Makefile history · blame · raw

58 lines · 2060 bytes

 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
 9HOST     ?= 155.138.253.199
10PORT     ?= 2222
11CLI_DEST ?= /opt/homebrew/bin/gitbay
12
13CROSS   := CGO_ENABLED=0 GOOS=linux GOARCH=amd64
14LDFLAGS := -s -w
15SERVER_BIN := dist/gitbayd-linux-amd64
16RUNNER_BIN := dist/gitbay-runner-linux-amd64
17
18.PHONY: help test server cli deploy deploy-runner preflight
19
20help:
21	@sed -n 's/^#   //p' $(MAKEFILE_LIST)
22
23test:
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.
28preflight:
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
35server:
36	@echo "==> building $(SERVER_BIN)"
37	$(CROSS) go build -trimpath -ldflags='$(LDFLAGS)' -o $(SERVER_BIN) ./cmd/gitbayd
38
39cli:
40	@echo "==> installing CLI to $(CLI_DEST)"
41	go build -o $(CLI_DEST) ./cmd/gitbay
42
43deploy: 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
49deploy-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'