-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
209 lines (165 loc) · 5.62 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
SHELL:=/usr/bin/env bash
#
# Directories
#
ROOT_DIR := .
DOTNET_ROOT_DIR := ${ROOT_DIR}/modules/dotnet
DOTNET_BUILD_DIR := ${DOTNET_ROOT_DIR}/bin/Debug/net9.0/wasi-wasm/AppBundle
RUST_ROOT_DIR := ${ROOT_DIR}/modules/rust
RUST_BUILD_DIR := ${ROOT_DIR}/target/wasm32-wasi/debug
ENVOY_ROOT_DIR := ${ROOT_DIR}/proxies/envoy
#
# Tools
#
DOTNET_IMAGE_NAME := envoy:dotnet
DOTNET_PROJECT_FILE := ${DOTNET_ROOT_DIR}/Envoy.csproj
RUST_IMAGE_NAME := envoy:rust
RUST_MANIFEST_FILE := ${RUST_ROOT_DIR}/Cargo.toml
ENVOY_NAME := envoy
#
# Aliases
#
bdn: build-dotnet
brs: build-rust
bdk: build-docker
tdn: test-dotnet
trs: test-rust
vdn: validate-dotnet
vrs: validate-rust
cdn: clean-dotnet
crs: clean-rust
cdk: clean-docker
sdn: start-dotnet
srs: start-rust
pdn: stop-dotnet
prs: stop-rust
lcn: list-containers
lim: list-images
idn: inspect-dotnet
irs: inspect-rust
hdn: shell-dotnet
hrs: shell-rust
ldn: logs-dotnet
lrs: logs-rust
rdn: run-dotnet
rrs: run-rust
#
# Targets
#
##@ General
.PHONY: help
help: # Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^\$$\([0-9A-Za-z_-]+\):.*?##/ { gsub("_","-", $$1); printf " \033[36m%-25s\033[0m %s\n", tolower(substr($$1, 3, length($$1)-7)), $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: all
all: clean build ## Execute all build tasks
##@ Build
.PHONY: build-dotnet
build-dotnet: ## Build dotnet module
@echo "=> (module) Compiling .NET source..."
@dotnet build -c Debug ${DOTNET_PROJECT_FILE}
@echo "=> (proxy) Building .NET image..."
@docker build --build-arg MOD_PATH=${DOTNET_BUILD_DIR}/Envoy.wasm -t ${ENVOY_NAME}:dotnet --file ${ENVOY_ROOT_DIR}/Dockerfile .
.PHONY: build-rust
build-rust: ## Build rust module
@echo "=> (module) Compiling Rust source..."
@rustup target add wasm32-wasi
@cargo build --manifest-path ${RUST_ROOT_DIR}/Cargo.toml --target wasm32-wasi --target-dir ${RUST_ROOT_DIR}/target
@echo "=> (proxy) Building Rust image..."
@docker build --build-arg MOD_PATH=${RUST_BUILD_DIR}/module.wasm -t ${ENVOY_NAME}:rust --file ${ENVOY_ROOT_DIR}/Dockerfile .
##@ Generate
# TODO: Implement wit-bindgen targets
# wit-bindgen c-sharp --runtime native-aot ./modules/dotnet/Envoy.wit --out-dir ./modules/dotnet/Generated/
##@ Test
.PHONY: test-dotnet
test-dotnet: ## Test dotnet module
@echo "=> (module) Testing .NET source..."
@dotnet test ${DOTNET_PROJECT_FILE} --verbosity minimal
.PHONY: test-rust
test-rust: ## Test rust module
@echo "=> (module) Testing Rust source..."
@cargo test --manifest-path ${RUST_DIR}/Cargo.toml
##@ Validate
.PHONY: validate-dotnet
validate-dotnet: ## Validate dotnet module
@echo "=> (module) Validating .NET module..."
@wasm-tools validate -vv ${DOTNET_BUILD_DIR}/Envoy.wasm
.PHONY: validate-rust
validate-rust: ## Validate rust module
@echo "=> (module) Validating Rust module..."
@wasm-tools validate -vv ${RUST_DIR}/target/wasm32-wasi/debug/module.wasm
##@ Clean
.PHONY: clean-dotnet
clean-dotnet: ## Clean dotnet artifacts
@echo "=> (module) Cleaning .NET source..."
@dotnet clean ${DOTNET_PROJECT_FILE} --verbosity minimal
@echo "=> (module) Removing compiled module..."
@rm -f ${DOTNET_ROOT_DIR}/Envoy.wasm
@echo "=> (proxy) Cleaning .NET image..."
@docker images -q ${DOTNET_IMAGE_NAME} | xargs -r docker rmi
.PHONY: clean-rust
clean-rust: ## Clean rust artifacts
@echo "=> (module) Cleaning Rust source..."
@cargo clean --manifest-path ${RUST_DIR}/Cargo.toml
@echo "=> (proxy) Cleaning Rust image..."
@docker images -q ${RUST_IMAGE_NAME} | xargs -r docker rmi
##@ Operate
.PHONY: start-dotnet
start-dotnet: ## Start dotnet container
@echo "=> (dotnet) Starting envoy..."
@docker run -d --name ${ENVOY_NAME}-dotnet -p 9905:9901 -p 10005:10000 ${DOTNET_IMAGE_NAME}
.PHONY: start-rust
start-rust: ## Start rust container
@echo "=> (rust) Starting envoy..."
@docker run -d --name ${ENVOY_NAME}-rust -p 9906:9901 -p 10006:10000 ${RUST_IMAGE_NAME}
.PHONY: stop-dotnet
stop-dotnet: ## Stop dotnet container
@echo "=> Stopping envoy..."
@docker stop ${ENVOY_NAME}-dotnet | xargs docker rm
.PHONY: stop-rust
stop-rust: ## Stop rust container
@echo "=> Stopping envoy..."
@docker stop ${ENVOY_NAME}-rust | xargs docker rm
##@ Manage
.PHONY: list-containers
list-containers: ## List all containers
@echo "=> Listing running containers..."
@docker container list --all
.PHONY: list-images
list-images: ## List all images
@echo "=> Listing images..."
@docker images --all
##@ Debug
.PHONY: inspect-dotnet
inspect-dotnet: ## Inspect dotnet image
@echo "=> Inspecting .NET container..."
@docker inspect ${ENVOY_NAME}-dotnet
.PHONY: inspect-rust
inspect-rust: ## Inspect rust image
@echo "=> Inspecting Rust container..."
@docker inspect ${ENVOY_NAME}-rust
.PHONY: shell-dotnet
shell-dotnet: ## Launch dotnet shell
@echo "=> Opening shell in .NET container..."
@docker exec -it ${ENVOY_NAME}-dotnet /bin/sh
.PHONY: shell-rust
shell-rust: ## Launch rust shell
@echo "=> Opening shell in Rust container..."
@docker exec -it ${ENVOY_NAME}-rust /bin/sh
##@ Logs
.PHONY: logs-dotnet
logs-dotnet: ## Display dotnet logs
@echo "=> Showing envoy logs..."
@docker logs -f ${ENVOY_NAME}-dotnet
.PHONY: logs-rust
logs-rust: ## Display envoy logs
@echo "=> Showing envoy logs..."
@docker logs -f ${ENVOY_NAME}-rust
##@ Runtime
.PHONY: run-dotnet
run-dotnet: ## Run dotnet module
@echo "=> Running .NET module with wasmtime..."
@wasmtime --dir . -- ${DOTNET_BUILD_DIR}/Envoy.wasm
.PHONY: run-rust
run-rust: ## Run rust module
@echo "=> Running Rust module with wasmtime..."
@wasmtime --dir . -- ${RUST_BUILD_DIR}/module.wasm