Makefile
3.58 KB
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
PROFILE ?= dev
ifeq "$(PROFILE)" "release"
CARGO_PROFILE = --release
WASM_PROFILE = --release
WASM_EXTRA = --no-default-features --features wee_alloc
SERVER_TARGET = target/release/artshop-server
WASM_TARGET = ui/target/wasm32-unknown-unknown/release/artshop_frontend.wasm
else
CARGO_PROFILE =
WASM_PROFILE = --dev
WASM_EXTRA =
SERVER_TARGET = target/debug/artshop-server
WASM_TARGET = ui/target/wasm32-unknown-unknown/debug/artshop_frontend.wasm
endif
SERVER_SOURCES = common/Cargo.toml \
server/Cargo.toml \
$(shell find common -name "*.rs") \
$(shell find server -name "*.rs")
WASM_DEPLOY = static/ui/artshop_frontend_bg.wasm
WASM_SOURCES = common/Cargo.toml \
ui/Cargo.toml \
$(shell find common -name "*.rs") \
$(shell find ui -name "*.rs")
define msg
@printf "\033[38;5;197m%s\033[0m" "$(1)"
endef
define msgnl
@printf "\033[38;5;197m%s\033[0m\n" "$(1)"
endef
.PHONY: start run wasm build clean release
start:
$(call msgnl,NOTIFY REBUILD RUN)
@systemfd --no-pid -s 0.0.0.0:3000 -- \
cargo watch -i static/ -i var/ \
-s "PROFILE=$(PROFILE) make run"
run: build wasm data/copyright.png
$(call msgnl,RUN SERVER)
@PROFILE=$(PROFILE) cargo run $(CARGO_PROFILE) --bin artshop-server
wasm: $(WASM_DEPLOY)
build: $(SERVER_TARGET)
clean:
$(call msgnl,CLEAN WORKSPACE)
@PROFILE=$(PROFILE) cargo clean
$(call msgnl,CLEAN INSTALLED WASM)
@rm -Rf ./static/ui
$(call msgnl,CLEAN INSTALLED WASM)
@pushd ui; PROFILE=$(PROFILE) cargo clean; popd
$(call msgnl,CLEAN COPYRIGHT PNG)
@rm -Rf ./data/copyright.png
$(WASM_TARGET): $(WASM_SOURCES)
$(call msgnl,BUILD WASM UI)
@PROFILE=$(PROFILE) wasm-pack build $(WASM_PROFILE) -d ../static/ui \
-t web --mode no-install ./ui -- $(WASM_EXTRA)
$(WASM_DEPLOY): $(WASM_TARGET)
$(call msgnl,INSTALL WASM UI)
@PROFILE=$(PROFILE) wasm-pack build $(WASM_PROFILE) -d ../static/ui \
-t web ./ui -- $(WASM_EXTRA)
$(SERVER_TARGET): $(SERVER_SOURCES)
$(call msgnl,PATCH DIFFY)
@PROFILE=$(PROFILE) cargo patch
$(call msgnl,BUILD SERVER)
@PROFILE=$(PROFILE) cargo build $(CARGO_PROFILE) --bin artshop-server
data/copyright.png: data/copyright.txt
$(call msgnl,CREATE COPYRIGHT PNG)
@cat $< | convert -pointsize 24 -font Helvetica \
-background transparent -fill "rgba(255,255,255,0.35)" \
text:- -trim +repage $@
release:
docker build -t artshop -f build/Dockerfile .
.PHONY: createdb devdb downdb enterdb rootdb
createdb: downdb devdb
$(call msg,TRY TO CONNECT TO DB )
@while true;\
do\
echo "SELECT VERSION();"|\
docker exec -i mariadb-dev \
mysql -p123456 >/dev/null 2>&1 && break;\
echo -n ".";\
sleep 3;\
done; echo
$(call msgnl,INITIALIZE APPLICATION DB)
echo "CREATE DATABASE artshop CHARACTER SET = 'utf8mb3' \
COLLATE = 'utf8mb3_general_ci'; \
GRANT ALL PRIVILEGES ON artshop.* TO 'artshop'@'%'"|\
docker exec -i mariadb-dev mysql -p123456
$(call msgnl,RUN MIGRATIONS)
@diesel migration run
downdb:
$(call msgnl,STOP DB CONTAINER)
@docker stop mariadb-dev||true
$(call msgnl,REMOVE DB CONTAINER)
@docker rm -v mariadb-dev||true
$(call msgnl,REMOVE IMAGES)
@rm -Rf var/lib/artshop/images
devdb:
$(call msgnl,CREATE DB CONTAINER)
@docker run --detach --name mariadb-dev \
-p 3306:3306 \
--env MARIADB_USER=artshop \
--env MARIADB_PASSWORD=123456 \
--env MARIADB_ROOT_PASSWORD=123456 mariadb:latest
enterdb:
docker exec -it mariadb-dev mysql -D artshop -u artshop -p123456||true
# docker run -it --network mariadb-dev-network --rm mariadb:latest \
# mysql -h mariadb-dev -u artshop -p
rootdb:
docker exec -it mariadb-dev mysql -p123456||true