From 31c479fe058b9b33c10c116de1e9c5b84f879a51 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Wed, 14 Oct 2020 09:48:48 +0200 Subject: [PATCH 1/3] added dockertags script --- dockertags.sh | 28 ++++++++++++++++++++++++++++ lib/config.shlib | 6 +++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100755 dockertags.sh diff --git a/dockertags.sh b/dockertags.sh new file mode 100755 index 0000000..502be5f --- /dev/null +++ b/dockertags.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ $# -lt 1 ] +then +cat << HELP + +dockertags -- list all tags for a Docker image on a remote registry. + +EXAMPLE: + - list all tags for ubuntu: + dockertags ubuntu + + - list all php tags containing apache: + dockertags php apache + +HELP +fi + +image="$1" +# REMEMBER wget is not native on mac os. +tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'` + +if [ -n "$2" ] +then + tags=` echo "${tags}" | grep "$2" ` +fi + +echo "${tags}" diff --git a/lib/config.shlib b/lib/config.shlib index bf1e486..e21eebd 100644 --- a/lib/config.shlib +++ b/lib/config.shlib @@ -12,9 +12,9 @@ read() { # path, key -> value } delete() { # path, key - test -f "$1" && sed -i "" -e "/^$(echo $2 | sed_escape).*$/d" "$1" - # UNIX VERSION: - # test -f "$1" && sed -i "/^$(echo $2 | sed_escape).*$/d" "$1" + test -f "$1" && sed -i "/^$(echo $2 | sed_escape).*$/d" "$1" + # MacOs + # test -f "$1" && sed -i "" -e "/^$(echo $2 | sed_escape).*$/d" "$1" } has_key() { # path, key From 3557027788b9375047d31dde8b1c789e8b83f2a6 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Wed, 14 Oct 2020 15:51:44 +0200 Subject: [PATCH 2/3] Added stable versions config. fixed bugs. added dockertags.shlib --- config.cfg | 5 ++--- dockertags.sh | 28 -------------------------- init_setup.sh | 44 ++++++++++++++++++++++++++++++----------- lib/config.cfg.defaults | 3 +++ lib/dockertags.shlib | 12 +++++++++++ 5 files changed, 49 insertions(+), 43 deletions(-) delete mode 100755 dockertags.sh create mode 100644 lib/dockertags.shlib diff --git a/config.cfg b/config.cfg index 2d1131a..1b9468a 100644 --- a/config.cfg +++ b/config.cfg @@ -1,8 +1,7 @@ -# Services rest_port=8080 frontend_port=80 - -# DB Settings db_user=root db_port=27017 db_name=filefighter +use_stable_versions=true +db_password= diff --git a/dockertags.sh b/dockertags.sh deleted file mode 100755 index 502be5f..0000000 --- a/dockertags.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -if [ $# -lt 1 ] -then -cat << HELP - -dockertags -- list all tags for a Docker image on a remote registry. - -EXAMPLE: - - list all tags for ubuntu: - dockertags ubuntu - - - list all php tags containing apache: - dockertags php apache - -HELP -fi - -image="$1" -# REMEMBER wget is not native on mac os. -tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'` - -if [ -n "$2" ] -then - tags=` echo "${tags}" | grep "$2" ` -fi - -echo "${tags}" diff --git a/init_setup.sh b/init_setup.sh index d8f174f..89f786f 100755 --- a/init_setup.sh +++ b/init_setup.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash source lib/config.shlib; # load the config library functions +source lib/dockertags.shlib # load docker functions. # Check if docker is running if ! docker info >/dev/null 2>&1; then @@ -14,10 +15,14 @@ frontendname="FileFighterFrontend" dbname="FileFighterDB" networkname="FileFighterNetwork" +# latest stable versions. +frontendVersion="latest" #"$(getTagsByName filefighter/frontend v | tail -1)" +restVersion="latest" #$(getTagsByName filefighter/rest v | tail -1)" + # Startup Message. echo "" echo "-------------------------< FileFighter >--------------------------" -echo "| Version 0.0.1 last updated at 10.10.20 |" +echo "| Version 0.0.1. Last updated at 14.10.20 |" echo "| Developed by Gimleux, Valentin, Open-Schnick. |" echo "| Development Blog: https://filefighter.github.io |" echo "| The code can be found at: https://www.github.com/filefighter |" @@ -33,35 +38,41 @@ db_port="$(read ./config.cfg db_port)" db_name="$(read ./config.cfg db_name)" db_user="$(read ./config.cfg db_user)" db_password="$(read ./config.cfg db_password)" +use_stable_versions="$(read ./config.cfg use_stable_versions)" if ! [[ $frontend_port ]]; then echo "Config for frontend_port not found, using defaults." - frontend_port="$(read ./config.cfg frontend_port)" + frontend_port="$(read ./config.cfg.defaults frontend_port)" fi if ! [[ $rest_port ]]; then echo "Config for rest_port not found, using defaults." - rest_port="$(read ./config.cfg rest_port)" + rest_port="$(read ./config.cfg.defaults rest_port)" fi if ! [[ $db_port ]]; then echo "Config for db_port not found, using defaults." - db_port="$(read ./config.cfg db_port)" + db_port="$(read ./config.cfg.defaults db_port)" fi if ! [[ $db_name ]]; then echo "Config for db_name not found, using defaults." - db_name="$(read ./config.cfg db_name)" + db_name="$(read ./config.cfg.defaults db_name)" fi if ! [[ $db_user ]]; then echo "Config for db_user not found, using defaults." - db_user="$(read ./config.cfg db_user)" + db_user="$(read ./config.cfg.defaults db_user)" fi if ! [[ $db_password ]]; then echo "Config for db_password not found, using defaults." - db_password="$(read ./config.cfg db_password)" + db_password="$(read ./config.cfg.defaults db_password)" +fi + +if ! [[ $use_stable_versions ]]; then + echo "Config for use_stable_versions not found, using defaults." + use_stable_versions="$(read ./config.cfg.defaults use_stable_versions)" fi # Check if (default) password was empty. @@ -72,6 +83,15 @@ if ! [[ $db_password ]]; then write $configFilePath db_password $db_password fi +# Check versions config +if [[ $use_stable_versions == "true" ]]; then + echo "Installing stable versions." + frontendVersion="$(getTagsByName filefighter/frontend v | tail -1)" + restVersion="$(getTagsByName filefighter/rest v | tail -1)" +else + echo "Installing latest versions. Be aware that minor bugs could occur. Please report found bugs: filefigther@t-online.de." +fi + # Finished Config: echo "Finished reading config. Building containers..." @@ -90,7 +110,7 @@ echo "Creating necessary network." docker network create $networkname >/dev/null 2>&1 # Database -echo "Creating DB Container." +echo "Creating DB Container, with tag: latest." docker create \ -e MONGO_INITDB=$db_name \ -e MONGO_INITDB_ROOT_USERNAME=$db_user \ @@ -102,7 +122,7 @@ docker start $dbname >/dev/null 2>&1 sleep 3 # waiting 3 seconds for mongo to start. # REST APP -echo "Creating REST Container." +echo "Creating REST Container, with tag: $restVersion." docker create \ -e DB_USERNAME=$db_user \ -e DB_PASSWORD=$db_password \ @@ -111,15 +131,15 @@ docker create \ -e SPRING_PROFILES_ACTIVE="prod" \ -p $rest_port:8080 \ --network $networkname \ ---name $restname filefighter/rest:latest >/dev/null 2>&1 +--name $restname filefighter/rest:$restVersion >/dev/null 2>&1 docker start $restname >/dev/null 2>&1 # Frontend -echo "Creating Frontend Container." +echo "Creating Frontend Container, with tag: $frontendVersion." docker create \ -e REST_PORT=$rest_port \ -p $frontend_port:5000 \ ---name $frontendname filefighter/frontend:0.0.1 >/dev/null 2>&1 +--name $frontendname filefighter/frontend:$frontendVersion >/dev/null 2>&1 docker start $frontendname >/dev/null 2>&1 # DataHandler diff --git a/lib/config.cfg.defaults b/lib/config.cfg.defaults index 1b827fd..732eec6 100644 --- a/lib/config.cfg.defaults +++ b/lib/config.cfg.defaults @@ -9,3 +9,6 @@ db_user=root db_password= db_port=27017 db_name=filefighter + +# Versions +use_stable_versions=true \ No newline at end of file diff --git a/lib/dockertags.shlib b/lib/dockertags.shlib new file mode 100644 index 0000000..a75e80c --- /dev/null +++ b/lib/dockertags.shlib @@ -0,0 +1,12 @@ +getTagsByName() { + image="$1" + # REMEMBER wget is not native on mac os. + tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'` + + if [ -n "$2" ] + then + tags=` echo "${tags}" | grep "$2" ` + fi + + echo "${tags}" +} From 1a4ef8ce612aa2a6fff683d36b5db0993dd422f2 Mon Sep 17 00:00:00 2001 From: open-schnick Date: Wed, 14 Oct 2020 16:13:26 +0200 Subject: [PATCH 3/3] Now generates random pw if there is none specified --- init_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init_setup.sh b/init_setup.sh index 89f786f..5849760 100755 --- a/init_setup.sh +++ b/init_setup.sh @@ -79,7 +79,7 @@ fi if ! [[ $db_password ]]; then # Create new Password echo "Creating new random password for the database." - db_password="asdasdasd" + db_password=$(wget -qO- "https://www.passwordrandom.com/query?command=password&scheme=rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr") write $configFilePath db_password $db_password fi