forked from hajnalben/react-tags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·146 lines (128 loc) · 4.59 KB
/
run
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# This script is a common utility for running various commands on this
# repository in a development environment, including setup tasks for a new
# development environment, and tasks that wrap docker and docker-compose to run
# the service, its dependencies, and other management scripts inside containers.
#
# See the USAGE message below for commands.
#------------------------------------------------------------------------------
set -e
############################################################
# Config
############################################################
DOCKER_IMAGE_NAME="facet/react-tags"
SERVER_CMD="npm run start"
EXTERNAL_SERVER_PORT=8060
INTERNAL_SERVER_PORT=3000
DOCKER_BUILD_CMD="docker build . -t $DOCKER_IMAGE_NAME"
DOCKER_RUN_CMD="docker run -it --rm -v $(pwd):/app"
DOCKER_RUND_CMD="docker run --rm -v $(pwd):/app"
############################################################
# Usage
############################################################
if [[ $# -lt 1 ]]; then
echo
echo "USAGE: ./run.sh [COMMAND]"
echo
echo "Commands:"
echo " setup - Setup the initial dev env by building the necessary"
echo " Docker container."
echo
echo " test - Run the unit tests."
echo
echo " test:watch - Run all unit tests under watch mode, without coverage."
echo
echo " lint - Run lint"
echo
echo " lint-fix - Run lint and auto-fix as many issues as possible"
echo
echo " build - Build the application for production"
echo
echo " npm-check - Run an interactive GUI to check for npm packages that are out of date."
echo " The GUI allows the user to select the packages they want to update and"
echo " will then perform the update automatically."
echo
echo " start - Run just the app server on http://localhost:$EXTERNAL_SERVER_PORT/"
echo
echo " exec - Run a one-off command in a container."
echo
echo " execd - Run a one-off command in a container, but non-interative, non-tty. (e.g., use with cron).."
echo
echo " shell - Run a bash shell in a container."
echo
echo "######################################################################"
echo "NOTE: This script requires that you have Docker installed."
echo "######################################################################"
echo
exit
fi
############################################################
# Main Script
############################################################
while [[ $# -gt 0 ]]; do
param="$1"
shift
case "$param" in
setup)
echo
echo "######################################################################"
echo "# Building '$DOCKER_IMAGE_NAME' Docker image..."
echo "######################################################################"
echo
$DOCKER_BUILD_CMD
rm -rf node_modules
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm install
break
;;
test)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm run test
break
;;
test:watch)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm run test:watch
break
;;
lint)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm run lint
break
;;
lint-fix)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm run lint:fix
break
;;
build)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm run build
break
;;
npm-check)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME npm run npm-check:update
break
;;
start)
echo
echo "######################################################################"
echo "# Running app server on: http://localhost:$EXTERNAL_SERVER_PORT/"
echo "######################################################################"
echo
$DOCKER_RUN_CMD -p $EXTERNAL_SERVER_PORT:$INTERNAL_SERVER_PORT $DOCKER_IMAGE_NAME $SERVER_CMD
break
;;
exec)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME $@
break
;;
execd)
$DOCKER_RUND_CMD $DOCKER_IMAGE_NAME $@
break
;;
shell|bash)
$DOCKER_RUN_CMD $DOCKER_IMAGE_NAME bash
break
;;
*)
echo "Unknown command: $param"
break
;;
esac
done