-
Notifications
You must be signed in to change notification settings - Fork 61
/
Makefile
158 lines (125 loc) · 4.74 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
APPNAME=$(shell basename $(shell go list))
VERSION?=snapshot
COMMIT=$(shell git rev-parse --verify HEAD)
DATE?=$(shell date +%FT%T%z)
RELEASE?=0
GOPATH?=$(shell go env GOPATH)
GO_LDFLAGS+=-X main.appName=$(APPNAME)
GO_LDFLAGS+=-X main.buildVersion=$(VERSION)
GO_LDFLAGS+=-X main.buildCommit=$(COMMIT)
GO_LDFLAGS+=-X main.buildDate=$(DATE)
ifeq ($(RELEASE), 1)
# Strip debug information from the binary
GO_LDFLAGS+=-s -w
endif
GO_LDFLAGS:=-ldflags="$(GO_LDFLAGS)"
DOCKER_IMAGE=ghcr.io/smocker-dev/smocker
# See: https://docs.docker.com/engine/reference/commandline/tag/#extended-description
# A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes.
# A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
DOCKER_TAG:=$(shell echo $(VERSION) | tr -cd '[:alnum:]_.-')
IS_SEMVER:=$(shell echo $(DOCKER_TAG) | grep -E "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$$")
LEVEL=debug
SUITE=*.yml
.PHONY: default
default: start
REFLEX=$(GOPATH)/bin/reflex
$(REFLEX):
go install github.com/cespare/reflex@latest
GOLANGCILINTVERSION:=1.54.2
GOLANGCILINT=$(GOPATH)/bin/golangci-lint
$(GOLANGCILINT):
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v$(GOLANGCILINTVERSION)
VENOMVERSION:=v1.0.0-rc.6
VENOM=$(GOPATH)/bin/venom
$(VENOM):
go install github.com/ovh/venom/cmd/venom@$(VENOMVERSION)
GOCOVMERGE=$(GOPATH)/bin/gocovmerge
$(GOCOVMERGE):
go install github.com/wadey/gocovmerge@latest
CADDY=$(GOPATH)/bin/caddy
$(CADDY):
cd /tmp; go get github.com/caddyserver/caddy/v2/...
.PHONY: persistence
persistence:
rm -rf ./sessions || true
cp -r tests/sessions sessions
.PHONY: start
start: $(REFLEX) persistence
$(REFLEX) --start-service \
--decoration='none' \
--regex='\.go$$' \
--inverse-regex='^vendor|node_modules|.cache/' \
-- go run $(GO_LDFLAGS) main.go --log-level=$(LEVEL) --static-files ./build/client --persistence-directory ./sessions
.PHONY: build
build:
go build -trimpath $(GO_LDFLAGS) -o ./build/$(APPNAME)
.PHONY: lint
lint: $(GOLANGCILINT)
$(GOLANGCILINT) run
.PHONY: format
format:
gofmt -s -w .
.PHONY: test
test:
mkdir -p coverage
go test -v -race -coverprofile=coverage/test-cover.out ./server/...
PID_FILE=/tmp/$(APPNAME).test.pid
.PHONY: test-integration
test-integration: $(VENOM) check-default-ports persistence
mkdir -p coverage
go test -race -coverpkg="./..." -c . -o $(APPNAME).test
SMOCKER_PERSISTENCE_DIRECTORY=./sessions ./$(APPNAME).test -test.coverprofile=coverage/test-integration-cover.out >/dev/null 2>&1 & echo $$! > $(PID_FILE)
sleep 5
$(VENOM) run tests/features/$(SUITE)
kill `cat $(PID_FILE)` 2> /dev/null || true
.PHONY: start-integration
start-integration: $(VENOM)
$(VENOM) run tests/features/$(SUITE)
coverage/test-cover.out:
$(MAKE) test
coverage/test-integration-cover.out:
$(MAKE) test-integration
.PHONY: coverage
coverage: $(GOCOVMERGE) coverage/test-cover.out coverage/test-integration-cover.out
$(GOCOVMERGE) coverage/test-cover.out coverage/test-integration-cover.out > coverage/cover.out
.PHONY: clean
clean:
rm -rf ./build ./coverage
.PHONY: build-docker
build-docker:
docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --tag $(DOCKER_IMAGE):latest .
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE):$(DOCKER_TAG)
.PHONY: start-docker
start-docker: check-default-ports
docker run -d -p 8080:8080 -p 8081:8081 --name $(APPNAME) $(DOCKER_IMAGE):$(DOCKER_TAG)
.PHONY: check-default-ports
check-default-ports:
@lsof -i:8080 > /dev/null && (echo "Port 8080 already in use"; exit 1) || true
@lsof -i:8081 > /dev/null && (echo "Port 8081 already in use"; exit 1) || true
.PHONY: optimize
optimize:
find client/assets/ -iname '*.png' -print0 | xargs -0 -n1 optipng -strip all
find docs/ -iname '*.png' -print0 | xargs -0 -n1 optipng -strip all
# The following targets are only available for CI usage
build/smocker.tar.gz:
$(MAKE) build
yarn install --frozen-lockfile --ignore-scripts
yarn build
cd build/; tar -czvf smocker.tar.gz *
.PHONY: release
release: build/smocker.tar.gz
.PHONY: start-release
start-release: clean build/smocker.tar.gz
cd build/; ./smocker --config-base-path=/smocker/
.PHONY: start-caddy
start-caddy: $(CADDY)
$(CADDY) run
.PHONY: deploy-docker
deploy-docker:
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use
ifdef IS_SEMVER
docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(DOCKER_IMAGE):latest .
endif
docker buildx build --push --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag $(DOCKER_IMAGE):$(DOCKER_TAG) .