-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
190 lines (165 loc) · 8.26 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
UNAME:=$(shell uname|sed 's/.*/\u&/')
OS:=$(shell echo $(GOOS)| sed 's/.*/\u&/')
PKG=$(shell basename $$(pwd))
colon := :
ifeq ($(BITBUCKET_BUILD_NUMBER),)
TYPE:="Local"
else
TYPE:=$(BITBUCKET_BUILD_NUMBER)
endif
all: sprout grlx farmer
sprout: cmd/sprout/*.go
ifeq ($(GOOS),)
@printf "OS not specified, defaulting to: \e[33m$(UNAME)\e[39m\n"
else
@printf "OS specified: \e[33m$$(echo $$GOOS | sed 's/.*/\u&/' )\e[39m\n"
endif
@echo "Building..."
@export GOARCH=amd64; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/sprout" ./cmd/sprout/*.go
@printf "\e[32mSuccess!\e[39m\n"
grlx: cmd/grlx/*.go
ifeq ($(GOOS),)
@printf "OS not specified, defaulting to: \e[33m$(UNAME)\e[39m\n"
else
@printf "OS specified: \e[33m$$(echo $$GOOS | sed 's/.*/\u&/' )\e[39m\n"
endif
@echo "Building..."
@export GOARCH=amd64; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export BuildTime=`date -u +%Y%m%d.%H%M%S`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/grlx" ./cmd/grlx/main.go
@printf "\e[32mSuccess!\e[39m\n"
farmer: cmd/farmer/*.go
ifeq ($(GOOS),)
@printf "OS not specified, defaulting to: \e[33m$(UNAME)\e[39m\n"
else
@printf "OS specified: \e[33m$$(echo $$GOOS | sed 's/.*/\u&/' )\e[39m\n"
endif
@echo "Building..."
@export GOARCH=amd64; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export BuildTime=`date -u +%Y%m%d.%H%M%S`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/farmer" ./cmd/farmer/main.go
@printf "\e[32mSuccess!\e[39m\n"
all-arches-farmer: farmer
@mkdir -p bin/arches
for arch in amd64 386 arm arm64 ; do \
export GOOS=linux; \
export GOARCH=$$arch; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export BuildTime=`date -u +%Y%m%d.%H%M%S`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/farmer" ./cmd/farmer/main.go &&\
printf "\e[32mSuccess!\e[39m\n" ;\
mkdir -p bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest ;\
cp bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/farmer bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest/farmer ;\
done
all-arches-sprout: sprout
@mkdir -p bin/arches
for arch in amd64 386 arm arm64 ; do \
export GOOS=linux; \
export GOARCH=$$arch; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export BuildTime=`date -u +%Y%m%d.%H%M%S`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/sprout" ./cmd/sprout/*.go &&\
printf "\e[32mSuccess!\e[39m\n" ;\
mkdir -p bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest ;\
cp bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/sprout bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest/sprout ;\
done
all-arches-grlx: grlx
@mkdir -p bin/arches
for arch in amd64 386 arm arm64 ; do \
export GOOS=linux; \
export GOARCH=$$arch; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export BuildTime=`date -u +%Y%m%d.%H%M%S`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/grlx" ./cmd/grlx/main.go &&\
printf "\e[32mSuccess!\e[39m\n" ;\
mkdir -p bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest ;\
cp bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/grlx bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest/grlx ;\
done
for arch in amd64 arm64 ; do \
export GOOS=darwin; \
export GOARCH=$$arch; \
export BITBUCKET_BUILD_NUMBER=$(TYPE);\
export CGO_ENABLED=0;\
export GitCommit=`git rev-parse HEAD | cut -c -7`;\
export BuildTime=`date -u +%Y%m%d.%H%M%S`;\
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
go build -ldflags "-X main.GitCommit=$$GitCommit -X main.Tag=$$GitTag" -o "bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/grlx" ./cmd/grlx/main.go &&\
printf "\e[32mSuccess!\e[39m\n" ;\
mkdir -p bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest ;\
cp bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/"$$(printf $$GitTag)"/grlx bin/arches/"$$(printf $$GOOS)"/"$$(printf $$GOARCH)"/latest/grlx ;\
done
github: all-arches-farmer all-arches-sprout all-arches-grlx
@printf "Creating GitHub release...\n"
mkdir -p bin/github
for arch in amd64 386 arm arm64 ; do \
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
cp bin/arches/linux/$$arch/$$(printf $$GitTag)/farmer bin/github/farmer-$$(printf $$GitTag)-linux-$$(printf $$arch);\
done
for arch in amd64 386 arm arm64 ; do \
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
cp bin/arches/linux/$$arch/$$(printf $$GitTag)/sprout bin/github/sprout-$$(printf $$GitTag)-linux-$$(printf $$arch);\
done
for arch in amd64 arm64 ; do \
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
cp bin/arches/darwin/$$arch/$$(printf $$GitTag)/grlx bin/github/grlx-$$(printf $$GitTag)-darwin-$$(printf $$arch);\
done
for arch in amd64 386 arm arm64 ; do \
export GitTag=$$(TAG=`git tag --contains $$(git rev-parse HEAD) | sort -R | tr '\n' ' '`; if [ "$$(printf "$$TAG")" ]; then printf "$$TAG"; else printf "undefined"; fi);\
cp bin/arches/linux/$$arch/$$(printf $$GitTag)/grlx bin/github/grlx-$$(printf $$GitTag)-linux-$$(printf $$arch);\
done
release: all-arches-farmer all-arches-sprout all-arches-grlx github
@printf "\e[32mSuccess!\e[39m\n"
clean:
@printf "Cleaning up \e[32mmain\e[39m...\n"
docker-compose down || true
yes| docker-compose rm || true
docker rmi grlx/sprout:latest || true
docker rmi grlx/farmer:latest || true
rm -f ~/.config/grlx/tls-rootca.pem
rm -f main bin/grlx bin/farmer bin/sprout
rm -r bin/arches bin/github || true
install: clean all
mv bin/grlx bin/farmer bin/sprout "$$GOPATH/bin/"
docker:
docker build -t grlx/farmer . -f docker/farmer.dockerfile
docker build -t grlx/sprout . -f docker/sprout.dockerfile
dcu:
docker-compose down || true
docker-compose rm
rm -f ~/.config/grlx/tls-rootca.pem
docker-compose up
test: clean
docker-compose build
docker-compose up -d
@printf "\e[31mNo tests defined!\e[39m\n"
docker compose down
@exit 1
.PHONY: all
.PHONY: clean
.PHONY: docker
.PHONY: install
.PHONY: test
.PHONY: update
.PHONY: release