Makefile 3.58 KB
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