-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
209 lines (154 loc) · 5.42 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
.PHONY: all clean \
get-version get-current-sha get-project-name \
check-tool-cargo check-tool-cargo-watch \
setup run run-tls watch cargo-clean \
build build-watch build-release build-test build-test-watch \
test test-unit test-unit-debug test-int test-int-debug test-e2e test-e2e-debug \
release-prep release-publish \
image image-publish image-release registry-login \
builer-image builer-image-publish \
tls-clean tls-credentials tls-run \
example example-tls
all: build
clean: cargo-clean tls-clean
PROJECT_NAME ?= Neo-Rust
VERSION=$(shell perl -ne '/version\s+=\s+"([0-9|\.]+)"$$/ && print $$1 and last' Cargo.toml)
CURRENT_SHA ?= $(shell $(GIT) rev-parse --short HEAD)
BUILD_TARGET ?= x86_64-unknown-linux-musl
CARGO_BUILD_FLAGS ?= --target $(BUILD_TARGET)
GIT_REMOTE ?= origin
DOCKER ?= docker
CARGO ?= cargo
CARGO_WATCH ?= cargo-watch
SHA256SUM ?= sha256sum
SHA1SUM ?= sha1sum
GIT ?= git
RELEASES_DIR ?= releases
RELEASE_BINARY_NAME ?= Neo
CARGO_TARGET_DIR ?= target
RELEASE_BUILT_BIN_PATH = $(CARGO_TARGET_DIR)/$(BUILD_TARGET)/release/$(RELEASE_BINARY_NAME)
check-tool-docker:
ifeq (, $(shell which $(DOCKER)))
$(error "`docker` is not available please install docker (https://docker.com)")
endif
check-tool-cargo:
ifeq (, $(shell which $(CARGO)))
$(error "`cargo` is not available please install cargo (https://github.com/rust-lang/cargo/)")
endif
check-tool-cargo-watch:
ifeq (, $(shell which $(CARGO_WATCH)))
$(error "`cargo-watch` is not available please install cargo-watch (https://github.com/passcod/cargo-watch)")
endif
check-tool-sha256sum:
ifeq (, $(shell which $(SHA256SUM)))
$(error "`sha256sum` is not available please install sha256sum")
endif
check-tool-sha1sum:
ifeq (, $(shell which $(SHA1SUM)))
$(error "`sha1sum` is not available please install sha1sum")
endif
get-version:
@echo -e -n ${VERSION}
get-current-sha:
@echo -e -n ${CURRENT_SHA}
get-project-name:
@echo -e -n ${PROJECT_NAME}
setup:
@echo "[info] installing rust utilities..."
$(CARGO) install cargo-watch
fmt:
$(CARGO) fmt
cargo-clean: check-tool-cargo
$(CARGO) clean
build: check-tool-cargo
$(CARGO) build $(CARGO_BUILD_FLAGS)
build-release: check-tool-cargo check-tool-sha1sum check-tool-sha256sum
$(CARGO) build $(CARGO_BUILD_FLAGS) --release
cp $(RELEASE_BUILT_BIN_PATH) $(RELEASES_DIR)/$(RELEASE_BINARY_NAME)
release-prep: build-release check-tool-sha1sum check-tool-sha256sum
$(SHA256SUM) $(RELEASES_DIR)/${RELEASE_BINARY_NAME} > $(RELEASES_DIR)/${RELEASE_BINARY_NAME}.sha256sum
$(SHA1SUM) $(RELEASES_DIR)/${RELEASE_BINARY_NAME} > $(RELEASES_DIR)/${RELEASE_BINARY_NAME}.sha1sum
$(GIT) add .
$(GIT) commit -am "Release v$(VERSION)"
$(GIT) tag v$(VERSION) HEAD
release-publish:
$(GIT) push $(GIT_REMOTE) v$(VERSION)
build-test: check-tool-cargo
$(CARGO) test $(CARGO_BUILD_FLAGS) --no-run
install: check-tool-cargo
$(CARGO) install --path . $(RELEASE_BINARY_NAME)
run:
$(CARGO) run
test: test-unit test-int test-e2e
test-unit:
$(CARGO) test $(CARGO_BUILD_FLAGS)
test-unit-debug:
$(CARGO) test $(CARGO_BUILD_FLAGS) -- --nocapture
test-int:
$(CARGO) test $(CARGO_BUILD_FLAGS) -- --ignored _int
test-int-debug:
$(CARGO) test $(CARGO_BUILD_FLAGS) -- --ignored _int --nocapture
test-e2e: build-release
$(CARGO) test $(CARGO_BUILD_FLAGS) -- --ignored _e2e
test-e2e-debug: build-release
$(CARGO) test $(CARGO_BUILD_FLAGS) -- --ignored _e2e --nocapture
build-watch: check-tool-cargo check-tool-cargo-watch
$(CARGO_WATCH) -x "build $(CARGO_BUILD_FLAGS)" --watch src
build-test-watch: check-tool-cargo check-tool-cargo-watch
$(CARGO_WATCH) -x "test $(CARGO_BUILD_FLAGS)" --watch src --watch tests
#############
# Packaging #
#############
REGISTRY_PATH = registry.gitlab.com/mrman/$(PROJECT_NAME)
IMAGE_NAME ?= cli
IMAGE_FULL_NAME=${REGISTRY_PATH}/${IMAGE_NAME}:v${VERSION}
IMAGE_FULL_NAME_SHA=${REGISTRY_PATH}/${IMAGE_NAME}:v${VERSION}-${CURRENT_SHA}
BUILDER_IMAGE_NAME ?= builder
BUILDER_FULL_NAME = ${REGISTRY_PATH}/${BUILDER_IMAGE_NAME}:v${VERSION}
registry-login:
cat infra/secrets/ci-deploy-token-password.secret | \
docker login \
-u $(shell cat infra/secrets/ci-deploy-token-username.secret) \
--password-stdin \
registry.gitlab.com
image:
docker build -f infra/docker/Dockerfile -t $(IMAGE_FULL_NAME_SHA) .
image-publish: check-tool-docker
$(DOCKER) push ${IMAGE_FULL_NAME_SHA}
image-release:
$(DOCKER) tag $(IMAGE_FULL_NAME_SHA) $(IMAGE_FULL_NAME)
$(DOCKER) push $(IMAGE_FULL_NAME)
builder-image:
docker build -f infra/docker/builder.Dockerfile -t $(BUILDER_FULL_NAME) .
builder-image-publish:
docker push $(BUILDER_FULL_NAME)
###########
# Testing #
###########
OPENSSL ?= openssl
TLS_KEY_PATH ?= $(realpath ./tls.key)
TLS_CERT_PATH ?= $(realpath ./tls.crt)
tls-clean:
rm -f $(TLS_KEY_PATH)
rm -f $(TLS_CERT_PATH)
tls-credentials:
@if [ ! -f "$(TLS_KEY_PATH)" ] && [ ! -f "$(TLS_CERT_PATH)" ] ; then \
echo "[info] neither TLS key (@ $(TLS_KEY_PATH)) or TLS cert (@ $(TLS_CERT_PATH)) exist, creating..."; \
$(OPENSSL) req -nodes -new -x509 \
-keyout $(TLS_KEY_PATH) \
-out $(TLS_CERT_PATH) \
-subj '/CN=Neo.localhost' \
-days 3650; \
else \
echo "[info] TLS key (@ $(TLS_KEY_PATH)) and TLS cert (@ $(TLS_CERT_PATH)) already exist"; \
fi
tls-run:
TLS_KEY=$(TLS_KEY_PATH) TLS_CERT=$(TLS_CERT_PATH) $(CARGO) run
###########
# Example #
###########
EXAMPLE_FILE_PATH= ./example.html
example:
FILE=$(EXAMPLE_FILE_PATH) $(CARGO) run
example-tls:
FILE=$(EXAMPLE_FILE_PATH) $(MAKE) tls-run