You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8KB

  1. #!/bin/bash
  2. STACK_NAME=$1
  3. BUILD=$2
  4. if [ -z $BUILD ]; then
  5. BUILD=1;
  6. fi
  7. if [ $# -eq 0 ]; then
  8. echo "You must pass stack name as a parameter"
  9. exit 1
  10. fi
  11. # Delete previous running stack
  12. docker stack rm ${STACK_NAME}
  13. # Build images
  14. if [ $BUILD -eq 1 ]; then
  15. docker-compose build
  16. docker push bingen/rpi-openldap
  17. docker push bingen/rpi-mariadb
  18. docker push bingen/rpi-haproxy
  19. docker push bingen/rpi-mailserver
  20. docker push bingen/rpi-nextcloud
  21. docker push bingen/rpi-zoneminder
  22. fi
  23. # Deploy Stack
  24. # seen here: https://github.com/docker/docker/issues/29133#issuecomment-278198683
  25. env $(cat .env | grep "^[A-Z]" | xargs) \
  26. docker stack deploy --compose-file docker-compose.yml ${STACK_NAME}
  27. echo Wait for services to start
  28. sleep 60
  29. # ##### Add users to LDAP ###### #
  30. ./add_users.sh ${STACK_NAME}
  31. # Wait for Nextcloud
  32. NC_UP=0
  33. while [ $NC_UP -eq 0 ]; do
  34. # TODO: Use docker inspect Go templates
  35. #NC_IP=$(docker network inspect debuen_default | grep -A 3 nextcloud | grep IPv4Address | cut -d':' -f 2 | cut -d'"' -f 2 | cut -d'/' -f 1)
  36. # Find Nextcloud container
  37. SERVICE=nextcloud
  38. host=$(docker stack ps ${STACK_NAME} | grep Running | grep ${SERVICE} | awk '{ print $4 }')
  39. #echo Host=$host
  40. if [ -z $host ]; then
  41. echo "No host found!";
  42. continue;
  43. fi
  44. container=$(ssh $host 'docker ps | grep '${SERVICE}' | cut -f1 -d" "')
  45. #echo Container=$container
  46. if [ -z $container ]; then
  47. echo "Qué me estás container?!";
  48. continue;
  49. fi
  50. #NC_IP=$(ssh $host "docker exec ${container} sh -c 'ifconfig eth1' | grep 'inet ' | cut -d':' -f 2 | cut -d' ' -f 1")
  51. curl http://${host}/index.nginx-debian.html 2>/dev/null | grep title | grep Welcome 1>/dev/null;
  52. NC_UP=$((1 - $?));
  53. done;
  54. ./letsencrypt.sh ${STACK_NAME}