-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeployment-react-graphql-express-postgres.sh
More file actions
56 lines (49 loc) · 1.67 KB
/
deployment-react-graphql-express-postgres.sh
File metadata and controls
56 lines (49 loc) · 1.67 KB
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
#!/bin/bash
# Let other container still running as long as they have different name
echo "Stop Docker Container ..."
# List of container names to be stopped
Container="web-app api postgres webserver"
for container_name in $Container; do
if [ "$(docker ps -q -f name=$container_name)" ]; then
if [ $(docker inspect -f '{{.State.Running}}' $container_name) = "true" ]; then
echo "Stop Container: "$container_name
docker stop $container_name
fi
fi
done
if [[ $(docker ps -a | grep -i Exited) ]]; then
echo "Remove Container...";
docker rm $(docker ps -a | grep -i Exited | grep -Eo '^[^ ]+');
fi
if [[ $(docker images -a | grep -i ago) ]]; then
echo "Remove Images...";
docker image prune -af;
fi
if [[ $(docker volume ls -f dangling=true | grep local) ]]; then
echo "Clean up orphaned volumes"
docker volume rm $(docker volume ls -qf dangling=true);
fi
if [[ $(docker network ls| grep local) ]]; then
echo "Clean up orphaned networks";
docker network prune $(docker network ls -q);
fi
echo "Start Docker Compose ..."
docker-compose up -d
# The database is not ready when the api container starts so the api container has to restart again.
sleep 10;
docker restart api;
Container="web-app api postgres webserver"
for container_name in $Container; do
if [ "$(docker ps -q -f name=$container_name)" ]; then
if [ ! $(docker inspect -f '{{.State.Running}}' $container_name) = "true" ]; then
echo "Container not running: "$container_name
docker ps -a
exit
fi
fi
done
docker ps -a
echo
echo "Call URL at http://localhost:3000/"
echo
echo "** Deployment successful **"