Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Makefile #101

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# production
/build
/panel.fs.neo.org
/output
*output.json
/release
Expand Down
87 changes: 37 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"resolutions": "npx npm-force-resolutions && npm install -D [email protected]",
"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"
},
Expand Down
Loading