Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 108 additions & 108 deletions dockerc
Original file line number Diff line number Diff line change
Expand Up @@ -713,17 +713,17 @@ ABSTRACT_CONTEXT='false'
# Unless context is '--': in this case, use no compose file argument
if [ "$CONTEXT" != '--' ]; then

CONTEXT_ONLY_ROOT_STANDARD='false'
CONTEXT_SKIP_ROOT_STANDARD='false'

if [ "$CONTEXT" = '-' ] || [ "$CONTEXT" = '.' ]; then
# Use default context
CONTEXT=''

elif [ "$(echo "$CONTEXT" | cut -c1)" = '.' ]; then
elif [ "$(echo "$CONTEXT" | cut -c1)" = '-' ]; then
# Only look for standard root level compose files
CONTEXT_ONLY_ROOT_STANDARD='true'
# Remove leading dot
CONTEXT="${CONTEXT#.}"
CONTEXT_SKIP_ROOT_STANDARD='true'
# Remove leading dash
CONTEXT="${CONTEXT#-}"
fi

# Iterate over directories:
Expand Down Expand Up @@ -761,15 +761,19 @@ if [ "$CONTEXT" != '--' ]; then
EOF
fi

# Check for standard root level compose file
if [ "$CONTEXT_SKIP_ROOT_STANDARD" != 'true' ]; then

# Check for standard root level compose file

# Look for root compose file
COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" '' '' "$COMPOSE_EXTENSION")
COMPOSE_LOOK_CODE=$?
if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then
# Compose file found
LVL1_COMPOSE_FILE_ARGS="$LVL1_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE"
LVL1_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true')
fi

# Look for root compose file
COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" '' '' "$COMPOSE_EXTENSION")
COMPOSE_LOOK_CODE=$?
if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then
# Compose file found
LVL1_COMPOSE_FILE_ARGS="$LVL1_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE"
LVL1_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true')
fi

# Parse context parts
Expand Down Expand Up @@ -830,7 +834,7 @@ if [ "$CONTEXT" != '--' ]; then
fi

done <<-EOF
$(echo "$CONTEXT" | tr '-' "\n" | tr '.' "\n")
$(echo "$CONTEXT" | tr '.' "\n")
EOF

if [ -n "$LVL2_COMPOSE_FILE_ARGS" ]; then
Expand All @@ -840,108 +844,104 @@ if [ "$CONTEXT" != '--' ]; then

fi

if [ "$CONTEXT_ONLY_ROOT_STANDARD" != 'true' ]; then
LVL2_COMPOSE_FILE_ARGS=''
LVL2_ENV_FILE_ARGS="$LVL1_ENV_FILE_ARGS"
LVL2_ABSTRACT_CONTEXT='false'

LVL2_COMPOSE_FILE_ARGS=''
LVL2_ENV_FILE_ARGS="$LVL1_ENV_FILE_ARGS"
LVL2_ABSTRACT_CONTEXT='false'
# Check for non-standard root level compose files

# Check for non-standard root level compose files

# Extract first context part
CONTEXT_FIRST="${CONTEXT%%.*}"
CONTEXT_REST="$([ "$CONTEXT" = "$CONTEXT_FIRST" ] && echo '' || echo "${CONTEXT#*.}")"

# Look for universal env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_FIRST")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi
# Extract first context part
CONTEXT_FIRST="${CONTEXT%%.*}"
CONTEXT_REST="$([ "$CONTEXT" = "$CONTEXT_FIRST" ] && echo '' || echo "${CONTEXT#*.}")"

# Look for context env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$CONTEXT_FIRST")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi
# Look for universal env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_FIRST")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi

# Look for root compose file
COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" '' "$COMPOSE_EXTENSION")
COMPOSE_LOOK_CODE=$?
if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then
# Compose file found
LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE"
LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true')
fi
# Look for context env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$CONTEXT_FIRST")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi

# Look for root compose file
COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" '' "$COMPOSE_EXTENSION")
COMPOSE_LOOK_CODE=$?
if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then
# Compose file found
LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE"
LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true')
fi

# Parse context parts
if [ -n "$CONTEXT_REST" ]; then

LVL2_PREFIX=''

while read -r CONTEXT_PART; do

if [ -z "$CONTEXT_PART" ]; then
# Skip empty parts
continue
fi

LVL2_PREFIX="$LVL2_PREFIX.$CONTEXT_PART"

# Look for universal env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_PART")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi

# Look for context env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$LVL2_PREFIX")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi

# Parse context parts
if [ -n "$CONTEXT_REST" ]; then

LVL2_PREFIX=''

while read -r CONTEXT_PART; do

if [ -z "$CONTEXT_PART" ]; then
# Skip empty parts
continue
fi

LVL2_PREFIX="$LVL2_PREFIX.$CONTEXT_PART"

# Look for universal env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_PART")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi

# Look for context env files
ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$LVL2_PREFIX")
ENV_LOOK_CODE=$?
if [ "$ENV_LOOK_CODE" -eq 0 ]; then
while read -r ENV_LOOK_FILE; do
LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE"
done <<-EOF
$(echo "$ENV_LOOK_FILES")
EOF
fi

# Look for context compose file
COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" "$LVL2_PREFIX" "$COMPOSE_EXTENSION")
COMPOSE_LOOK_CODE=$?
if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then
# Context compose file found
LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE"
LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true')

else
# Context compose file not found: invalidate LVL2 and break loop
LVL2_COMPOSE_FILE_ARGS=''
break
fi

done <<-EOF
$(echo "$CONTEXT_REST" | tr '-' "\n" | tr '.' "\n")
EOF

if [ -n "$LVL2_COMPOSE_FILE_ARGS" ]; then
# Context resolved: break loop
# Look for context compose file
COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" "$LVL2_PREFIX" "$COMPOSE_EXTENSION")
COMPOSE_LOOK_CODE=$?
if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then
# Context compose file found
LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE"
LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true')

else
# Context compose file not found: invalidate LVL2 and break loop
LVL2_COMPOSE_FILE_ARGS=''
break
fi

done <<-EOF
$(echo "$CONTEXT_REST" | tr '.' "\n")
EOF

if [ -n "$LVL2_COMPOSE_FILE_ARGS" ]; then
# Context resolved: break loop
break
fi

fi
Expand Down
Empty file.
5 changes: 1 addition & 4 deletions test/test/structure_1_22_00/test_disambiguation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def test_dev(file = __file__):
'dev',
)
dockerc.assert_context_ok(
# TODO: change behavior
format_dockerc_stdout(
b'docker compose'
b' -f ./docker-compose.yml'
Expand All @@ -22,11 +21,9 @@ def test_dash_dev(file = __file__):
'-dev',
)
dockerc.assert_context_ok(
# TODO: change behavior
format_dockerc_stdout(
b'docker compose'
b' -f ./docker-compose.yml'
b' -f ./docker-compose.dev.yml'
b' -f ./docker-compose-dev.yml'
b' up -d'
),
)
Expand Down
16 changes: 16 additions & 0 deletions test/test/structure_1_22_00/test_long.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from test.src.format_dockerc_stdout import format_dockerc_stdout
from test.src.TestDirContext import TestDirContext

def test_long(file = __file__):
with TestDirContext(file) as ctx:
dockerc = ctx.run_dockerc(
'long-name',
)
dockerc.assert_context_ok(
format_dockerc_stdout(
b'docker compose'
b' -f ./docker-compose.yml'
b' -f ./docker-compose.long-name.yml'
b' up -d'
),
)
Loading