-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
223 lines (187 loc) · 8.65 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
######################################################################
# Build
######################################################################
TARGETS=starlight-proxy starlight-daemon ctr-starlight
COMMONENVVAR=GOOS=$(shell uname -s | tr A-Z a-z)
BUILDENVVAR=CGO_ENABLED=0
VERSION=$(shell git describe --tags --match "v*" | cut -d "-" -f 1 || echo "v0.0.0")
VERSIONNUMBER=$(shell echo $(VERSION) | sed 's/v//g')
COMPILEDATE=$(shell date +%Y%m%d)
.SILENT: install-systemd-service
######################################################################
# Build
######################################################################
.PHONY: build
build: starlight-proxy starlight-daemon ctr-starlight
.PHONY: test
test:
go mod tidy
go test -v ./...
.PHONY: starlight-proxy
starlight-proxy:
-mkdir ./out 2>/dev/null | true
go mod tidy
go build -o ./out/starlight-proxy ./cmd/starlight-proxy/main.go
.PHONY: starlight-daemon
starlight-daemon:
-mkdir ./out 2>/dev/null | true
go build -o ./out/starlight-daemon ./cmd/starlight-daemon/main.go
.PHONY: ctr-starlight
ctr-starlight:
-mkdir ./out 2>/dev/null | true
go build -o ./out/ctr-starlight ./cmd/ctr-starlight/main.go
.PHONY: ctr-starlight-for-alpine
ctr-starlight-for-alpine:
-mkdir ./out 2>/dev/null | true
go mod vendor
go mod tidy
$(COMMONENVVAR) $(BUILDENVVAR) go build -o ./out/ctr-starlight ./cmd/ctr-starlight/main.go
.PHONY: starlight-proxy-for-alpine
starlight-proxy-for-alpine:
-mkdir ./out 2>/dev/null | true
go mod vendor
go mod tidy
$(COMMONENVVAR) $(BUILDENVVAR) go build -o ./out/starlight-proxy ./cmd/starlight-proxy/main.go
.PHONY: helm-package
helm-package:
helm package ./demo/chart --version $(VERSIONNUMBER) -d /tmp
.PHONE: helm-template
helm-template:
@if [ ! -d ./sandbox ]; then mkdir ./sandbox; fi
@if [ ! -f ./sandbox/values.yaml ]; then cp ./demo/values.yaml ./sandbox/values.yaml; fi
@helm template ./demo/chart --version $(VERSIONNUMBER) -f ./sandbox/values.yaml
.PHONY: push-helm-package
push-helm-package:
helm push /tmp/starlight-$(VERSIONNUMBER).tgz oci://ghcr.io/mc256/starlight/
.PHONY: change-version-number
change-version-number:
sed -i 's/var Version = "0.0.0"/var Version = "$(VERSIONNUMBER)-$(COMPILEDATE)"/g' ./util/version.go
.PHONY: set-production
set-production:
sed -i 's/production = false/production = true/g' ./util/config.go
.PHONY: generate-changelog
generate-changelog:
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/ 2>/dev/null | true
sh -c ./demo/deb-package/generate-changelog.sh > ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/changelog
.PHONY: create-deb-package
create-deb-package: change-version-number set-production starlight-daemon ctr-starlight generate-changelog
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/ 2>/dev/null | true
cp -r ./demo/deb-package/debian ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/starlight/usr/bin/ 2>/dev/null | true
cp -r ./out/* ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/starlight/usr/bin/
sed -i 's/Standards-Version: 0.0.0/Standards-Version: $(VERSIONNUMBER)/g' ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/control
cd ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE) ; \
dh_systemd_enable; \
dh_systemd_start; \
dh_installdeb; \
dh_gencontrol; \
dh_md5sums; \
dh_builddeb
dpkg-deb --info ./sandbox/starlight_$(VERSIONNUMBER)_amd64.deb
.PHONY: install-protobuf
install-protobuf:
sudo apt update
sudo apt install protobuf-compiler -y
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
echo "You need to add $(go env GOPATH)/bin to your PATH"
.PHONY: update-protobuf
update-protobuf:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
client/api/daemon.proto
.PHONY: check-env-file
check-env-file:
@if [ ! -f .env ]; then cp .env_example .env; fi
.PHONY: copy-env-file
copy-env-file:
cp .env .env_example
sed -i 's/=.*/=/g' .env_example
######################################################################
###### Platform dependent build
.PHONY: create-deb-package.amd64
create-deb-package.amd64: create-deb-package
.PHONY: create-deb-package.armv6l
create-deb-package.armv6l: change-version-number set-production starlight-daemon ctr-starlight generate-changelog
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/ 2>/dev/null | true
cp -r ./demo/deb-package/debian ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/starlight/usr/bin/ 2>/dev/null | true
cp -r ./out/* ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/starlight/usr/bin/
sed -i 's/Standards-Version: 0.0.0/Standards-Version: $(VERSIONNUMBER)/g' ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/control
sed -i 's/Architecture: amd64/Architecture: armhf/g' ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/control
cd ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE) ; \
dh_systemd_enable; \
dh_systemd_start; \
dh_installdeb; \
dh_gencontrol; \
dh_md5sums; \
dh_builddeb
dpkg-deb --info ./sandbox/starlight_$(VERSIONNUMBER)_armhf.deb
.PHONY: create-deb-package.arm64
create-deb-package.arm64: change-version-number set-production starlight-daemon ctr-starlight generate-changelog
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/ 2>/dev/null | true
cp -r ./demo/deb-package/debian ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/
mkdir -p ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/starlight/usr/bin/ 2>/dev/null | true
cp -r ./out/* ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/starlight/usr/bin/
sed -i 's/Standards-Version: 0.0.0/Standards-Version: $(VERSIONNUMBER)/g' ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/control
sed -i 's/Architecture: amd64/Architecture: arm64/g' ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE)/debian/control
cd ./sandbox/starlight-$(VERSIONNUMBER)-$(COMPILEDATE) ; \
dh_systemd_enable; \
dh_systemd_start; \
dh_installdeb; \
dh_gencontrol; \
dh_md5sums; \
dh_builddeb
dpkg-deb --info ./sandbox/starlight_$(VERSIONNUMBER)_arm64.deb
.PHONY: upload-deb-package.amd64
upload-deb-package.amd64:
curl --form uploadfile='@./sandbox/starlight_$(VERSIONNUMBER)_amd64.deb' $(UPLOAD_URL)
#curl -X POST -u $(APT_UPLOAD_AUTH) -F starlight_$(VERSIONNUMBER)_amd64.deb='@./sandbox/starlight_$(VERSIONNUMBER)_amd64.deb' https://repo.yuri.moe/api/files/starlight
.PHONY: upload-deb-package.armv6l
upload-deb-package.armv6l:
curl --form uploadfile='@./sandbox/starlight_$(VERSIONNUMBER)_armhf.deb' $(UPLOAD_URL)
#curl -X POST -u $(APT_UPLOAD_AUTH) -F starlight_$(VERSIONNUMBER)_armhf.deb='@./sandbox/starlight_$(VERSIONNUMBER)_armhf.deb' https://repo.yuri.moe/api/files/starlight
.PHONY: upload-deb-package.amd64
upload-deb-package.arm64:
curl --form uploadfile='@./sandbox/starlight_$(VERSIONNUMBER)_arm64.deb' $(UPLOAD_URL)
#curl -X POST -u $(APT_UPLOAD_AUTH) -F starlight_$(VERSIONNUMBER)_arm64.deb='@./sandbox/starlight_$(VERSIONNUMBER)_arm64.deb' https://repo.yuri.moe/api/files/starlight
######################################################################
.PHONY: docker-buildx-multi-arch
docker-buildx-multi-arch:
docker buildx build \
--platform linux/amd64 \
--build-arg ARCH=amd64 \
--build-arg UPLOAD_URL=$(UPLOAD_URL) \
--build-arg APT_UPLOAD_AUTH=$(APT_UPLOAD_AUTH) \
--network=host \
-f ./demo/deb-package/Dockerfile .
docker buildx build \
--platform linux/arm/v7 \
--build-arg ARCH=armv6l \
--build-arg UPLOAD_URL=$(UPLOAD_URL) \
--build-arg APT_UPLOAD_AUTH=$(APT_UPLOAD_AUTH) \
--network=host \
-f ./demo/deb-package/Dockerfile .
docker buildx build \
--platform linux/arm64/v8 \
--build-arg ARCH=arm64 \
--build-arg UPLOAD_URL=$(UPLOAD_URL) \
--build-arg APT_UPLOAD_AUTH=$(APT_UPLOAD_AUTH) \
--network=host \
-f ./demo/deb-package/Dockerfile .
######################################################################
# Clean
######################################################################
clean:
-rm -rf ./out/*
######################################################################
# Install
######################################################################
install:
install ./out/*-* /usr/bin
install-systemd-service:
cp ./demo/deb-package/debian/starlight.service /lib/systemd/system/
systemctl daemon-reload
docker-image:
docker build -t registry.yuri.moe/public/starlight-proxy:latest -f Dockerfile --target starlight-proxy .
docker build -t registry.yuri.moe/public/starlight-cli:latest -f Dockerfile --target starlight-cli .