-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-run
executable file
·56 lines (49 loc) · 2.18 KB
/
docker-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
#!/usr/bin/env bash
set -e
# we need to check if the container is running, and if not, tell the user to run ./docker-up
if [ ! "$(docker ps -q -f name=dockerlocal3090-web-1)" ]; then
printf "============ ❌ Docker container is not running. Please run ./docker-up\n"
exit 1
fi
# temporary: Inside the docker container:
# Copy /var/www/simple-docker/scripts/templates/setup-site to /var/www/LEMP-setup-guide/scripts/setup-site && chmod +x it
# docker exec -t -i dockerlocal3090-web-1 /bin/bash -i -c "cp /var/www/simple-docker/scripts/templates/setup-site /var/www/LEMP-setup-guide/scripts/ && chmod +x /var/www/LEMP-setup-guide/scripts/setup-site"
# user will use this script like: ./docker-run -n <server-name>
HELP="ℹ️ How to use:\n\t./docker-run -n <server-name>\n\teg. ./docker-run -n mysite.com\n"
# getopts for -n for server name, take a -h for help too
while getopts ":n:h" opt; do
case ${opt} in
n ) # process option n
SERVER_NAME=$OPTARG
;;
h ) # process option h
printf "$HELP"
exit 1
;;
\? ) # invalid option
printf "Invalid option: $OPTARG" 1>&2
printf "$HELP"
exit 1
;;
: ) # invalid option
printf "Invalid option: $OPTARG requires an argument" 1>&2
printf "$HELP"
exit 1
;;
esac
done
# Require -n
if [ -z "$SERVER_NAME" ]; then
printf "============ ❌ Running a script requires -n option for server-name\n"
exit 1
fi
# store docker exec command in a variable
COMMAND="docker exec -t -i \"dockerlocal3090\"-web-1 /bin/bash -i -c \"cd /var/www/simple-docker/scripts/server-$SERVER_NAME && chmod +x run-$SERVER_NAME && ./run-$SERVER_NAME\""
# if run is true and scripts/server-<server-name>/run-<server-name> exists, then we need to run scripts/server-<server-name>/run-<server-name>
if $RUN && [ -f scripts/server-$SERVER_NAME/run-$SERVER_NAME ]; then
printf "============ 🖥️\tServer name: $SERVER_NAME\n"
printf "============ 🏃\tRunning script: scripts/server-$SERVER_NAME/run-$SERVER_NAME\n"
# execute the script from inside the docker container
eval $COMMAND
exit 1
fi