Skip to content

Commit

Permalink
Remove Docker Compose v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
sichapman authored Jan 16, 2025
1 parent 858d7c9 commit a4ec792
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
33 changes: 6 additions & 27 deletions logic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,18 @@
end

puts colorize_lightblue('Building images...')
# v2 already builds in parallel
if ENV['DC_VERSION'] == '2'
if run_command("#{ENV['DC_CMD']} build " + (options['nopull'] ? '' : '--pull')) != 0
puts colorize_red('Something went wrong when building your app images. Check the output above.')
exit
end
elsif run_command("#{ENV['DC_CMD']} build --parallel " + (options['nopull'] ? '' : '--pull')) != 0
puts colorize_yellow('Build command failed. Trying without --parallel')
# Might not be running a version of compose that supports --parallel, try one more time
if run_command("#{ENV['DC_CMD']} build " + (options['nopull'] ? '' : '--pull')) != 0
puts colorize_red('Something went wrong when building your app images. Check the output above.')
exit
end
if run_command("#{ENV['DC_CMD']} build " + (options['nopull'] ? '' : '--pull')) != 0
puts colorize_red('Something went wrong when building your app images. Check the output above.')
exit
end

end

if options['provision_commodities']
# Before creating any containers, let's see what already exists (in case we need to override provision status)
existing_containers = []
# v2 --services seems to work differently. it already excludes deleted containers
if ENV['DC_VERSION'] == '2'
run_command("#{ENV['DC_CMD']} ps --services", existing_containers)
else
run_command('docker-compose --compatibility ps --services --filter "status=stopped" && '\
'docker-compose --compatibility ps --services --filter "status=running"',
existing_containers)
end
run_command("#{ENV['DC_CMD']} ps --services", existing_containers)

# Let's force a recreation of the containers here so we know they're using up-to-date images
puts colorize_lightblue('Creating containers...')
Expand All @@ -229,13 +214,7 @@

# Now we identify exactly which containers we've created in the above command
existing_containers2 = []
if ENV['DC_VERSION'] == '2'
run_command("#{ENV['DC_CMD']} ps --services", existing_containers2)
else
run_command('docker-compose --compatibility ps --services --filter "status=stopped" && '\
'docker-compose --compatibility ps --services --filter "status=running"',
existing_containers2)
end
run_command("#{ENV['DC_CMD']} ps --services", existing_containers2)
new_containers = existing_containers2 - existing_containers

# Provision all commodities (by executing fragments found in app repos)
Expand Down
18 changes: 1 addition & 17 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
export DC_VERSION=1

# No docker-compose command means v2 is implied
docker-compose > /dev/null 2>&1
retVal=$?
if [ $retVal -ne 0 ]; then
DC_VERSION=2
else
docker-compose version 2>&1 | grep -q 'version 2\|version v2' && DC_VERSION=2
fi

if [ "$DC_VERSION" = "2" ] ; then
echo -e "\e[35mUsing Docker-Compose version 2 commands\e[0m"
export DC_CMD='docker compose'
else
export DC_CMD='docker-compose --compatibility'
fi
export DC_CMD='docker compose'

# Best effort check that the script has been sourced.
# From https://stackoverflow.com/a/28776166
Expand Down
2 changes: 1 addition & 1 deletion scripts/add-aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function localstack(){
function fullreset(){
stop ${1}
remove ${1}
ruby $DEV_ENV_ROOT_DIR/scripts/commodities_standalone.rb ${1} $DC_VERSION
ruby $DEV_ENV_ROOT_DIR/scripts/commodities_standalone.rb ${1}
rebuild ${1}
}

Expand Down

0 comments on commit a4ec792

Please sign in to comment.