This repository has been archived by the owner on Oct 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
92 lines (76 loc) · 2.52 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
# SSH private key set up.
CURRENT_USER ?= $(shell whoami)
PRIVATE_KEY_FILE ?= id_ed25519
PRIVATE_KEY_PATH ?= github=${HOME}/.ssh/$(PRIVATE_KEY_FILE)
# Enable docker buildkit.
DOCKER_BUILDKIT = 1
# Project image repo.
IMAGE ?= ghcr.io/sb-im/sphinx
IMAGE_TAG ?= latest
# OCI platform.
OCI_PLATFORM ?= linux/arm64
# Docker-compose service.
SERVICE ?=
# Version info for binaries.
GIT_REVISION := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_TAG := $(shell git describe --tags)
# go build flags.
VPREFIX := github.com/SB-IM/sphinx/cmd/build
GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) -X $(VPREFIX).Version=$(GIT_TAG) -X $(VPREFIX).Revision=$(GIT_REVISION) -X $(VPREFIX).BuildUser=$(shell whoami)@$(shell hostname) -X $(VPREFIX).BuildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GO_FLAGS := -trimpath -ldflags "-extldflags \"-static\" -s -w $(GO_LDFLAGS)" -a -installsuffix cgo
# See: https://golang.org/doc/gdb#Introduction
DEBUG_GO_FLAGS := -trimpath -race -gcflags "all=-N -l" -ldflags "-extldflags \"-static\" $(GO_LDFLAGS)"
# go build with -race flag must enable cgo.
CGO_ENABLED := 0
DEBUG ?= false
ifeq ($(DEBUG), true)
IMAGE_TAG := debug
GO_FLAGS := $(DEBUG_GO_FLAGS)
CGO_ENABLED := 1
endif
ifeq ($(OCI_PLATFORM), linux/arm64)
IMAGE_TAG := $(IMAGE_TAG)-arm64
else ifeq ($(OCI_PLATFORM), linux/amd64)
IMAGE_TAG := $(IMAGE_TAG)-amd64
endif
.PHONY: run
run:
@DEBUG_MQTT_CLIENT=false go run -race ./cmd --debug $(SERVICE) -c config/config.dev.toml
sphinx:
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux go build $(GO_FLAGS) -o $@ ./cmd
sphinx-hookstream:
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm64 go build $(GO_FLAGS) -o $@ ./cmd
.PHONY: lint
lint:
@golangci-lint run ./...
# binfmt is the requisite for docker cross platform build.
binfmt:
@docker run --privileged --rm tonistiigi/binfmt --install all
.PHONY: image
image:
docker buildx build \
--build-arg DEBUG=$(DEBUG) \
--platform $(OCI_PLATFORM) \
--ssh $(PRIVATE_KEY_PATH) \
-t $(IMAGE):$(IMAGE_TAG) \
.
# Note: '--env-file' value is relative to '-f' value's directory.
.PHONY: up
up: down
@docker-compose -f up -d
.PHONY: down
down:
@docker-compose -f down --remove-orphans
.PHONY: logs
logs:
@docker-compose -f logs --no-log-prefix -f $(SERVICE)
.PHONY: run-mosquitto
run-mosquitto:
@docker run -d --rm --name mosquitto -p 1883:1883 -p 9001:9001 -v $$PWD/config/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto:2
.PHONY: stop-mosquitto
stop-mosquitto:
@docker stop mosquitto
.PHONY: clean
clean:
@rm -rf sphinx*