From 13d5d91750d394cc559631193e47d541f2ed121f Mon Sep 17 00:00:00 2001
From: Quentin Duchemin <quentinduchemin@tuta.io>
Date: Fri, 31 Jan 2020 15:55:11 +0100
Subject: [PATCH] [MISC] Add a helper production deployment script

---
 docker_prod.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 docker_prod.sh

diff --git a/docker_prod.sh b/docker_prod.sh
new file mode 100644
index 00000000..f60aa2f7
--- /dev/null
+++ b/docker_prod.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -e
+
+usage() {
+  echo -e "usage:\t$0 DIRECTORY, e.g. $0 pica-mattermost"
+  echo -e "\tDIRECTORY : name of the directory containing docker-compose.yml\n"
+  echo "This script is a helper to launch a service : it will create all needed volumes for the service,"
+  echo "pull the specified version of the image if any, and then launch docker-compose up -d."
+  exit 1
+}
+
+if [[ $# -ne 1 ]]; then
+  echo "ERROR : wrong number of arguments"
+  usage
+fi
+
+if [[ ! -d "$1" ]]; then
+  echo "ERROR : directory does not exist ($1)"
+  usage
+fi
+
+# Go to the folder of the service which will be tested
+cd "$1"
+
+echo -e "Starting procedure for \033[31m$1\e[0m..."
+
+echo -e "\n==== Pull Dockerfiles repository ===="
+echo -e "Using branch \033[31m $(git rev-parse --abbrev-ref HEAD)\e[0m, is this correct ? [y/N]"
+read ans
+
+if [ $ans == "y" ]; then
+  git pull
+else
+  echo "Aborting."
+  exit 0
+fi
+
+echo -e "\n==== Pull new versions of images ===="
+docker-compose pull
+
+echo -e "\n==== Ensure named external volumes are created ===="
+for v in $(docker-compose config --volumes); do
+  docker volume create "$v"
+done
+
+echo -e "\n==== Lauch $1 ===="
+docker-compose up -d
+
+echo -e "\n==== Print logs (use Ctrl+C to stop) ===="
+docker-compose logs -f
-- 
GitLab