This repository has been archived by the owner on Feb 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgo-docker
executable file
·122 lines (100 loc) · 3.05 KB
/
go-docker
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
#! /bin/bash -e
command_exists () {
type "$1" &> /dev/null ;
}
run_docker() {
docker run \
-it \
--rm \
-p "8000:8000" \
-w "/app" \
-v $(pwd):/app \
$docker_image \
"${@-bash}"
}
bold_text() {
echo -e "\033[1m$1\033[0m"
}
green_tick() {
echo -e "\033[1;92m✓\033[0m $1"
}
red_text() {
echo -e "\033[0;91m$1\033[0m"
}
green_text() {
echo -e "\033[0;92m$1\033[0m"
}
show_instructions () {
echo "$(bold_text Usage): ./go <command>"
echo ""
echo "where <command> is one of:"
echo " $(bold_text "setup ") setups your development machine"
echo " $(bold_text "install | i " ) installs any required dependencies"
echo " $(bold_text "test | t " ) runs all your unit tests"
echo " $(bold_text "test:dev | td") runs all your unit tests and watch any changes (dev mode)"
echo " $(bold_text "precommit | p " ) prepares your changes to be committed"
echo " $(bold_text "start | s " ) runs your local development server at http://localhost:8000"
}
echo " _ ________ ________ _ _ _ _____ ____ _ _ _____ _ _____ "
echo " | | | ____\ \ / / ____| | | | | | __ \ | _ \| | | |_ _| | | __ \ "
echo " | | | |__ \ \ / /| |__ | | | | | | |__) | | |_) | | | | | | | | | | | |"
echo " | | | __| \ \/ / | __| | | | | | | ___/ | _ <| | | | | | | | | | | |"
echo " | |____| |____ \ / | |____| |___| |__| | | | |_) | |__| |_| |_| |____| |__| |"
echo " |______|______| \/ |______|______\____/|_| |____/ \____/|_____|______|_____/ "
echo ""
echo ""
intro_message() {
echo "It looks like this is your first time trying to run the app."
echo "Before you start, I need to set a few things up for you."
}
docker_needed_message() {
red_text "You need to have docker installed, I can't install it for you."
red_text "If you haven't already, please follow the setup instructions for your machine over at"
red_text "https://github.com/twlevelup/watch_edition_react/wiki/Setup%3A-Tools"
}
docker_image_exist() {
[[ "$(docker images -q $docker_image 2> /dev/null)" ]]
}
export NODE_VERSION="$(cat .node-version)"
export docker_image="node:${NODE_VERSION}"
case "$1" in
"setup")
if ! command_exists docker; then
docker_needed_message
exit 1
fi
if ! docker_image_exist; then
bold_text "Pulling docker image: ${docker_image}"
docker pull $docker_image
green_tick "Pulled docker image"
fi
if [ ! -d "node_modules" ]; then
bold_text "Installing npm packages"
run_docker npm install
green_tick "Installed npm packages"
fi
echo ""
green_text "All done! You can now start using the app!"
;;
"install" | "i")
run_docker npm -s install
;;
"test" | "t" )
run_docker npm -s test
exit $?
;;
"test:dev" | "td")
run_docker npm -s run test:dev
exit $?
;;
"precommit" | "p")
run_docker npm -s run precommit
exit $?
;;
"start" | "s")
run_docker npm run start
;;
*)
show_instructions
;;
esac