Add custom code to base docker templates

Sometimes you need custom code in Docerfiles to solve for example
proxy problems or preconfigure base image in some specific way.
With this commit you can insert content of custom file to the beggining
of base Dockerfile to provide these changes

Partially-implements: bp rhel-based-image-support
Partially-implements: bp add-proxy-to-dockerfiles
Partially-implements: bp build-script
Change-Id: Idbfec764aad627f5c00dc09c4854d5fa1c5ac9cf
This commit is contained in:
Michal Jastrzebski (inc0) 2015-08-20 21:59:16 +02:00 committed by inc0
parent fd9d11aeb4
commit 598fe7bad1
2 changed files with 10 additions and 0 deletions

2
docker_templates/base/Dockerfile.j2 Normal file → Executable file
View File

@ -1,6 +1,8 @@
FROM {{ base_distro }}:{{ base_distro_tag }} FROM {{ base_distro }}:{{ base_distro_tag }}
MAINTAINER Kolla Project (https://launchpad.net/kolla) MAINTAINER Kolla Project (https://launchpad.net/kolla)
{{ include_header }}
{% if base_distro in ['fedora', 'centos', 'oraclelinux'] %} {% if base_distro in ['fedora', 'centos', 'oraclelinux'] %}
{% if install_type == 'binary' %} {% if install_type == 'binary' %}
{% if base_distro in ['centos', 'oraclelinux'] %} {% if base_distro in ['centos', 'oraclelinux'] %}

View File

@ -173,6 +173,10 @@ def argParser():
parser.add_argument('-d', '--debug', parser.add_argument('-d', '--debug',
help='Turn on debugging log level', help='Turn on debugging log level',
action='store_true') action='store_true')
parser.add_argument('-i', '--include-header',
help=('Path to custom file to be added at '
'beginning of base Dockerfile'),
type=str)
return vars(parser.parse_args()) return vars(parser.parse_args())
@ -191,6 +195,7 @@ class KollaWorker(object):
self.prefix = self.base + '-' + self.type_ + '-' self.prefix = self.base + '-' + self.type_ + '-'
self.config = ConfigParser.SafeConfigParser() self.config = ConfigParser.SafeConfigParser()
self.config.read(os.path.join(sys.path[0], '..', 'build.ini')) self.config.read(os.path.join(sys.path[0], '..', 'build.ini'))
self.include_header = args['include_header']
self.image_statuses_bad = {} self.image_statuses_bad = {}
self.image_statuses_good = {} self.image_statuses_good = {}
@ -225,6 +230,9 @@ class KollaWorker(object):
'install_type': self.type_, 'install_type': self.type_,
'namespace': self.namespace, 'namespace': self.namespace,
'tag': self.tag} 'tag': self.tag}
if self.include_header:
with open(self.include_header, 'r') as f:
values['include_header'] = f.read()
content = template.render(values) content = template.render(values)
with open(os.path.join(path, 'Dockerfile'), 'w') as f: with open(os.path.join(path, 'Dockerfile'), 'w') as f:
f.write(content) f.write(content)