Skip to content
Snippets Groups Projects
Commit ad1ebc08 authored by Lucendio's avatar Lucendio
Browse files

Improve again handling of white spaces in paths

* changed the way how the paths of makefile and .local folder are determined
* removed failsafe and replaced it with quoted path variables
parent b1a4614b
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ SHELL = /usr/bin/env bash -eo pipefail ...@@ -3,8 +3,8 @@ SHELL = /usr/bin/env bash -eo pipefail
MKFILE_DIR = $(abspath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) MKFILE_DIR = $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
LOCAL_DIR := $(abspath $(MKFILE_DIR)/.local) LOCAL_DIR := $(shell echo $$(cd "$(MKFILE_DIR)" && pwd)/.local)
DATA_DIR := $(LOCAL_DIR)/data DATA_DIR := $(LOCAL_DIR)/data
...@@ -32,12 +32,10 @@ $(LOCAL_DIR)/%/: ...@@ -32,12 +32,10 @@ $(LOCAL_DIR)/%/:
.PHONY: clean .PHONY: clean
clean: clean:
echo "DELETING: $(APP_NODE_MODULE_DIRS) $(TEMP_DIR) $(LOCAL_DIR)/dist" | tr ' ' '\n' rm -rf \
read -p "OK? [N,y] " input; [[ "$${input}" == "y" ]] \ "$(APP_NODE_MODULE_DIRS)" \
&& rm -rf \ "$(TEMP_DIR)" \
$(APP_NODE_MODULE_DIRS) \ "$(LOCAL_DIR)/dist"
$(TEMP_DIR) \
$(LOCAL_DIR)/dist
...@@ -45,30 +43,28 @@ clean: ...@@ -45,30 +43,28 @@ clean:
build: SERVER_PUBLIC_URL ?= http://127.0.0.1:3001 build: SERVER_PUBLIC_URL ?= http://127.0.0.1:3001
build: APP_BUILD_PATH ?= $(TEMP_DIR) build: APP_BUILD_PATH ?= $(TEMP_DIR)
build: build:
echo "DELETING: $(APP_BUILD_PATH)" | tr ' ' '\n' rm -rf "$(APP_BUILD_PATH)"
read -p "OK? [N,y] " input; [[ "$${input}" == "y" ]] \
&& rm -rf $(APP_BUILD_PATH)
cp -r $(MKFILE_DIR)/app/server/src $(APP_BUILD_PATH) cp -r "$(MKFILE_DIR)/app/server/src" "$(APP_BUILD_PATH)"
cp $(MKFILE_DIR)/app/server/package* $(APP_BUILD_PATH)/ cp "$(MKFILE_DIR)"/app/server/package* "$(APP_BUILD_PATH)/"
cd $(APP_BUILD_PATH) \ cd "$(APP_BUILD_PATH)" \
&& \ && \
npm install --prod --no-audit --no-fund \ npm install --prod --no-audit --no-fund \
&& rm -rf ./package* && rm -rf ./package*
cd $(MKFILE_DIR)/app/client \ cd "$(MKFILE_DIR)/app/client" \
&& \ && \
PUBLIC_URL=$(SERVER_PUBLIC_URL) \ PUBLIC_URL=$(SERVER_PUBLIC_URL) \
BUILD_PATH=$(APP_BUILD_PATH)/public \ BUILD_PATH="$(APP_BUILD_PATH)/public" \
node ./scripts/build.js node ./scripts/build.js
.PHONY: test .PHONY: test
test: randomString = $(shell LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1) test: randomString = $(shell LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 32 | head -n 1)
test: test:
cd $(MKFILE_DIR)/app/client \ cd "$(MKFILE_DIR)/app/client" \
&& npm run test && npm run test
cd $(MKFILE_DIR)/app/server \ cd "$(MKFILE_DIR)/app/server" \
&& \ && \
PORT=3002 \ PORT=3002 \
MONGODB_URL=mongodb://localhost:27017/$(randomString) \ MONGODB_URL=mongodb://localhost:27017/$(randomString) \
...@@ -80,23 +76,23 @@ test: ...@@ -80,23 +76,23 @@ test:
.PHONY: dev-test-client .PHONY: dev-test-client
dev-test-client: dev-test-client:
cd $(MKFILE_DIR)/app/client \ cd "$(MKFILE_DIR)/app/client" \
&& npm run test:dev && npm run test:dev
.PHONY: dev-start-db .PHONY: dev-start-db
dev-start-db: $(LOG_DIR)/ $(DATA_DIR)/ $(DATA_DIR)/db/ dev-start-db: $(LOG_DIR)/ $(DATA_DIR)/ $(DATA_DIR)/db/
mongod --config $(MKFILE_DIR)/app/server/dev.mongod.conf mongod --config "$(MKFILE_DIR)/app/server/dev.mongod.conf"
.PHONY: dev-start-app .PHONY: dev-start-app
dev-start-app: dev-start-app:
cd $(MKFILE_DIR)/app/client \ cd "$(MKFILE_DIR)/app/client" \
&& \ && \
PUBLIC_URL=$(SERVER_PUBLIC_URL) \ PUBLIC_URL=$(SERVER_PUBLIC_URL) \
BUILD_PATH=$(MKFILE_DIR)/app/server/src/public \ BUILD_PATH="$(MKFILE_DIR)/app/server/src/public" \
node ./scripts/build.js node ./scripts/build.js
cd $(MKFILE_DIR)/app/server \ cd "$(MKFILE_DIR)/app/server" \
&& npm run start:dev && npm run start:dev
...@@ -109,20 +105,20 @@ run: DB_HOST = localhost ...@@ -109,20 +105,20 @@ run: DB_HOST = localhost
run: DB_PORT = 27017 run: DB_PORT = 27017
run: $(DATA_DIR)/ $(LOG_DIR)/ $(DATA_DIR)/db/ run: $(DATA_DIR)/ $(LOG_DIR)/ $(DATA_DIR)/db/
make build \ make build \
APP_BUILD_PATH=$(BUILD_PATH) \ APP_BUILD_PATH="$(BUILD_PATH)" \
SERVER_PUBLIC_URL=$(PUBLIC_URL):$(SERVER_PORT) SERVER_PUBLIC_URL=$(PUBLIC_URL):$(SERVER_PORT)
(exec mongod \ (exec mongod \
--port $(DB_PORT) \ --port $(DB_PORT) \
--bind_ip $(DB_HOST) \ --bind_ip $(DB_HOST) \
--logpath /dev/stdout \ --logpath /dev/stdout \
--dbpath $(DATA_DIR)/db \ --dbpath "$(DATA_DIR)/db" \
) & PIDS[1]=$$!; \ ) & PIDS[1]=$$!; \
\ \
(PORT=$(SERVER_PORT) \ (PORT=$(SERVER_PORT) \
MONGODB_URL=mongodb://$(DB_HOST):$(DB_PORT)/todo-app \ MONGODB_URL=mongodb://$(DB_HOST):$(DB_PORT)/todo-app \
JWT_SECRET=myjwtsecret \ JWT_SECRET=myjwtsecret \
exec node $(BUILD_PATH)/index.js \ exec node "$(BUILD_PATH)/index.js" \
) & PIDS[2]=$$!; \ ) & PIDS[2]=$$!; \
\ \
for PID in $${PIDS[*]}; do wait $${PID}; done; for PID in $${PIDS[*]}; do wait $${PID}; done;
Lecture: DevOps - Application Lecture: DevOps - Application
============================= =============================
> :warning: __Invoking `make` in a path containing white spaces may lead to unforeseen side effects like DATA LOSS !__
> :warning: __Invoking `make` in a path containing white spaces will break execution and may lead to
> unforeseen side effects like DATA LOSS !__
This repository contains the [application](./app/README.md) that is supposed be used as *deployable workload* in the This repository contains the [application](./app/README.md) that is supposed be used as *deployable workload* in the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment