Skip to content

Commit

Permalink
[dist] Parallelize docker builds with rake multitask
Browse files Browse the repository at this point in the history
Defines dependencies between rake docker:maintainer tasks and run them
as multitask. That way tasks that don't depend on each other can run in
parallel and thus reduce the build time.

This also means that the defined dependencies will also run if a single
image is rebuild, eg. via
'rake docker:maintainer:rebuild:frontend-base'.

My assumption is that we are usually building all images at once and
thus don't mind this change. If the old behaviour is still needed, we
can extend the rake tasks.

Real time of 'rake docker:maintainer:rebuild':

Before: 16m34.778s
After:   9m10.307s
  • Loading branch information
bgeuken committed Feb 14, 2018
1 parent adb00c6 commit 4abf612
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,27 @@ namespace :docker do
end

desc 'Rebuild all our static containers'
task rebuild: ['rebuild:base', 'rebuild:backend', 'rebuild:frontend-base', 'rebuild:mariadb', 'rebuild:memcached', 'rebuild:old-test-suite'] do
multitask rebuild: ['rebuild:all'] do
end
namespace :rebuild do
multitask all: [:base, :backend, 'frontend-base', :mariadb, :memcached, 'old-test-suite'] do
end
task :base do
sh "docker build docker-files/base/ #{tags_for(:base)} -f docker-files/base/Dockerfile.#{VERSION}"
end
task :mariadb do
task mariadb: [:base] do
sh "docker build docker-files/mariadb/ #{tags_for(:mariadb)} -f docker-files/mariadb/Dockerfile.mariadb"
end
task :memcached do
task memcached: [:base] do
sh "docker build docker-files/memcached/ #{tags_for(:memcached)} -f docker-files/memcached/Dockerfile.memcached"
end
task 'frontend-base' do
task 'frontend-base' => [:base] do
sh "docker build src/api/ #{tags_for('frontend-base')} -f src/api/docker-files/Dockerfile.frontend-base"
end
task :backend do
task backend: [:base] do
sh "docker build src/backend/ #{tags_for(:backend)} -f src/backend/docker-files/Dockerfile.backend"
end
task 'old-test-suite' do
task 'old-test-suite' => [:base] do
sh "docker build src/api/ #{tags_for('old-test-suite')} -f src/api/docker-files/Dockerfile.old-test-suite"
end
end
Expand Down

0 comments on commit 4abf612

Please sign in to comment.