diff --git a/Makefile b/Makefile index a9e1b63a85e529345ab9db280883778e246fb488..8cc33f10aa0488d60844d0392dfcbf4bb98ccd3d 100644 --- a/Makefile +++ b/Makefile @@ -10,52 +10,74 @@ BIN_DIR = $(LOCAL_DIR)/bin TEMP_DIR = $(LOCAL_DIR)/tmp DATA_DIR = $(LOCAL_DIR)/data LOG_DIR = $(LOCAL_DIR)/logs +STACK_DIR = $(MKFILE_DIR)/stack + +APP_NODE_MODULE_DIRS = $(foreach dir, client server, $(subst %,$(dir),$(MKFILE_DIR)/app/%/node_modules)) + + + +NODEJS_VERSION ?= 12.16.3 +NPM_VERSION ?= 6.14.4 +MONGODB_VERSION ?= 4.2.6 +REACT_APP_VERSION = 3.4.1 PLATFORM := $(shell if echo $$OSTYPE | grep -q darwin; then echo darwin; else echo linux; fi) +NODEJS_URL = https://nodejs.org/dist/v$(NODEJS_VERSION)/node-v$(NODEJS_VERSION)-$(PLATFORM)-x64.tar.gz +NODEJS_ARTIFACT = $(TEMP_DIR)/node-v$(NODEJS_VERSION)-$(PLATFORM)-x64.tar.gz +NODEJS_BIN = $(BIN_DIR)/node +NPM_BIN = $(BIN_DIR)/npm +NODEJS_SHA256 ?= $(shell cat $(STACK_DIR)/versions/nodejs.256.sums | grep v$(NODEJS_VERSION)-$(PLATFORM)-x64 | awk '{ print $$ 2 }') -MONGO_VERSION = -MONGO_URL = +ifeq ($(PLATFORM), darwin) +MONGODB_URL = https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-$(MONGODB_VERSION).tgz +else ifeq ($(PLATFORM), linux) +# NOTE: hard-coded Debian version. Others can be found here: https://www.mongodb.com/download-center/community +MONGODB_URL = https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-$(MONGODB_VERSION).tgz +else + fail 'Unknown platform. No condition met' +endif +MONGODB_ARTIFACT = $(TEMP_DIR)/mongodb-$(PLATFORM)-$(MONGODB_VERSION).tar.gz +MONGODB_BIN = $(BIN_DIR)/mongod +MONGODB_SHA256 ?= $(shell cat $(STACK_DIR)/versions/mongodb.256.sums | grep $(PLATFORM)-x86_64-$(MONGODB_VERSION) | awk '{ print $$ 2 }') -REACT_APP_VERSION = '3.4.1' -install-stack: - echo '# mongo' - echo '# node' - echo '# npm' +default: all -install-deps: - cd $(MKFILE_DIR)/app/client \ - && npm install - cd $(MKFILE_DIR)/app/server \ - && npm install +all: install-stack install-deps -run-db: - mkdir -p $(LOG_DIR) $(DATA_DIR)/db - mongod --config ./conf/mongod.conf +install-stack: node npm mongod -build: - cd $(MKFILE_DIR)/app/client \ - && rm -rf ./build \ - && PUBLIC_URL=http://localhost:3000 \ - npm run build +install-deps: $(APP_NODE_MODULE_DIRS) + +.PHONY: run-db +run-db: export PATH := $(BIN_DIR):$(PATH) +run-db: | $(LOG_DIR)/ $(DATA_DIR)/ + mkdir -p $(DATA_DIR)/db + mongod --config $(STACK_DIR)/mongod.conf + + +.PHONY: run-local +run-local: export PATH := $(BIN_DIR):$(PATH) run-local: cd $(MKFILE_DIR)/app/server \ && npm run dev +.PHONY: test +test: export PATH := $(BIN_DIR):$(PATH) test: cd $(MKFILE_DIR)/app/client \ && npm run test @@ -63,16 +85,114 @@ test: && npm run test - +.PHONY: test-local +test-local: export PATH := $(BIN_DIR):$(PATH) test-local: cd $(MKFILE_DIR)/app/client \ && npm run test:dev +.PHONY: build +build: export PATH := $(BIN_DIR):$(PATH) +build: + cd $(MKFILE_DIR)/app/client \ + && rm -rf ./build \ + && PUBLIC_URL=http://localhost:3000 \ + npm run build + + + +.PHONY: clean +clean: clean-stack clean-modules + + + + +$(LOCAL_DIR)/%/: + mkdir -p $(@) + + +.PHONY: node +node: $(NODEJS_BIN) +$(NODEJS_BIN): | $(NODEJS_ARTIFACT) $(BIN_DIR)/ + @ [ $$(openssl dgst -sha256 "$(NODEJS_ARTIFACT)" | awk '{ print $$ 2 }') == $(NODEJS_SHA256) ] || ( echo "Invalid SHA256." && rm $(NODEJS_ARTIFACT) && exit 1 ) + tar \ + --extract \ + --verbose \ + --strip-components 2 \ + --directory "$(BIN_DIR)" \ + --file "$(NODEJS_ARTIFACT)" \ + node-*/bin/node + chmod +x "$@" + +$(NODEJS_ARTIFACT): | $(TEMP_DIR)/ + curl \ + --silent --show-error \ + --location \ + $(NODEJS_URL) \ + > $(NODEJS_ARTIFACT) + +.PHONY: npm +npm: $(NPM_BIN) +npm: export PATH := $(BIN_DIR):$(PATH) +$(NPM_BIN): | $(NODEJS_BIN) + tar \ + --extract \ + --verbose \ + --strip-components 2 \ + --directory "$(BIN_DIR)" \ + --file "$(NODEJS_ARTIFACT)" \ + node-*/bin/npm + chmod +x "$@" + npm install -g npm@$(NPM_VERSION) + + +.PHONY: mongod +mongod: $(MONGODB_BIN) +$(MONGODB_BIN): | $(MONGODB_ARTIFACT) $(BIN_DIR)/ + @ [ $$(openssl dgst -sha256 "$(MONGODB_ARTIFACT)" | awk '{ print $$ 2 }') == $(MONGODB_SHA256) ] || ( echo "Invalid SHA256." && rm $(MONGODB_ARTIFACT) && exit 1 ) + tar \ + --extract \ + --verbose \ + --strip-components 2 \ + --directory "$(BIN_DIR)" \ + --file "$(MONGODB_ARTIFACT)" \ + mongodb-*/bin/mongod + chmod +x "$@" + +$(MONGODB_ARTIFACT): | $(TEMP_DIR)/ + curl \ + --silent --show-error \ + --location \ + $(MONGODB_URL) \ + > $(MONGODB_ARTIFACT) + + +.PHONY: clean-stack +clean-stack: + rm -rf \ + $(LOCAL_DIR) + + + +.PHONY: $(APP_NODE_MODULE_DIRS) +$(APP_NODE_MODULE_DIRS): export PATH := $(BIN_DIR):$(PATH) +$(APP_NODE_MODULE_DIRS): $(MKFILE_DIR)/app/%/node_modules: + cd $(@D) \ + && npm install + +.PHONY: clean-modules +clean-modules: + for nodeModulesDir in $(APP_NODE_MODULE_DIRS); do \ + rm -rf "$${nodeModulesDir}"; \ + done + + .PHONY: update-react-app-template +update-react-app-template: export PATH := $(BIN_DIR):$(PATH) update-react-app-template: rm -rf $(TEMP_DIR)/npm-project-scope mkdir -p $(TEMP_DIR)/npm-project-scope diff --git a/README.md b/README.md index 443130dab9b7d8e9a507ce18a145f662e2b5c4b1..ef0ee31147173329ed4613b950309d8c0b59a81b 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,17 @@ This repository contains the [application](./app/README.md) that should be used ### Getting started -For more information on the app, please have a look into its [README](./app/README.md). +For more information regarding the app, please have a look into its [README](./app/README.md). + The `Makefile` is the main entry point for this repository. It's meant to be used for documentation purposes and local - invokation only. The following the following commands are available: +development/invocation only. The following commands are available: + + +#### `make install-stack` + +* install technology stack (nodejs, npm, mongodb) locally within the project +* in order for the application-related targets to pick up these binaries, the `PATH` variable is adjusted and exported + for the corresponding target #### `make install-deps` diff --git a/app/client/package.json b/app/client/package.json index 8f62a7de473d42717e9dbf295ada213d155479a3..ccb7714394f5e45848a2c709197025d5074af749 100644 --- a/app/client/package.json +++ b/app/client/package.json @@ -88,7 +88,7 @@ }, "engines": { "node": ">=12.16.0", - "npm": ">=6.13.0" + "npm": ">=6.14.0" }, "jest": { "roots": [ diff --git a/app/server/package.json b/app/server/package.json index 0e8058703b75cab2795605283f604606f36822c1..60b66d978fe9ae47f0110a973838dbe252a6f1ad 100644 --- a/app/server/package.json +++ b/app/server/package.json @@ -26,6 +26,6 @@ }, "engines": { "node": ">=12.16.0", - "npm": ">=6.13.0" + "npm": ">=6.14.0" } } diff --git a/stack/mongod.conf b/stack/mongod.conf new file mode 100644 index 0000000000000000000000000000000000000000..bc6157a2437682a135239896f9dcaadc47a05ed2 --- /dev/null +++ b/stack/mongod.conf @@ -0,0 +1,12 @@ +systemLog: + destination: file + path: ./.local/logs/mongodb.log + logAppend: true +storage: + dbPath: ./.local/data/db + journal: + enabled: true + engine: wiredTiger +net: + bindIp: 127.0.0.1 + port: 27017 diff --git a/stack/versions/mongodb.256.sums b/stack/versions/mongodb.256.sums new file mode 100644 index 0000000000000000000000000000000000000000..b26ea39905accc48be87516a1b7cb4ec3f1ec67c --- /dev/null +++ b/stack/versions/mongodb.256.sums @@ -0,0 +1,2 @@ +mongodb-linux-x86_64-4.2.6.tgz 7c763aea275b9b3ebb6b746e9e356d81305dcd0c760319bfa78abd1b30eb4612 +mongodb-darwin-x86_64-4.2.6.tgz 701fda6ab0b49121913204596d527d89d4a533a3a7d1ca2f245c7908e1342c5b diff --git a/stack/versions/nodejs.256.sums b/stack/versions/nodejs.256.sums new file mode 100644 index 0000000000000000000000000000000000000000..2f59ed026250a91db12d51d126779ad12509958c --- /dev/null +++ b/stack/versions/nodejs.256.sums @@ -0,0 +1,2 @@ +node-v12.16.3-linux-x64.tar.gz 66518c31ea7735ae5a0bb8ea27edfee846702dbdc708fea6ad4a308d43ef5652 +node-v12.16.3-darwin-x64.tar.gz 0718812b3ab8e77e8d1354f4d10428ae99d78f721bdcceee527c4b592ea7fed0