From 0bcca5b605d348b153e1ef6b516a2fab54799366 Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Wed, 11 Oct 2023 16:34:20 +0300 Subject: [PATCH] Improve Makefile: make it simple, closes #96 Signed-off-by: Mikhail Petrov --- .gitignore | 1 + Makefile | 87 ++++++++++++++++++++++------------------------------ README.md | 6 ++-- package.json | 2 +- 4 files changed, 41 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index 071e6a5..b25a674 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ # production /build +/panel.fs.neo.org /output *output.json /release diff --git a/Makefile b/Makefile index b118c09..ec37570 100644 --- a/Makefile +++ b/Makefile @@ -1,66 +1,53 @@ #!/usr/bin/make -f -PORT = 3000 -NODE_VERSION ?= 14 -VERSION ?= "$(shell git describe --tags --match "v*" --abbrev=8 2>/dev/null | sed -r 's,^v([0-9]+\.[0-9]+)\.([0-9]+)(-.*)?$$,\1 \2 \3,' | while read mm patch suffix; do if [ -z "$$suffix" ]; then echo $$mm.$$patch; else patch=`expr $$patch + 1`; echo $$mm.$${patch}-pre$$suffix; fi; done)" +SHELL = bash -ifeq ($(shell uname), Linux) - STAT:=-u $(shell stat -c "%u:%g" .) -endif - -# Build and run optimized server. -.PHONY: all -all: build - @npm install --location=local serve - @./node_modules/.bin/serve -s output -p $(PORT) +VERSION ?= "$(shell git describe --tags --match "v*" --abbrev=8 2>/dev/null | sed -r 's,^v([0-9]+\.[0-9]+)\.([0-9]+)(-.*)?$$,\1 \2 \3,' | while read mm patch suffix; do if [ -z "$$suffix" ]; then echo $$mm.$$patch; else patch=`expr $$patch + 1`; echo $$mm.$${patch}-pre$$suffix; fi; done)" +SITE_DIR ?= panel.fs.neo.org +RELEASE_DIR ?= $(SITE_DIR)-$(VERSION) +RELEASE_PATH ?= $(SITE_DIR)-$(VERSION).tar.gz +CURRENT_UID ?= $(shell id -u $$USER) -# Run npm build. -.PHONY: build -build: clean install - @npm run build +PORT = 3000 -# Run npm install. -.PHONY: install -install: - @npm install +$(SITE_DIR): + docker run \ + -v $$(pwd)/src:/usr/src/app/src \ + -v $$(pwd)/public:/usr/src/app/public \ + -v $$(pwd)/package.json:/usr/src/app/package.json \ + -v $$(pwd)/.env:/usr/src/app/.env \ + -v $$(pwd)/$(SITE_DIR):/usr/src/app/$(SITE_DIR) \ + -e CURRENT_UID=$(CURRENT_UID) \ + -w /usr/src/app node:14-alpine \ + sh -c 'npm install && REACT_APP_VERSION=$(VERSION) npm run build && chown -R $$CURRENT_UID: $(SITE_DIR)' -# Run npm start. .PHONY: start -start: install - @npm start - -# Run npm test. -.PHONY: test -test: - @npm run test +start: + docker run \ + -p $(PORT):3000 \ + -v `pwd`:/usr/src/app \ + -w /usr/src/app node:14-alpine \ + sh -c 'npm install --silent && npm run build && npm install -g serve && serve -s $(SITE_DIR) -p 3000' -# Create archive with build output. .PHONY: release -release: build - @rm -rf release - @mkdir release - @tar -czvf release/neofs-panel.tar.gz -C output . +release: $(SITE_DIR) + cp $(SITE_DIR)/index.html $(SITE_DIR)/agreement + @ln -sf $(SITE_DIR) $(RELEASE_DIR) + @tar cfvhz $(RELEASE_PATH) $(RELEASE_DIR) -# Remove all produced artifacts. .PHONY: clean clean: - @rm -rf release - @rm -rf output - @rm -rf node_modules + @echo "Cleaning up ..." + @rm -rf $(SITE_DIR) $(RELEASE_DIR) $(RELEASE_PATH) -# Run `make %` in Golang container, for more information run `make help.docker/%` -.PHONY: docker/% -docker/%: - @echo "=> Running 'make $*' in clean Docker environment" - @docker run --rm -it \ - --name panel_fs_neo_org \ - -v `pwd`:/usr/src/app \ - -p $(PORT):$(PORT) \ - -w /usr/src/app \ - $(STAT) \ - node:$(NODE_VERSION) sh -c 'make $*' - -include help.mk +.PHONY: release_name +release_name: + @echo $(RELEASE_PATH) +.PHONY: version version: @echo $(VERSION) + +.PHONY: test +test: + @npm run test diff --git a/README.md b/README.md index d45d3a2..3e3c746 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,11 @@ Optionally you can specify `PORT=3000`. # Make instructions -* Compile the build using `make` (will be generated in `output` dir) -* Start app using `make start PORT=3000` (PORT=3000 by default) +* Compile the build using `make` (will be generated in `panel.fs.neo.org` dir) +* Start app using `make start` (PORT=3000 by default) * Clean up cache directories using `make clean` * Get release dir with tar.gz using `make release` -Also, you can run all targets in docker (`make docker/*`): - ```shell $ make docker/start ``` diff --git a/package.json b/package.json index 9633777..a713722 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "scripts": { "resolutions": "npx npm-force-resolutions && npm install -D react-error-overlay@6.0.9", "start": "REACT_APP_VERSION=$(make version) react-scripts start", - "build": "BUILD_PATH='./output' react-scripts build", + "build": "BUILD_PATH='./panel.fs.neo.org' react-scripts build", "test": "jest --updateSnapshot", "eject": "react-scripts eject" },