Skip to content

Commit

Permalink
[dist] Reduce build context of docker builds
Browse files Browse the repository at this point in the history
Every docker image build has a build context that contains files needed
to build the image and a docker file that contains the recipe for the
image build.

By reducing the build context we decrease the overhead of a docker build
quite a bit and thus speed things up (see table below).

In addition clearer seperation of the various docker files we have and
their dependencies, eg. contrib/start_old_tests is only needed by
Dockerfile.old-test-suite.

docker image    before   | after
-------------------------|----------
base:           175.8 MB |  4.096 kB
backend:        175.8 MB |  7.025 MB
frontend-base:  175.8 MB | 18.940 MB
mariadb:        175.8 MB |  2.560 kB
memcached:      175.8 MB |  2.048 kB
old-test-suite: 175.8 MB | 18.940 MB
                         |
build time*:   0m16.364s | 0m1.459s

* running 'time rake docker:maintainer:rebuild' with no source changes
  applied (using cached docker images)
  • Loading branch information
bgeuken committed Feb 13, 2018
1 parent 4a857e2 commit 8576fe1
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 20 deletions.
6 changes: 0 additions & 6 deletions .dockerignore

This file was deleted.

12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ namespace :docker do
end
namespace :rebuild do
task :base do
sh "docker build . -t openbuildservice/base:#{VERSION} -t openbuildservice/base -f Dockerfile.#{VERSION}"
sh "docker build docker-files/base/ -t openbuildservice/base:#{VERSION} -t openbuildservice/base -f docker-files/base/Dockerfile.#{VERSION}"
end
task :mariadb do
sh "docker build . -t openbuildservice/mariadb:#{VERSION} -t openbuildservice/mariadb -f Dockerfile.mariadb"
sh "docker build docker-files/mariadb/ -t openbuildservice/mariadb:#{VERSION} -t openbuildservice/mariadb -f docker-files/mariadb/Dockerfile.mariadb"
end
task :memcached do
sh "docker build . -t openbuildservice/memcached:#{VERSION} -t openbuildservice/memcached -f Dockerfile.memcached"
sh "docker build docker-files/memcached/ -t openbuildservice/memcached:#{VERSION} -t openbuildservice/memcached -f docker-files/memcached/Dockerfile.memcached"
end
task 'frontend-base' do
sh "docker build . -t openbuildservice/frontend-base:#{VERSION} -t openbuildservice/frontend-base -f Dockerfile.frontend-base"
sh "docker build src/api/ -t openbuildservice/frontend-base:#{VERSION} -t openbuildservice/frontend-base -f src/api/docker-files/Dockerfile.frontend-base"
end
task :backend do
sh "docker build . -t openbuildservice/backend:#{VERSION} -t openbuildservice/backend -f Dockerfile.backend"
sh "docker build src/backend/ -t openbuildservice/backend:#{VERSION} -t openbuildservice/backend -f src/backend/docker-files/Dockerfile.backend"
end
task 'old-test-suite' do
sh "docker build . -t openbuildservice/old-test-suite:#{VERSION} -t openbuildservice/old-test-suite -f Dockerfile.old-test-suite"
sh "docker build src/api/ -t openbuildservice/old-test-suite:#{VERSION} -t openbuildservice/old-test-suite -f src/api/docker-files/Dockerfile.old-test-suite"
end
end

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
frontend:
image: openbuildservice/frontend
build:
context: .
context: src/api
volumes:
- .:/obs
ports:
Expand Down
1 change: 1 addition & 0 deletions docker-files/api
1 change: 1 addition & 0 deletions docker-files/backend
2 changes: 1 addition & 1 deletion Dockerfile.42.3 → docker-files/base/Dockerfile.42.3
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN zypper -n install --no-recommends --replacefiles \
timezone ack glibc-locale sudo aaa_base

# Add our bootstrap script
ADD contrib/docker-bootstrap.sh /root/bin/docker-bootstrap.sh
ADD docker-bootstrap.sh /root/bin/docker-bootstrap.sh

# Add our user
RUN useradd -m frontend
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tmp/*
log/*

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ RUN /root/bin/docker-bootstrap.sh frontend
# Install other requirements
RUN npm install -g jshint

ADD src/api/Gemfile /obs/src/api/Gemfile
ADD src/api/Gemfile.lock /obs/src/api/Gemfile.lock
ADD Gemfile /obs/src/api/Gemfile
ADD Gemfile.lock /obs/src/api/Gemfile.lock
RUN chown -R frontend /obs/src/api

# Ensure there are ruby, gem and irb commands without ruby suffix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ RUN /root/bin/docker-bootstrap.sh memcached
RUN /root/bin/docker-bootstrap.sh backend
RUN /root/bin/docker-bootstrap.sh frontend

ADD src/api/Gemfile /obs/src/api/Gemfile
ADD src/api/Gemfile.lock /obs/src/api/Gemfile.lock
ADD contrib/start_old_tests /obs/contrib/start_old_tests
ADD Gemfile /obs/src/api/Gemfile
ADD Gemfile.lock /obs/src/api/Gemfile.lock
ADD docker-files/start_old_tests /obs/contrib/start_old_tests
RUN chown -R frontend:users /obs/

# Set up some convenience ruby binaries...
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/backend/t/*

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM openbuildservice/base
RUN /root/bin/docker-bootstrap.sh backend

# Add our sign configuration
ADD dist/obs-signd-conf.tar.bz2 /
ADD docker-files/obs-signd-conf.tar.bz2 /

# Run our command
WORKDIR /obs
Expand Down
File renamed without changes.

0 comments on commit 8576fe1

Please sign in to comment.