-
Notifications
You must be signed in to change notification settings - Fork 59
/
Makefile
146 lines (129 loc) · 3.92 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
PWD := $(shell pwd)
GOPATH := $(shell go env GOPATH)
VERSION := $(shell git describe --tags --always)
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)
BUILD_LDFLAGS := -s -w
BUILD_LDFLAGS += -X github.com/target/flottbot/version.Version=${VERSION}
GOLANGCI_LINT_VERSION := "v1.61.0"
PACKAGES := $(shell go list ./... | grep -v /config-example/)
PLATFORM := "linux/amd64,linux/arm64"
DOCKER_IMAGE ?= "target/flottbot"
DOCKER_FLAVORS ?= golang ruby python
.PHONY: all
all: test build
# ┌┬┐┌─┐┌─┐┌┬┐
# │ ├┤ └─┐ │
# ┴ └─┘└─┘ ┴
.PHONY: validate
validate: getdeps fmt vet lint tidy
.PHONY: getdeps
getdeps:
@mkdir -p ${GOPATH}/bin
@which golangci-lint 1>/dev/null || \
(echo "Installing golangci-lint" && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_LINT_VERSION))
.PHONY: lint
lint:
@echo "Running $@ check"
@golangci-lint run
.PHONY: fmt
fmt:
@echo "Running $@ check"
@go fmt ./...
.PHONY: vet
vet:
@echo "Running $@ check"
@go vet ./...
.PHONY: tidy
tidy:
@echo "Running $@"
@go mod tidy
.PHONY: test
test:
@echo "Running unit tests"
@go test ./...
.PHONY: test-coverage
test-coverage:
@echo "Running unit tests with coverage"
@go test -v -covermode=count -coverpkg=$(PACKAGES) -coverprofile=coverage.out ./...
.PHONY: clean
clean: validate
@echo "Running $@ tasks"
-rm -v ./flottbot*
-rm -v ./debug #Not created
# ┌┐ ┬ ┬┬┬ ┌┬┐
# ├┴┐│ │││ ││
# └─┘└─┘┴┴─┘─┴┘
.PHONY: build
build: clean
@echo "Building flottbot binary to './flottbot'"
@go build -a -ldflags '$(BUILD_LDFLAGS)' -o $(PWD)/flottbot ./cmd/flottbot
# ┌┬┐┌─┐┌─┐┬┌─┌─┐┬─┐
# │││ ││ ├┴┐├┤ ├┬┘
# ─┴┘└─┘└─┘┴ ┴└─┘┴└─
.PHONY: docker-login
docker-login:
ifndef DOCKER_USERNAME
$(error DOCKER_USERNAME not set)
else ifndef DOCKER_PASSWORD
$(error DOCKER_PASSWORD not set)
endif
@echo "Logging into docker hub"
@echo "$$DOCKER_PASSWORD" | docker login -u $$DOCKER_USERNAME --password-stdin
.PHONY: docker-build-push-latest
docker-build-push-latest: docker-login
@echo "Building and pushing latest to docker hub..."
@echo "Building and pushing $(DOCKER_IMAGE):latest"
@docker buildx build \
--progress=plain \
--build-arg "VERSION=$(VERSION)" \
--platform $(PLATFORM) \
--file "./docker/Dockerfile" \
--tag $(DOCKER_IMAGE):latest \
--push .
@for flavor in $(DOCKER_FLAVORS); do \
echo "Building and pushing $(DOCKER_IMAGE):$$flavor"; \
docker buildx build \
--progress=plain \
--build-arg "VERSION=$(VERSION)" \
--platform $(PLATFORM) \
--file "./docker/Dockerfile.$$flavor" \
--tag $(DOCKER_IMAGE):$$flavor \
--push .; \
done
.PHONY: docker-build-push
docker-build-push: docker-login
@echo "Building and pushing $(VERSION) to docker hub..."
@echo "Building and pushing $(DOCKER_IMAGE):$(VERSION)"
@docker buildx build \
--progress=plain \
--build-arg "VERSION=$(VERSION)" \
--platform $(PLATFORM) \
--file "./docker/Dockerfile" \
--tag $(DOCKER_IMAGE):$(VERSION) \
--tag $(DOCKER_IMAGE):latest \
--push .
@for flavor in $(DOCKER_FLAVORS); do \
echo "Building and pushing $(DOCKER_IMAGE):$$flavor-$(VERSION)"; \
docker buildx build \
--progress=plain \
--build-arg "VERSION=$(VERSION)" \
--platform $(PLATFORM) \
--file "./docker/Dockerfile.$$flavor" \
--tag $(DOCKER_IMAGE):$$flavor-$(VERSION) \
--tag $(DOCKER_IMAGE):$$flavor \
--push .; \
done
# ┬─┐┬ ┬┌┐┌
# ├┬┘│ ││││
# ┴└─└─┘┘└┘
.PHONY: run
run: build
@echo "Starting flottbot"
./flottbot
.PHONY: run-docker
run-docker: docker
@echo "Starting flottbot docker image"
@docker run -it --rm --name myflottbot -v "$$PWD"/config:/config --env-file .env $(DOCKER_IMAGE):latest /flottbot