Skip to content

Commit

Permalink
change docker env switch based on @ppiotr3k and @alles-klar suggestio…
Browse files Browse the repository at this point in the history
…ns, using symlinks
  • Loading branch information
ptrovatelli committed May 21, 2019
1 parent f684104 commit c730322
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 18 deletions.
4 changes: 0 additions & 4 deletions docker-compose.override.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ services:
published: 3306
protocol: tcp
mode: host
volumes:
- defectdojo_data:/var/lib/mysql
volumes:
defectdojo_data: {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ services:
mode: host
environment:
MYSQL_DATABASE: ${DD_TEST_DATABASE_NAME:-test_defectdojo}
volumes:
- defectdojo_data_unittest:/var/lib/mysql
volumes:
defectdojo_data_unittest: {}
8 changes: 0 additions & 8 deletions docker-compose.override.yml

This file was deleted.

4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ services:
MYSQL_PASSWORD: ${DD_DATABASE_PASSWORD:-defectdojo}
MYSQL_DATABASE: ${DD_DATABASE_NAME:-defectdojo}
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
volumes:
- defectdojo_data:/var/lib/mysql
rabbitmq:
image: rabbitmq:3.7
volumes:
defectdojo_data: {}
90 changes: 90 additions & 0 deletions docker/setEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

# docker-compose.*.yml files names and their position compared to this script.
# Here: in parent directory.
target_dir="${0%/*}/.."
override_link='docker-compose.override.yml'
override_file_dev='docker-compose.override.dev.yml'
override_file_unit_tests='docker-compose.override.unit_tests.yml'


# Get the current environment and tells what are the options
function show_current {
get_current
say_switch
}


# Get the current environment
# Output variable: current_env
function get_current {
if [ -L ${override_link} ]
then
current_env=$(expr $(basename $(readlink -f docker-compose.override.yml)) : "^docker-compose.override.\(.*\).yml$")
else
current_env=release
fi
}

# Tell to which environments we can switch
function say_switch {
echo "Using '${current_env}' configuration."
for one_env in dev unit_tests release
do
if [ "${current_env}" != ${one_env} ]; then
echo "-> switch to '${one_env}' with '${0} ${one_env}'"
fi
done
}


function set_release {
get_current
if [ "${current_env}" != release ]
then
# In release configuration there is no override file
rm ${override_link}
docker-compose down
echo "Now using 'release' configuration."
else
echo "Already using 'release' configuration."
fi
}


function set_dev {
get_current
if [ "${current_env}" != dev ]
then
rm -f ${override_link}
ln -s ${override_file_dev} ${override_link}
docker-compose down
echo "Now using 'dev' configuration."
else
echo "Already using 'dev' configuration."
fi
}


function set_unit_tests {
get_current
if [ "${current_env}" != unit_tests ]
then
rm -f ${override_link}
ln -s ${override_file_unit_tests} ${override_link}
docker-compose down
echo "Now using 'unit_tests' configuration."
else
echo "Already using 'unit_tests' configuration."
fi
}

# Change directory to allow working with relative paths.
cd ${target_dir}

if [ ${#} -eq 1 ] && [[ 'dev unit_tests release' =~ "${1}" ]]
then
set_"${1}"
else
show_current
fi
2 changes: 0 additions & 2 deletions docker/setEnvDev.sh

This file was deleted.

2 changes: 0 additions & 2 deletions docker/setEnvRelease.sh

This file was deleted.

2 changes: 0 additions & 2 deletions docker/setEnvUnitTests.sh

This file was deleted.

0 comments on commit c730322

Please sign in to comment.