From a347f39c1b8e9478499e3b01cb8ff0f5cc2853dd Mon Sep 17 00:00:00 2001 From: Dominik Date: Wed, 8 Jan 2020 13:05:23 +0100 Subject: [PATCH] Add support for Docker secrets --- .gitignore | 4 ++++ docker-compose.yml | 17 ++++++++++++----- startapp.sh | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8bc6b14 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +idrac_host.txt +idrac_password.txt +idrac_user.txt +idrac_port.txt diff --git a/docker-compose.yml b/docker-compose.yml index 4346519..5be4ea6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3.1' services: idrac1: @@ -21,11 +21,18 @@ services: ports: - 5801:5800 - 5901:5900 - environment: - - IDRAC_HOST=idrac2.example.org - - IDRAC_USER=root - - IDRAC_PASSWORD=1234 + secrets: + - idrac_host + - idrac_user + - idrac_password volumes: - /path/to/app:/app - /path/to/media:/vmedia - /path/to/screenshots:/screenshots +secrets: + idrac_host: + file: ./idrac_host.txt + idrac_user: + file: ./idrac_user.txt + idrac_password: + file: ./idrac_password.txt diff --git a/startapp.sh b/startapp.sh index 8641812..b8e84c0 100644 --- a/startapp.sh +++ b/startapp.sh @@ -6,6 +6,26 @@ NC='\033[0m' echo "Starting" +if [ -f "/run/secrets/idrac_host" ]; then + echo "Using Docker secret for IDRAC_HOST" + IDRAC_HOST="$(cat /run/secrets/idrac_host)" +fi + +if [ -f "/run/secrets/idrac_port" ]; then + echo "Using Docker secret for IDRAC_PORT" + IDRAC_PORT="$(cat /run/secrets/idrac_port)" +fi + +if [ -f "/run/secrets/idrac_user" ]; then + echo "Using Docker secret for IDRAC_USER" + IDRAC_USER="$(cat /run/secrets/idrac_user)" +fi + +if [ -f "/run/secrets/idrac_password" ]; then + echo "Using Docker secret for IDRAC_PASSWORD" + IDRAC_PASSWORD="$(cat /run/secrets/idrac_password)" +fi + if [ -z "${IDRAC_HOST}" ]; then echo "${RED}Please set a proper idrac host with IDRAC_HOST${NC}" sleep 2