-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
110 lines (81 loc) · 3.69 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
FEDBOX_HOSTNAME ?= fedbox.git
STORAGE ?= all
ENV ?= dev
PROJECT ?= fedbox
LDFLAGS ?= -X main.version=$(VERSION)
BUILDFLAGS ?= -a -ldflags '$(LDFLAGS)'
TEST_FLAGS ?= -count=1
M4 = /usr/bin/m4
M4_FLAGS =
DESTDIR ?= /
INSTALL_PREFIX ?= usr/local
GO ?= go
APPSOURCES := $(wildcard ./*.go activitypub/*.go internal/*/*.go storage/*/*.go)
ASSETFILES := $(wildcard templates/*)
TAGS := $(ENV) storage_$(STORAGE)
export CGO_ENABLED=0
ifeq ($(shell git describe --always > /dev/null 2>&1 ; echo $$?), 0)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD | tr '/' '-')
HASH=$(shell git rev-parse --short HEAD)
VERSION ?= $(shell printf "%s-%s" "$(BRANCH)" "$(HASH)")
endif
ifeq ($(shell git describe --tags > /dev/null 2>&1 ; echo $$?), 0)
VERSION ?= $(shell git describe --tags | tr '/' '-')
endif
ifneq ($(ENV),dev)
LDFLAGS += -s -w -extldflags "-static"
BUILDFLAGS += -trimpath
endif
BUILD := $(GO) build $(BUILDFLAGS)
TEST := $(GO) test $(BUILDFLAGS)
.PHONY: all run clean test coverage integration install download help
.DEFAULT_GOAL := help
help: ## Help target that shows this message.
@sed -rn 's/^([^:]+):.*[ ]##[ ](.+)/\1:\2/p' $(MAKEFILE_LIST) | column -ts: -l2
all: fedbox fedboxctl ##
download: go.sum ## Downloads dependencies and tidies the go.mod file.
go.sum: go.mod
$(GO) mod download all
$(GO) mod tidy
fedbox: bin/fedbox ## Builds the main FedBOX service binary.
bin/fedbox: go.mod cmd/fedbox/main.go $(APPSOURCES)
$(BUILD) -tags "$(TAGS)" -o $@ ./cmd/fedbox/main.go
systemd/fedbox.service: systemd/fedbox.service.in ## Creates a systemd service file for the FedBOX service.
$(M4) $(M4_FLAGS) -DWORKING_DIR=$(STORAGE_PATH) $< >$@
systemd/fedbox.socket: systemd/fedbox.socket.in ## Creates a socket systemd unit file to accompany the service file.
$(M4) $(M4_FLAGS) -DLISTEN_HOST=$(LISTEN_HOST) -DLISTEN_PORT=$(LISTEN_PORT) $< >$@
fedboxctl: bin/fedboxctl ## Builds the control binary for the FedBOX service.
bin/fedboxctl: go.mod cmd/control/main.go $(APPSOURCES)
$(BUILD) -tags "$(TAGS)" -o $@ ./cmd/control/main.go
run: fedbox ## Runs the FedBOX binary.
@./bin/fedbox
clean: ## Cleanup the build workspace.
-$(RM) bin/*
$(MAKE) -C tests $@
test: TEST_TARGET := . ./{activitypub,storage,internal}/...
test: download ## Run unit tests for the service.
$(TEST) $(TEST_FLAGS) -tags "$(TAGS)" $(TEST_TARGET)
coverage: TEST_TARGET := .
coverage: TEST_FLAGS += -covermode=count -coverprofile $(PROJECT).coverprofile
coverage: test ## Run unit tests for the service with coverage.
integration: download ## Run integration tests for the service.
$(MAKE) -C tests $@
$(FEDBOX_HOSTNAME).key $(FEDBOX_HOSTNAME).crt:
openssl req -subj "/C=AQ/ST=Omond/L=Omond/O=*.$(FEDBOX_HOSTNAME)/OU=none/CN=*.$(FEDBOX_HOSTNAME)" -newkey rsa:2048 -sha256 -keyout $(FEDBOX_HOSTNAME).key -nodes -x509 -days 365 -out $(FEDBOX_HOSTNAME).crt
$(FEDBOX_HOSTNAME).pem: $(FEDBOX_HOSTNAME).key $(FEDBOX_HOSTNAME).crt
cat $(FEDBOX_HOSTNAME).key $(FEDBOX_HOSTNAME).crt > $(FEDBOX_HOSTNAME).pem
cert: $(FEDBOX_HOSTNAME).key ## Create a certificate.
install: ./bin/fedbox systemd/fedbox.service systemd/fedbox.socket $(FEDBOX_HOSTNAME).crt $(FEDBOX_HOSTNAME).key ## Install the application.
useradd -m -s /bin/false -u 2000 fedbox
install bin/fedbox $(DESTDIR)$(INSTALL_PREFIX)/bin
install -m 644 -o fedbox systemd/fedbox.service $(DESTDIR)/etc/systemd/system
install -m 644 -o fedbox systemd/fedbox.socket $(DESTDIR)/etc/systemd/system
install -m 600 -o fedbox .env.prod $(STORAGE_PATH)
install -m 600 -o $(FEDBOX_HOSTNAME).crt $(STORAGE_PATH)
install -m 600 -o $(FEDBOX_HOSTNAME).key $(STORAGE_PATH)