changeset 363:cf7166c5c52f

INV-196 Move inventory scripts to prod directory
author Matt Calmes <calmes@ssdt-ohio.org>
date Mon, 16 Aug 2021 12:58:30 -0400
parents 91d530304bbf
children 33457af7a5f7 6be741c083a3
files prod/import-inventory.sh prod/install-inventory-app.sh prod/install-inventory-db.sh prod/update-inventory-app.sh
diffstat 4 files changed, 136 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prod/import-inventory.sh	Mon Aug 16 12:58:30 2021 -0400
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+BASEDIR="$PWD"
+# read required environment variables
+source $BASEDIR/.env/ssdt-inventory-shared.properties
+source $BASEDIR/.env/ssdt-inventory-import.properties
+#
+# docker login
+echo "Attempting to login to $artifactUrl"
+docker login $artifactUrl -u $artifactUser -p $artifactPassword
+# docker pull
+echo "Attempting to pull $artifactUrl/inventory-importapp:$importVersion"
+docker pull $artifactUrl/inventory-importapp:$importVersion
+#
+echo "Building docker run command"
+dockerParams="--rm --name $entityId-inventory-importapp -v $importPath:/extracts --network $entityId-inventory-net" 
+dockerParams="$dockerParams -e SPRING_DATASOURCE_URL=jdbc:postgresql://$entityId-inventory-db:5432/invdb -e SPRING_DATASOURCE_PASSWORD=$dbPassword"
+dockerParams="$dockerParams -e SPRING_PROFILES_ACTIVE=prod -e APPLICATION_ADMIN_PASSWORD=$adminPassword -i $artifactUrl/inventory-importapp:$importVersion"
+echo "Executing docker run command"
+docker run $dockerParams
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prod/install-inventory-app.sh	Mon Aug 16 12:58:30 2021 -0400
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# read required env variables
+BASEDIR="$PWD"
+source $BASEDIR/.env/ssdt-inventory-shared.properties
+source $BASEDIR/.env/ssdt-inventory-app.properties
+#
+# docker login
+echo "Attempting to login to $artifactUrl"
+docker login $artifactUrl -u $artifactUser -p $artifactPassword
+# docker pull app image
+echo "Attempting to pull $artifactUrl/inventory-app:$appVersion"
+docker pull $artifactUrl/inventory-app:$appVersion
+# 
+# Build docker run command based on setting in env files
+echo "Building docker run command"
+dockerRunCommand="docker run --name $entityId-inventory-app --restart=unless-stopped --network $entityId-inventory-net -e SPRING_DATASOURCE_URL=jdbc:postgresql://$entityId-inventory-db:5432/invdb"
+dockerRunCommand="$dockerRunCommand -e SPRING_DATASOURCE_PASSWORD=$dbPassword -e SPRING_PROFILES_ACTIVE=prod -e APPLICATION_ADMIN_PASSWORD=$adminPassword -e JAVA_OPTS=$java_opts"
+dockerRunCommand="$dockerRunCommand -e USAS_CONFIGURATION_HOST=$usasHost -e USAS_CONFIGURATION_PORT=$usasPort -e USAS_CONFIGURATION_APIKEY=$inventoryApiKey -e USAS_CONFIGURATION_REMOTEAPIKEY=$usasApiKey"
+if [ ! -z "$virtualHost" ]; then
+    dockerRunCommand="$dockerRunCommand -e VIRTUAL_HOST=$virtualHost"
+fi
+#
+if [ ! -z "$virtualPort" ]; then
+    dockerRunCommand="$dockerRunCommand -e VIRTUAL_PORT=$virtualPort"
+fi
+#
+if [ ! -z "$letsencryptHost" ]; then
+    dockerRunCommand="$dockerRunCommand -e LETSENCRYPT_HOST=$letsencryptHost"
+fi
+#
+if [ ! -z "$letsencryptEmail" ]; then
+    dockerRunCommand="$dockerRunCommand -e LETSENCRYPT_EMAIL=$letsencryptEmail"
+fi
+#
+if [ ! -z "$hostPort" ]; then
+    dockerRunCommand="$dockerRunCommand -p $hostPort"
+fi
+#
+dockerRunCommand="$dockerRunCommand -d $artifactUrl/inventory-app:$appVersion"
+#
+# Execute constructed docker run command to create $entityId-inventory-app container connected to db and docker network
+echo "Executing docker run command"
+$dockerRunCommand
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prod/install-inventory-db.sh	Mon Aug 16 12:58:30 2021 -0400
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# read required env variables
+BASEDIR="$PWD"
+source $BASEDIR/.env/ssdt-inventory-shared.properties
+source $BASEDIR/.env/ssdt-inventory-db.properties
+#
+# docker login
+echo "Attempting to login to $artifactUrl"
+docker login $artifactUrl -u $artifactUser -p $artifactPassword
+# docker pull db image 
+echo "Attempting to pull $artifactUrl/inventory-db:$dbVersion"
+docker pull $artifactUrl/inventory-db:$dbVersion
+#
+# Create inventory specific docker network for $entityId 
+echo "Attempting to create $entityId-inventory-net docker network"
+docker network create $entityId-inventory-net
+# docker run inventory-db (data mounted as volume) connected to $entityId-inventory-net docker network
+echo "Attempting to execute docker run command"
+docker run --name $entityId-inventory-db --restart=unless-stopped --mount source=$entityId-inventory-db,target=/var/lib/postgresql/data --network $entityId-inventory-net -e POSTGRES_DB=invdb -e POSTGRES_PASSWORD=$dbPassword -d $artifactUrl/inventory-db:$dbVersion
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prod/update-inventory-app.sh	Mon Aug 16 12:58:30 2021 -0400
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# read required env variables
+BASEDIR="$PWD"
+source $BASEDIR/.env/ssdt-inventory-shared.properties
+source $BASEDIR/.env/ssdt-inventory-app.properties
+#
+# docker login
+echo "Attempting to login to $artifactUrl"
+docker login $artifactUrl -u $artifactUser -p $artifactPassword
+# docker pull app image
+echo "Attempting to pull $artifactUrl/inventory-app:$appVersion"
+docker pull $artifactUrl/inventory-app:$appVersion
+# 
+# docker stop inventory app container
+echo "Attempting to stop $entityId-inventory-app container"
+docker stop $entityId-inventory-app
+#
+# docker rm inventory app container
+echo "Attempting to remove $entityId-inventory-app container"
+docker rm $entityId-inventory-app
+#
+# docker run inventory app container based on new image
+dockerRunCommand="docker run --name $entityId-inventory-app --restart=unless-stopped --network $entityId-inventory-net -e SPRING_DATASOURCE_URL=jdbc:postgresql://$entityId-inventory-db:5432/invdb"
+dockerRunCommand="$dockerRunCommand -e SPRING_DATASOURCE_PASSWORD=$dbPassword -e SPRING_PROFILES_ACTIVE=prod -e APPLICATION_ADMIN_PASSWORD=$adminPassword -e JAVA_OPTS=$java_opts"
+dockerRunCommand="$dockerRunCommand -e USAS_CONFIGURATION_HOST=$usasHost -e USAS_CONFIGURATION_PORT=$usasPort -e USAS_CONFIGURATION_APIKEY=$inventoryApiKey -e USAS_CONFIGURATION_REMOTEAPIKEY=$usasApiKey"
+if [ ! -z "$virtualHost" ]; then
+    dockerRunCommand="$dockerRunCommand -e VIRTUAL_HOST=$virtualHost"
+fi
+#
+if [ ! -z "$virtualPort" ]; then
+    dockerRunCommand="$dockerRunCommand -e VIRTUAL_PORT=$virtualPort"
+fi
+#
+if [ ! -z "$letsencryptHost" ]; then
+    dockerRunCommand="$dockerRunCommand -e LETSENCRYPT_HOST=$letsencryptHost"
+fi
+#
+if [ ! -z "$letsencryptEmail" ]; then
+    dockerRunCommand="$dockerRunCommand -e LETSENCRYPT_EMAIL=$letsencryptEmail"
+fi
+#
+if [ ! -z "$hostPort" ]; then
+    dockerRunCommand="$dockerRunCommand -p $hostPort"
+fi
+#
+dockerRunCommand="$dockerRunCommand -d $artifactUrl/inventory-app:$appVersion"
+#
+# Execute constructed docker run command to create $entityId-inventory-app container connected to db and docker network
+echo "Executing docker run command"
+$dockerRunCommand