-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (84 loc) · 2.48 KB
/
Makefile
File metadata and controls
105 lines (84 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# MAKEFLAGS += --silent
default: watch
.PHONY: lint
lint:
npm run lint
.PHONY: watch
watch: clean node_modules lint watch
npm run watch
.PHONY: start
start: node_modules build
npm start
node_modules:
ifeq ($(MAKECMDGOALS), production-bundle)
npm ci
else
npm install
endif
.PHONY: clean-modules
clean-modules:
rm -rf node_modules/
build: clean
npm run build -- --mode production
.PHONY: clean
clean:
rm -rf build/
.PHONY: production-bundle
production-bundle: clean-modules node_modules lint build
.PHONY: test
test: node_modules lint
npm test
###############################################################################
# Docker
###############################################################################
# These variables are read from .env
APP_NAME =$(shell grep '^APP_NAME=' .env | awk -F"=" '{print $$2}')
COMPANY_NAME=$(shell grep '^COMPANY_NAME=' .env | awk -F"=" '{print $$2}')
ENVIRONMENT =$(shell grep '^ENVIRONMENT=' .env | awk -F"=" '{print $$2}')
PORT =$(shell grep '^PORT=' .env | awk -F"=" '{print $$2}')
# These variables are read from package.json
APP_VERSION=$(shell grep '"version": ' package.json | head -1 | cut -d '"' -f 4)
.PHONY: show-variables
show-variables:
@echo APP_NAME = $(APP_NAME)
@echo COMPANY_NAME = $(COMPANY_NAME)
@echo ENVIRONMENT = $(ENVIRONMENT)
@echo APP_VERSION = $(APP_VERSION)
@echo PORT = $(PORT)
.PHONY: docker-image
docker-image:
docker build \
-t $(COMPANY_NAME)/$(APP_NAME):latest \
-t $(COMPANY_NAME)/$(APP_NAME):$(APP_VERSION) \
--build-arg COMPANY_NAME=$(COMPANY_NAME) \
--build-arg APP_NAME=$(APP_NAME) \
./
.PHONY: docker-image-archive
docker-image-archive:
docker save -o $(APP_NAME):$(APP_VERSION).tar $(COMPANY_NAME)/$(APP_NAME):$(APP_VERSION) && \
bzip2 -f $(APP_NAME):$(APP_VERSION).tar
.PHONY: docker-image-load
docker-image-load:
docker load -i $(APP_NAME):$(APP_VERSION).tar
.PHONY: docker-run
docker-run:
docker run \
-e PORT=$(PORT) \
-p 80:$(PORT) \
$(COMPANY_NAME)/$(APP_NAME):latest
.PHONY: compose-up
compose-up:
ifeq ($(ENVIRONMENT), production)
docker-compose -f docker-compose.yml up --build
else
docker-compose -f docker-compose.development.yml up --build
endif
.PHONY: compose-down
compose-down:
ifeq ($(ENVIRONMENT), production)
docker-compose -f docker-compose.yml down --remove-orphans
else
docker-compose -f docker-compose.development.yml down --remove-orphans
endif
.PHONY: compose-restart
compose-restart: compose-down compose-up