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

Add make targets to install tech stack & app deps

* tech stack can be installed locally and will be used by app-related
  targets if available
* bumped minimal required npm version to 6.14 for server and client
parent 7deefa2c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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`
......
......@@ -88,7 +88,7 @@
},
"engines": {
"node": ">=12.16.0",
"npm": ">=6.13.0"
"npm": ">=6.14.0"
},
"jest": {
"roots": [
......
......@@ -26,6 +26,6 @@
},
"engines": {
"node": ">=12.16.0",
"npm": ">=6.13.0"
"npm": ">=6.14.0"
}
}
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
mongodb-linux-x86_64-4.2.6.tgz 7c763aea275b9b3ebb6b746e9e356d81305dcd0c760319bfa78abd1b30eb4612
mongodb-darwin-x86_64-4.2.6.tgz 701fda6ab0b49121913204596d527d89d4a533a3a7d1ca2f245c7908e1342c5b
node-v12.16.3-linux-x64.tar.gz 66518c31ea7735ae5a0bb8ea27edfee846702dbdc708fea6ad4a308d43ef5652
node-v12.16.3-darwin-x64.tar.gz 0718812b3ab8e77e8d1354f4d10428ae99d78f721bdcceee527c4b592ea7fed0
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