-
Notifications
You must be signed in to change notification settings - Fork 3
/
start_dockerized.sh
executable file
·83 lines (72 loc) · 1.95 KB
/
start_dockerized.sh
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
#!/bin/bash
# Vars
ENVPATH="app/.env"
CONTAINERNAME="eon-bot"
IMAGEVERSION="1.4.3"
# Color variables
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
# Clear the color
clear='\033[0m'
# Check if script runs as root
if [ "$EUID" -ne 0 ]
then
echo -e "${yellow}Not running as root${clear}"
echo "assuming user has access to files and to docker socket if running docker."
echo
else
echo "Running script as ${cyan}root${clear}"
echo
fi
# Check if podman (and podman-docker) or docker is installed
echo "Looking for a container runtime"
if command -v podman &> /dev/null
then
echo "podman found"
CONTAINERRUNTIME="podman"
elif command -v docker &> /dev/null
then
echo "docker found"
CONTAINERRUNTIME="docker"
else
echo "No Container runtime found. please install docker or podman"
fi
echo
# Check if inventory file exists
if [ -f "$ENVPATH" ]; then
echo "$ENVPATH exists."
else
echo "$ENVPATH does not exist."
echo "Creating from example file"
cp $ENVPATH.example $ENVPATH
echo "Please edit ${ENVPATH}, the bot will not work without a token."
read -p "Press enter to continue"
fi
echo
# Stop and Remove running bot
echo "Stopping eon-bot if running with same name."
$CONTAINERRUNTIME stop ${CONTAINERNAME}
echo "Removing eon-bot container."
$CONTAINERRUNTIME rm ${CONTAINERNAME}
# Delete built image if same IMAGEVER
echo "Deleting image if image exists with the same tag."
$CONTAINERRUNTIME rmi ${CONTAINERNAME}:${IMAGEVERSION}
# Build Image
echo "Building image"
$CONTAINERRUNTIME build . --no-cache -t ${CONTAINERNAME}:${IMAGEVERSION}
# Run Image
echo "Run image"
$CONTAINERRUNTIME run -d \
--mount type=bind,source=$PWD/app/.env,target=/eon-bot/app/.env,readonly \
--restart unless-stopped \
--name ${CONTAINERNAME} \
${CONTAINERNAME}:${IMAGEVERSION}
# Sleep 3 seconds
sleep 3
# Print running containers
echo "Container status"
$CONTAINERRUNTIME ps -a