From ccbfff4366a03048959c15faadd739c952da2b55 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 31 May 2019 15:42:11 +0400 Subject: [PATCH] dk: simplifier la gestion du nommage des services --- dk | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/dk b/dk index ae88da1..41b7438 100755 --- a/dk +++ b/dk @@ -147,6 +147,7 @@ function docker_set_run_args() { } function docker_check_name() { [ -n "$NAME" ] || die "Vous devez définir NAME dans .build.env" + if [ "$1" == set_container_name ]; then project_name="$NAME" container_name="${project_name//[^a-zA-Z0-9_-]/}" @@ -159,28 +160,27 @@ function compose_set_env_args() { if [ -f docker-compose.override.yml ]; then replace_env_args+=(-f docker-compose.override.yml) fi - local PROJECT_NAME=--none-- + + local PROJECT_NAME= PROJECT_NAME_REMOVE_SUFFIX=.service PROJECT_NAME_ADD_PROFILE=1 [ -f .compose.env ] && source ./.compose.env + + [ -n "$PROJECT_NAME" ] || PROJECT_NAME="$(basename -- "$(pwd)")" + PROJECT_NAME="${PROJECT_NAME%$PROJECT_NAME_REMOVE_SUFFIX}" + if [ -n "$PROFILE" ]; then if [ -f "docker-compose.$PROFILE.yml" ]; then replace_env_args+=(-f "docker-compose.$PROFILE.yml") fi - if [ "$PROJECT_NAME" != --none-- ]; then - if [ -z "$COMPOSE_PROJECT_NAME" ]; then - [ -n "$PROJECT_NAME" ] || PROJECT_NAME="$(basename -- "$(pwd)")" - COMPOSE_PROJECT_NAME="${PROJECT_NAME}_${PROFILE}" - fi - export COMPOSE_PROJECT_NAME - fi + [ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME${PROJECT_NAME_ADD_PROFILE:+_${PROFILE}}" + else + [ -n "$COMPOSE_PROJECT_NAME" ] || COMPOSE_PROJECT_NAME="$PROJECT_NAME" fi + export COMPOSE_PROJECT_NAME + if [ "$1" == set_container_name ]; then - if [ "$PROJECT_NAME" == --none-- ]; then - project_name="$(basename -- "$(pwd)")" - else - project_name="$PROJECT_NAME" - fi + project_name="$PROJECT_NAME" container_name="${project_name//[^a-zA-Z0-9_-]/}" - [ -n "$PROFILE" ] && container_name="${container_name}_$PROFILE" + [ -n "$PROFILE" -a -n "$PROJECT_NAME_ADD_PROFILE" ] && container_name="${container_name}_$PROFILE" fi }