Blame view

deploy.sh 2.18 KB
a7065b1b3   George Vlahavas   Add deploy and de...
1
  #!/bin/sh
bb68d7fdb   George Vlahavas   Dump all containe...
2
  dump_logs() {
248aceaba   George Vlahavas   Remove kea_compos...
3
    CONTAINERS="suricata elasticsearch logstash kibana webserver api od mltd mqtt timescaledb grafana"
bb68d7fdb   George Vlahavas   Dump all containe...
4
    for CONTAINER in $CONTAINERS; do
83d192a8b   George Vlahavas   Mark end of logs too
5
      echo "*** Logs for kea_$CONTAINER (start) ***"
bb68d7fdb   George Vlahavas   Dump all containe...
6
      docker logs kea_$CONTAINER
83d192a8b   George Vlahavas   Mark end of logs too
7
      echo "*** Logs for kea_$CONTAINER (end) ***"
bb68d7fdb   George Vlahavas   Dump all containe...
8
    done
626f6d63f   George Vlahavas   Show contents of ...
9
10
11
    echo "*** Contents of data directory (start) ***"
    ls -lR data
    echo "*** Contents of data directory (end) ***"
bb68d7fdb   George Vlahavas   Dump all containe...
12
  }
a5d31f18b   George Vlahavas   Show current dire...
13
  echo "Current directory: `pwd`"
a7065b1b3   George Vlahavas   Add deploy and de...
14
15
16
17
  # Login into the CUREX registry
  docker login https://registry.curex-project.eu:443/artifactory/curex-local/
  
  # pull all containers
fc3cc7824   George Vlahavas   Move composer to ...
18
19
  docker-compose \
    -f docker-compose-jfrog.yml \
fc3cc7824   George Vlahavas   Move composer to ...
20
    pull
a7065b1b3   George Vlahavas   Add deploy and de...
21
22
  
  sleep 1
1898c47f2   George Vlahavas   Loop until all al...
23
24
  # Keep the timestamp of when starting up containers
  TIME_START=`date +%s`
00ba62308   George Vlahavas   Stop containers b...
25
  # Just in case something is up from previous runs
a6777d113   George Vlahavas   Add some messages
26
  echo "Bringing down any previous containers..."
00ba62308   George Vlahavas   Stop containers b...
27
  docker-compose -f docker-compose-jfrog.yml down
a7065b1b3   George Vlahavas   Add deploy and de...
28
  # Run containers
a6777d113   George Vlahavas   Add some messages
29
  echo "Bringing up containers..."
a7065b1b3   George Vlahavas   Add deploy and de...
30
  docker-compose -f docker-compose-jfrog.yml up --detach
1898c47f2   George Vlahavas   Loop until all al...
31
32
  
  # loop until all containers are up
a6777d113   George Vlahavas   Add some messages
33
  echo "Checking if all containers are up..."
942cf4e44   George Vlahavas   Fix loop
34
  while true; do
1898c47f2   George Vlahavas   Loop until all al...
35
36
37
    # if any container other than composer has exited, bail out
    res=`docker ps -a | \
      grep "/curex-local/kea_" | \
1898c47f2   George Vlahavas   Loop until all al...
38
39
40
41
      grep "Exited" | \
      wc -l`
    if [ $res -gt 0 ]; then
      echo "ERROR: Some containers have exited."
24c412072   George Vlahavas   Show header line
42
      docker ps -a | grep "^CONTAINER\|/curex-local/kea_"
bb68d7fdb   George Vlahavas   Dump all containe...
43
      dump_logs
b9f8960be   George Vlahavas   Stop containers a...
44
      docker-compose -f docker-compose-jfrog.yml down
1898c47f2   George Vlahavas   Loop until all al...
45
46
47
48
49
      exit 1
    fi
    # count containers that are up
    res=`docker ps -a | \
      grep "/curex-local/kea_" | \
1898c47f2   George Vlahavas   Loop until all al...
50
51
52
      grep "Up" | \
      wc -l`
    if [ $res -eq 11 ]; then
a6777d113   George Vlahavas   Add some messages
53
      echo "All good!"
1898c47f2   George Vlahavas   Loop until all al...
54
55
56
57
58
59
60
      break
    fi
    # only wait for 10 mins until everything is up. It should be more than
    # enough.
    TIME_NOW=`date +%s`
    if [ $((TIME_NOW - TIME_START)) -ge 600 ]; then
      echo "ERROR: Timeout exceeded."
bb68d7fdb   George Vlahavas   Dump all containe...
61
      dump_logs
b9f8960be   George Vlahavas   Stop containers a...
62
      docker-compose -f docker-compose-jfrog.yml down
1898c47f2   George Vlahavas   Loop until all al...
63
64
65
66
67
68
69
      exit 2
    fi
    sleep 1
  done
  
  # Wait a bit more
  sleep 10
a7065b1b3   George Vlahavas   Add deploy and de...
70
71
  
  # create and populate the database
a6777d113   George Vlahavas   Add some messages
72
  echo "Creating and populating the database..."
9eacacfe5   George Vlahavas   Disable the TTY i...
73
  docker-compose -f docker-compose-jfrog.yml exec -T api php artisan migrate:fresh --seed --force
004404c2c   George Vlahavas   Try to debug Jenk...
74
75
  docker-compose -f docker-compose-jfrog.yml exec -T api pwd
  docker-compose -f docker-compose-jfrog.yml exec -T api ls -l
a7065b1b3   George Vlahavas   Add deploy and de...
76