-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·84 lines (76 loc) · 2.91 KB
/
build.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
84
#!/bin/bash
# load .env file
source .env
#######################################################################################
# check if nginx-proxy container is running
NGINX_PROXY_CONTAINER_NAME=nginx-proxy
if [ ! "$(docker ps -q -f name=$NGINX_PROXY_CONTAINER_NAME)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$NGINX_PROXY_CONTAINER_NAME)" ]; then
# cleanup
docker rm $NGINX_PROXY_CONTAINER_NAME
fi
# run your container
docker run --detach \
--name $NGINX_PROXY_CONTAINER_NAME \
--publish 80:80 \
--publish 443:443 \
--volume certs:/etc/nginx/certs \
--volume html:/usr/share/nginx/html \
--volume /var/run/docker.sock:/tmp/docker.sock:ro \
nginxproxy/nginx-proxy
else
echo "Container $NGINX_PROXY_CONTAINER_NAME is already running"
fi
# check if nginx-proxy-acme container is running
NGINX_PROXY_CONTAINER_NAME_ACME=nginx-proxy-acme
if [ ! "$(docker ps -q -f name=$NGINX_PROXY_CONTAINER_NAME_ACME)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$NGINX_PROXY_CONTAINER_NAME_ACME)" ]; then
# cleanup
docker rm $NGINX_PROXY_CONTAINER_NAME_ACME
fi
# run your container
docker run --detach \
--name $NGINX_PROXY_CONTAINER_NAME_ACME \
--volumes-from $NGINX_PROXY_CONTAINER_NAME \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--volume acme:/etc/acme.sh \
--env "DEFAULT_EMAIL=$MAIL_SERVER" \
nginxproxy/acme-companion
else
echo "Container $NGINX_PROXY_CONTAINER_NAME_ACME is already running"
fi
#######################################################################################
### HERE WE START THE WEBSITE CONTAINER ###
# check if website container is running
if [ "$(docker ps -q -f name=$WEBSITE_CONTAINER_NAME)" ]; then
echo "Container $WEBSITE_CONTAINER_NAME exists."
read -p "Do you want to remove the container and image $WEBSITE_CONTAINER_NAME? (y/[n]): " remove_container
# Check the user input and act accordingly
if [[ $remove_container == "y" || $remove_container == "Y" ]]; then
# stop and remove container
docker stop $WEBSITE_CONTAINER_NAME
docker remove $WEBSITE_CONTAINER_NAME
# remove image
docker rmi -f $WEBSITE_CONTAINER_NAME
else
echo "Nothing to do..."
exit 1
fi
else
echo "Container $WEBSITE_CONTAINER_NAME does not exist."
fi
# build the image
read -p "Do you want to build container and image $WEBSITE_CONTAINER_NAME? (y/[n]): " build_image
# Check the user input and act accordingly
if [[ $build_image == "y" || $build_image == "Y" ]]; then
docker build -t $WEBSITE_CONTAINER_NAME .
docker run --detach \
--name website_links \
--env "VIRTUAL_HOST=$SITES" \
--env "LETSENCRYPT_HOST=$SITES" \
--env "VIRTUAL_PORT=3000" \
$WEBSITE_CONTAINER_NAME
else
echo "Nothing to do..."
exit 1
fi