Merge pull request #81 from markgoddard/container-image-builders

Improve container image build workflow
This commit is contained in:
Mark Goddard
2017-11-24 15:37:43 +00:00
committed by GitHub
14 changed files with 203 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
--- ---
- name: Ensure Kolla container images are built - name: Ensure Kolla container images are built
hosts: seed:controllers hosts: container-image-builders
vars: vars:
# Set this to True to push images to the registry when built. # Set this to True to push images to the registry when built.
push_images: False push_images: False
@@ -38,7 +38,9 @@
username: "{{ kolla_docker_registry_username }}" username: "{{ kolla_docker_registry_username }}"
password: "{{ kolla_docker_registry_password }}" password: "{{ kolla_docker_registry_password }}"
reauthorize: yes reauthorize: yes
when: kolla_docker_registry_username is not none and kolla_docker_registry_password is not none when:
- kolla_docker_registry_username is not none
- kolla_docker_registry_password is not none
- name: Ensure Kolla container images are built - name: Ensure Kolla container images are built
shell: > shell: >
@@ -47,7 +49,7 @@
kolla-build \ kolla-build \
--config-dir {{ kolla_build_config_path }} \ --config-dir {{ kolla_build_config_path }} \
{% if item.type is defined %}--type {{ item.type }}{% endif %} \ {% if item.type is defined %}--type {{ item.type }}{% endif %} \
{% if kolla_docker_registry != "" and kolla_docker_registry != None %}--registry {{ kolla_docker_registry }}{% endif %} \ {% if kolla_docker_registry is not none %}--registry {{ kolla_docker_registry }}{% endif %} \
{% if push_images | bool %}--push{% endif %} \ {% if push_images | bool %}--push{% endif %} \
{{ item.regexes }} 2>&1 | tee --append {{ kolla_build_log_path }} {{ item.regexes }} 2>&1 | tee --append {{ kolla_build_log_path }}
with_items: "{{ container_image_sets }}" with_items: "{{ container_image_sets }}"

View File

@@ -0,0 +1,12 @@
---
- name: Ensure the container-image-builders group exists
hosts: localhost
gather_facts: False
tasks:
- name: Ensure the container-image-builders group exists
fail:
msg: >
Container images are now built by hosts in the
container-image-builders group. Ensure that this group is present in
your inventory.
when: groups.get('container-image-builders', []) | length == 0

View File

@@ -104,8 +104,8 @@ seed_container_image_sets:
regexes: "{{ seed_container_image_regexes | join(' ') }}" regexes: "{{ seed_container_image_regexes | join(' ') }}"
# List of regular expressions matching names of container images to build for # List of regular expressions matching names of container images to build for
# controllers. # overcloud hosts.
controller_container_image_regex_map: overcloud_container_image_regex_map:
- regex: aodh - regex: aodh
enabled: "{{ kolla_enable_aodh | bool }}" enabled: "{{ kolla_enable_aodh | bool }}"
- regex: barbican - regex: barbican
@@ -113,33 +113,35 @@ controller_container_image_regex_map:
- regex: ceilometer - regex: ceilometer
enabled: "{{ kolla_enable_ceilometer | bool }}" enabled: "{{ kolla_enable_ceilometer | bool }}"
- regex: cinder - regex: cinder
enabled: True enabled: "{{ kolla_enable_cinder | bool }}"
- regex: cron - regex: cron
enabled: True enabled: True
- regex: designate - regex: designate
enabled: "{{ kolla_enable_designate | bool }}" enabled: "{{ kolla_enable_designate | bool }}"
- regex: dnsmasq - regex: dnsmasq
enabled: True enabled: "{{ kolla_enable_ironic | bool }}"
- regex: elasticsearch - regex: elasticsearch
enabled: "{{ kolla_enable_elasticsearch | bool }}" enabled: "{{ kolla_enable_elasticsearch | bool }}"
- regex: etcd
enabled: "{{ kolla_enable_etcd | bool }}"
- regex: fluentd - regex: fluentd
enabled: True enabled: True
- regex: glance - regex: glance
enabled: "{{ kolla_enable_glance | bool }}" enabled: "{{ kolla_enable_glance | bool }}"
- regex: gnocchi - regex: gnocchi
enabled: "{{ kolla_enable_gnocchi | bool }}" enabled: "{{ kolla_enable_gnocchi | bool }}"
- regex: haproxy - regex: ^haproxy$
enabled: True enabled: "{{ kolla_enable_haproxy | bool }}"
- regex: heat - regex: heat
enabled: True enabled: "{{ kolla_enable_heat | bool }}"
- regex: horizon - regex: horizon
enabled: True enabled: "{{ kolla_enable_horizon | bool }}"
- regex: ironic - regex: ironic
enabled: "{{ kolla_enable_ironic | bool }}" enabled: "{{ kolla_enable_ironic | bool }}"
- regex: iscsid - regex: iscsid
enabled: True enabled: "{{ kolla_enable_cinder | bool or kolla_enable_ironic | bool }}"
- regex: keepalived - regex: keepalived
enabled: True enabled: "{{ kolla_enable_haproxy | bool }}"
- regex: keystone - regex: keystone
enabled: True enabled: True
- regex: kibana - regex: kibana
@@ -157,14 +159,14 @@ controller_container_image_regex_map:
- regex: memcached - regex: memcached
enabled: True enabled: True
- regex: neutron-server - regex: neutron-server
enabled: True enabled: "{{ kolla_enable_neutron | bool }}"
# Neutron SFC agent not currently supported on CentOS binary builds. # Neutron SFC agent not currently supported on CentOS binary builds.
- regex: "neutron-\\(dhcp\\|l3\\|metadata\\|openvswitch\\)-agent" - regex: "neutron-\\(dhcp\\|l3\\|metadata\\|openvswitch\\)-agent"
enabled: True enabled: "{{ kolla_enable_neutron | bool }}"
- regex: nova - regex: nova
enabled: True enabled: "{{ kolla_enable_nova | bool }}"
- regex: openvswitch - regex: openvswitch
enabled: True enabled: "{{ kolla_enable_neutron | bool }}"
- regex: rabbitmq - regex: rabbitmq
enabled: True enabled: True
- regex: sahara - regex: sahara
@@ -174,16 +176,16 @@ controller_container_image_regex_map:
- regex: swift - regex: swift
enabled: "{{ kolla_enable_swift | bool }}" enabled: "{{ kolla_enable_swift | bool }}"
- regex: tgtd - regex: tgtd
enabled: True enabled: "{{ kolla_enable_cinder | bool or kolla_enable_ironic | bool }}"
# List of regular expressions matching names of container images to build for # List of regular expressions matching names of container images to build for
# controllers. # overcloud hosts.
controller_container_image_regexes: "{{ controller_container_image_regex_map | selectattr('enabled') | map(attribute='regex') | list }}" overcloud_container_image_regexes: "{{ overcloud_container_image_regex_map | selectattr('enabled') | map(attribute='regex') | list }}"
# List of container image sets for controllers. This is used when building # List of container image sets for overcloud hosts. This is used when building
# container images to determine which images to build. # container images to determine which images to build.
controller_container_image_sets: overcloud_container_image_sets:
- regexes: "{{ controller_container_image_regexes | join(' ') }}" - regexes: "{{ overcloud_container_image_regexes | join(' ') }}"
# Dict mapping Jinja2 block names in kolla's Docker images to their contents. # Dict mapping Jinja2 block names in kolla's Docker images to their contents.
kolla_build_blocks: {} kolla_build_blocks: {}
@@ -266,8 +268,10 @@ kolla_enable_barbican: "no"
kolla_enable_central_logging: "no" kolla_enable_central_logging: "no"
kolla_enable_ceph: "no" kolla_enable_ceph: "no"
kolla_enable_ceilometer: "no" kolla_enable_ceilometer: "no"
kolla_enable_cinder: "no"
kolla_enable_designate: "no" kolla_enable_designate: "no"
kolla_enable_elasticsearch: "{{ 'yes' if kolla_enable_central_logging | bool or kolla_enable_freezer | bool or kolla_enable_osprofiler | bool or kolla_enable_skydive | bool else 'no' }}" kolla_enable_elasticsearch: "{{ 'yes' if kolla_enable_central_logging | bool or kolla_enable_freezer | bool or kolla_enable_osprofiler | bool or kolla_enable_skydive | bool else 'no' }}"
kolla_enable_etcd: "no"
kolla_enable_freezer: "no" kolla_enable_freezer: "no"
kolla_enable_glance: "yes" kolla_enable_glance: "yes"
kolla_enable_gnocchi: "no" kolla_enable_gnocchi: "no"

View File

@@ -1,3 +0,0 @@
---
# List of Kolla container image sets for controllers.
container_image_sets: "{{ controller_container_image_sets }}"

View File

@@ -1,3 +0,0 @@
---
# List of Kolla container image sets for the seed.
container_image_sets: "{{ seed_container_image_sets }}"

View File

@@ -1,6 +1,7 @@
--- ---
- name: Ensure Kolla is installed and configured - name: Ensure Kolla is installed and configured
hosts: seed:controllers hosts: container-image-builders
roles: roles:
- role: kolla - role: kolla
- role: kolla-build - role: kolla-build
kolla_build_extra_config_path: "{{ kayobe_config_path }}/kolla/kolla-build.conf"

View File

@@ -1,6 +0,0 @@
---
- name: Ensure Kolla is configured
hosts: config-mgmt
roles:
- role: kolla
- role: kolla-build

View File

@@ -2,6 +2,9 @@
# Directory where Kolla config files will be installed. # Directory where Kolla config files will be installed.
kolla_build_config_path: kolla_build_config_path:
# Path to extra kolla configuration files.
kolla_build_extra_config_path:
# Valid options are [ centos, fedora, oraclelinux, ubuntu ] # Valid options are [ centos, fedora, oraclelinux, ubuntu ]
kolla_base_distro: kolla_base_distro:
@@ -34,3 +37,6 @@ kolla_build_blocks: {}
# most commonly packages. The operation should be one of override, append or # most commonly packages. The operation should be one of override, append or
# remove. The value should be a list. # remove. The value should be a list.
kolla_build_customizations: {} kolla_build_customizations: {}
# Free-form extra configuration for kolla-build.
kolla_extra_build: {}

View File

@@ -1,4 +1,18 @@
--- ---
- name: Check whether a Kolla build extra configuration file exists
local_action:
module: stat
path: "{{ kolla_build_extra_config_path }}"
get_checksum: False
get_md5: False
mime: False
register: stat_result
- name: Set a fact containing extra configuration
set_fact:
kolla_build_extra_config: "{{ lookup('template', kolla_build_extra_config_path) }}"
when: stat_result.stat.exists
- name: Ensure the Kolla build configuration files exist - name: Ensure the Kolla build configuration files exist
template: template:
src: "{{ item.src }}" src: "{{ item.src }}"

View File

@@ -33,3 +33,11 @@ reference = {{ source_def.reference }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if kolla_build_extra_config is defined %}
#######################
# Extra configuration
#######################
{{ kolla_build_extra_config }}
{% endif %}

View File

@@ -1,9 +1,22 @@
# Kayobe groups inventory file. This file should generally not be modified. # Kayobe groups inventory file. This file should generally not be modified.
# If declares the top-level groups and sub-groups. # If declares the top-level groups and sub-groups.
###############################################################################
# Seed groups.
[seed] [seed]
# Empty group to provide declaration of seed group. # Empty group to provide declaration of seed group.
[seed-hypervisor]
# Empty group to provide declaration of seed-hypervisor group.
[container-image-builders:children]
# Build container images on the seed by default.
seed
###############################################################################
# Overcloud groups.
[controllers] [controllers]
# Empty group to provide declaration of controllers group. # Empty group to provide declaration of controllers group.
@@ -24,6 +37,9 @@ network
monitoring monitoring
compute compute
###############################################################################
# Docker groups.
[docker:children] [docker:children]
# Hosts in this group will have Docker installed. # Hosts in this group will have Docker installed.
seed seed

View File

@@ -26,6 +26,12 @@
# Base image for the seed VM root volume. # Base image for the seed VM root volume.
#seed_vm_root_image: #seed_vm_root_image:
# Capacity of the seed VM data volume.
#seed_vm_data_capacity:
# Format of the seed VM data volume.
#seed_vm_data_format:
############################################################################### ###############################################################################
# Dummy variable to allow Ansible to accept this file. # Dummy variable to allow Ansible to accept this file.
workaround_ansible_issue_8743: yes workaround_ansible_issue_8743: yes

View File

@@ -414,12 +414,16 @@ class SeedContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.app.LOG.debug("Building seed container images") self.app.LOG.debug("Building seed container images")
playbooks = _build_playbook_list( playbooks = _build_playbook_list(
"kolla-build", "container-image-build") "container-image-builders-check", "kolla-build",
"container-image-build")
extra_vars = {"push_images": parsed_args.push} extra_vars = {"push_images": parsed_args.push}
if parsed_args.regex: if parsed_args.regex:
regexes = "'%s'" % " ".join(parsed_args.regex) regexes = "'%s'" % " ".join(parsed_args.regex)
extra_vars["container_image_regexes"] = regexes extra_vars["container_image_regexes"] = regexes
self.run_kayobe_playbooks(parsed_args, playbooks, limit="seed", else:
extra_vars["container_image_sets"] = (
"{{ seed_container_image_sets }}")
self.run_kayobe_playbooks(parsed_args, playbooks,
extra_vars=extra_vars) extra_vars=extra_vars)
@@ -940,12 +944,16 @@ class OvercloudContainerImageBuild(KayobeAnsibleMixin, VaultMixin, Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
self.app.LOG.debug("Building overcloud container images") self.app.LOG.debug("Building overcloud container images")
playbooks = _build_playbook_list( playbooks = _build_playbook_list(
"kolla-build", "container-image-build") "container-image-builders-check", "kolla-build",
"container-image-build")
extra_vars = {"push_images": parsed_args.push} extra_vars = {"push_images": parsed_args.push}
if parsed_args.regex: if parsed_args.regex:
regexes = "'%s'" % " ".join(parsed_args.regex) regexes = "'%s'" % " ".join(parsed_args.regex)
extra_vars["container_image_regexes"] = regexes extra_vars["container_image_regexes"] = regexes
self.run_kayobe_playbooks(parsed_args, playbooks, limit="controllers", else:
extra_vars["container_image_sets"] = (
"{{ overcloud_container_image_sets }}")
self.run_kayobe_playbooks(parsed_args, playbooks,
extra_vars=extra_vars) extra_vars=extra_vars)

View File

@@ -81,3 +81,101 @@ class TestCase(unittest.TestCase):
mock.call(mock.ANY, ["ansible/network-connectivity.yml"]), mock.call(mock.ANY, ["ansible/network-connectivity.yml"]),
] ]
self.assertEqual(expected_calls, mock_run.call_args_list) self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_seed_container_image_build(self, mock_run):
command = commands.SeedContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args([])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_sets": (
"{{ seed_container_image_sets }}"),
"push_images": False,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_seed_container_image_build_with_regex(self, mock_run):
command = commands.SeedContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--push", "^regex1$", "^regex2$"])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_regexes": "'^regex1$ ^regex2$'",
"push_images": True,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_overcloud_container_image_build(self, mock_run):
command = commands.OvercloudContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args([])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_sets": (
"{{ overcloud_container_image_sets }}"),
"push_images": False,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)
@mock.patch.object(commands.KayobeAnsibleMixin,
"run_kayobe_playbooks")
def test_overcloud_container_image_build_with_regex(self, mock_run):
command = commands.OvercloudContainerImageBuild(TestApp(), [])
parser = command.get_parser("test")
parsed_args = parser.parse_args(["--push", "^regex1$", "^regex2$"])
result = command.run(parsed_args)
self.assertEqual(0, result)
expected_calls = [
mock.call(
mock.ANY,
[
"ansible/container-image-builders-check.yml",
"ansible/kolla-build.yml",
"ansible/container-image-build.yml"
],
extra_vars={
"container_image_regexes": "'^regex1$ ^regex2$'",
"push_images": True,
}
),
]
self.assertEqual(expected_calls, mock_run.call_args_list)