-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev
executable file
·149 lines (122 loc) · 4.8 KB
/
dev
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
147
148
149
#!/bin/bash
# @package exadra37-playground/amazon-associates-search
# @link https://gitlab.com/u/exadra37-playground/amazon-associates-search
# @since 2017/02/24
# @license MIT
# @author Exadra37(Paulo Silva) <exadra37ingmailpointcom>
#
# Social Links:
# @link Auhthor: https://exadra37.com
# @link Gitlab: https://gitlab.com/Exadra37
# @link Github: https://github.com/Exadra37
# @link Linkedin: https://uk.linkedin.com/in/exadra37
# @link Twitter: https://twitter.com/Exadra37
########################################################################################################################
# Functions
########################################################################################################################
function build()
{
local image_name="${1:-amazon-associates-search:latest}"
local uid=$( id -u )
local gid=$( id -g )
sudo docker build \
--build-arg HOST_USER="${USER}" \
--build-arg HOST_UID="${uid}" \
--build-arg HOST_GID="${gid}" \
-t "${image_name}" \
./docker &&
Print_Text "Container is Ready to Use" "Start it with ./dev run"
}
function run()
{
local ports="${1:-8000:80}"
local host_app_dir="${2:-$PWD}"
local container_name="${3:-amazon-associates-search}"
local image_name="${4:-amazon-associates-search:latest}"
sudo docker run -d \
--publish="${ports}" \
--name="${container_name}" \
--workdir="/var/www/html" \
--volume=/home/"${USER}"/.secrets/"${container_name}":/home/"${USER}"/.secrets/"${container_name}" \
--volume="${host_app_dir}":/var/www/html \
"${image_name}" &&
Print_Text "Container is now Running" "Use ./dev shell to go inside it. Visit http://localhost:8000 in the browser."
}
function deploy()
{
local ports="${1:-8000:80}"
local host_app_dir="${2:-$PWD}"
local container_name="${3:-amazon-associates-search}"
local image_name="${4:-amazon-associates-search:latest}"
build "${image_name}" &&
run "${ports}" "${host_app_dir}" "${container_name}" "${image_name}" &&
Print_Text "Container Deployed" "This is the Container Shell." &&
shell "${container_name}"
}
function shell()
{
local container_name="${1:-amazon-associates-search}"
sudo docker exec -it \
--user="${USER}" \
"${container_name}" \
zsh
}
function start()
{
local container_name="${1:-amazon-associates-search}"
sudo docker start "${container_name}" &&
Print_Text "Container is now Running" "Use ./dev shell to go inside it. Visit http://localhost:8000 in the browser."
}
function stop()
{
local container_name="${1:-amazon-associates-search}"
sudo docker stop "${container_name}" &&
Print_Text "Container is now Stopped" "Use ./dev start to start it again or ./dev remove to delete it."
}
function remove()
{
local container_name="${1:-amazon-associates-search}"
sudo docker rm "${container_name}" &&
Print_Text "Container is now Removed" "Use ./dev deploy to build and start it in 1 go."
}
function destroy()
{
local container_name="${1:-amazon-associates-search}"
local image_name="${2:-amazon-associates-search:latest}"
stop "${container_name}" &&
remove "${container_name}" &&
Print_Text "Container is now Destroyed" "Use ./dev deploy to build and start it in 1 go."
}
function purge()
{
local container_name="${1:-amazon-associates-search}"
local image_name="${2:-amazon-associates-search:latest}"
destroy "${container_name}" "${image_name}" &&
sudo docker rmi "${image_name}" &&
Print_Text "Container and Image Purged" "Use ./dev deploy to build and start it in 1 go."
}
function secrets()
{
local container_name="${1:-amazon-associates-search}"
local file_name=".secrets.php"
local secrets_dir=/home/"${USER}"/.secrets/"${container_name}"
local secrets_file="${secrets_dir}"/"${file_name}"
Print_Text "Edit this file" "${secrets_file}"
if [ ! -d "${secrets_dir}" ]
then
mkdir -p "${secrets_dir}"
fi
if [ ! -f "${secrets_file}" ]
then
cp ./.secrets-example.php "${secrets_file}"
fi
if [ ! -f "${file_name}" ]
then
ln -s "${secrets_file}"
fi
}
function Print_Text()
{
printf "\n\e[1;42m ${1}:\e[30;48;5;229m ${2} \e[0m \n"
}
"${@}"