diff --git a/playbooks/tripleo-buildcontainers/post.yaml b/playbooks/tripleo-buildcontainers/post.yaml new file mode 100644 index 000000000..62979ec65 --- /dev/null +++ b/playbooks/tripleo-buildcontainers/post.yaml @@ -0,0 +1,49 @@ +- hosts: primary + tasks: + - name: Include common vars + include_vars: + file: "common.yaml" + + - name: Grab job artifacts + become: true + args: + chdir: "{{ workspace }}" + shell: | + set -x + mkdir -p {{ workspace }}/conf/ + mkdir -p {{ workspace }}/logs/system + mkdir -p {{ workspace }}/etc/docker + + mv *.conf {{ workspace }}/conf/ + mv *.log {{ workspace }}/logs/ + rsync -var --no-links /var/log/ {{ workspace }}/logs/system/ || true + rsync -var --no-links /etc/docker/ {{ workspace }}/etc/docker/ || true + gzip -r "{{ workspace }}/logs" "{{ workspace }}/conf" "{{ workspace }}/etc" + chmod -R a+r "{{ workspace }}" + chown -R {{ ansible_user }}: "{{ workspace }}" + + - name: Rename compressed text based files to end with txt.gz extension + become: true + shell: > + set -o pipefail && + find {{ workspace }}/logs {{ workspace }}/conf {{ workspace }}/etc -type f | + awk 'function rename(orig) + { new=orig; sub(/\.gz$/, ".txt.gz", new); system("mv " orig " " new) } + /\.(conf|ini|json|sh|log|yaml|yml|repo|cfg|j2|py)\.gz$/ { rename($0) } + /(\/logs\/|\/etc\/)[^ \/\.]+\.gz$/ { rename($0) }'; + + - name: Copy files from {{ ansible_user_dir }}/workspace/ on node + #no_log: true + synchronize: + src: '{{ ansible_user_dir }}/workspace/' + dest: '{{ zuul.executor.log_root }}' + mode: pull + copy_links: true + verify_host: true + rsync_opts: + - --include=/etc/** + - --include=/conf/** + - --include=/logs/** + - --include=*/ + - --exclude=* + - --prune-empty-dirs diff --git a/playbooks/tripleo-buildcontainers/pre.yaml b/playbooks/tripleo-buildcontainers/pre.yaml new file mode 100644 index 000000000..7ac6ff2b4 --- /dev/null +++ b/playbooks/tripleo-buildcontainers/pre.yaml @@ -0,0 +1,66 @@ +- hosts: all + name: TripleO Setup Container Registry and repos mirror + roles: + - role: tripleo-repos + tripleo_repos_repository: "{{ ansible_user_dir }}/{{ zuul.projects['git.openstack.org/openstack/tripleo-repos'].src_dir }}" + tasks: + - name: Include common vars + include_vars: + file: "common.yaml" + + - name: Ensure legacy workspace directory + file: + path: '{{ workspace }}' + state: directory + + - name: Setup docker registry + block: + - name: Install ansible + become: true + package: + name: ansible + state: present + + - name: Create playbook structure + file: + path: '{{ workspace }}/container-registry' + src: '{{ openstack_git_root }}/ansible-role-container-registry' + state: link + + - name: Configure docker registry + template: + src: templates/docker-playbook.yaml.j2 + dest: '{{ workspace }}/docker-playbook.yaml' + mode: 0644 + force: yes + + - name: Run ansible playbook to configure docker + args: + chdir: '{{ workspace }}' + shell: | + ansible-playbook docker-playbook.yaml --extra-vars "container_registry_deployment_user={{ ansible_user }}" + + - name: Add docker masquerading rules + become: true + command: iptables -t nat -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE + + - name: Reset connection because of group changes for current user + meta: reset_connection + + - name: Setup repo web service + become: true + block: + - name: Install apache + package: + name: httpd + state: present + + - name: Start apache + service: + name: httpd + state: running + + - name: Fetch delorean repos + shell: | + set -ex + cp /etc/yum.repos.d/delorean* /var/www/html/ diff --git a/playbooks/tripleo-buildcontainers/run.yaml b/playbooks/tripleo-buildcontainers/run.yaml new file mode 100644 index 000000000..d6843c466 --- /dev/null +++ b/playbooks/tripleo-buildcontainers/run.yaml @@ -0,0 +1,76 @@ +- hosts: all + name: TripleO container image building job + roles: + - role: bindep + bindep_dir: "{{ ansible_user_dir }}/{{ zuul.projects['git.openstack.org/openstack/python-tripleoclient'].src_dir }}" + tasks: + - name: Include common vars + include_vars: + file: "common.yaml" + + - name: Get branch + set_fact: + ci_branch: "{{ zuul.branch | default('master') | replace('stable/','') }}" + + - name: Swap is essential as we are not meeting memory requirements + include_role: + name: configure-swap + + - name: Set legacy log path + include_role: + name: set-zuul-log-path-fact + + - name: Ensure legacy workspace directory + file: + path: '{{ workspace }}' + state: directory + + - name: Ensure legacy logs directory + file: + path: '{{ workspace }}/logs' + state: directory + + - name: Install pip + become: true + package: + name: python-pip + state: present + + - name: Install virtualenv + become: true + package: + name: python-virtualenv + state: present + + - name: pip install required items + become: true + pip: + name: "{{ item }}" + state: present + virtualenv: "{{ workspace }}/venv" + with_items: + - "file://{{ openstack_git_root }}/kolla" + - "file://{{ openstack_git_root }}/tripleo-common" + - "file://{{ openstack_git_root }}/python-tripleoclient" + + # TODO(aschultz): make the kolla-build branch aware + - name: Generate kolla-build.conf + template: + src: templates/kolla-build.conf.j2 + dest: "{{ workspace }}/kolla-build.conf" + mode: 0644 + force: yes + + - name: Run image build + args: + chdir: '{{ workspace }}' + shell: | + set -x + source {{ workspace }}/venv/bin/activate + TRIPLEO_COMMON_PATH="{{ openstack_git_root }}/tripleo-common" + + openstack overcloud container image build \ + --config-file $TRIPLEO_COMMON_PATH/container-images/overcloud_containers.yaml \ + --kolla-config-file {{ workspace }}/kolla-build.conf > {{ workspace }}/build.log 2> {{ workspace }}/build-err.log + RESULT=$? + exit $RESULT diff --git a/playbooks/tripleo-buildcontainers/templates/docker-playbook.yaml.j2 b/playbooks/tripleo-buildcontainers/templates/docker-playbook.yaml.j2 new file mode 100644 index 000000000..c1806ae70 --- /dev/null +++ b/playbooks/tripleo-buildcontainers/templates/docker-playbook.yaml.j2 @@ -0,0 +1,4 @@ +- hosts: localhost + become: true + roles: + - container-registry diff --git a/playbooks/tripleo-buildcontainers/templates/kolla-build.conf.j2 b/playbooks/tripleo-buildcontainers/templates/kolla-build.conf.j2 new file mode 100644 index 000000000..06a52fc53 --- /dev/null +++ b/playbooks/tripleo-buildcontainers/templates/kolla-build.conf.j2 @@ -0,0 +1,9 @@ +[DEFAULT] +base=centos +type=binary +namespace='{{ ci_branch | replace("/", "") }}' +registry=127.0.0.1:8787 +tag=latest +template_override={{ openstack_git_root }}/tripleo-common/container-images/tripleo_kolla_template_overrides.j2 +rpm_setup=http://localhost/delorean.repo,http://localhost/delorean-deps.repo + diff --git a/playbooks/tripleo-buildcontainers/vars/common.yaml b/playbooks/tripleo-buildcontainers/vars/common.yaml new file mode 100644 index 000000000..6138324ab --- /dev/null +++ b/playbooks/tripleo-buildcontainers/vars/common.yaml @@ -0,0 +1,2 @@ +workspace: "{{ ansible_user_dir }}/workspace" +openstack_git_root: "{{ ansible_user_dir }}/src/git.openstack.org/openstack" diff --git a/zuul.d/build-containers.yaml b/zuul.d/build-containers.yaml new file mode 100644 index 000000000..d01440a3e --- /dev/null +++ b/zuul.d/build-containers.yaml @@ -0,0 +1,38 @@ +--- +# zuul.d/build-containers.yaml +# Zuul layout for TripleO Build Containers jobs. + +- project-template: + name: tripleo-build-containers-jobs + check: + jobs: + - tripleo-build-containers-centos-7 + +- job: + name: tripleo-build-containers-centos-7 + parent: tripleo-ci-base-singlenode + pre-run: + - playbooks/tripleo-buildcontainers/pre.yaml + run: playbooks/tripleo-buildcontainers/run.yaml + post-run: playbooks/tripleo-buildcontainers/post.yaml + timeout: 7200 + nodeset: single-centos-7-node + voting: false + required-projects: + - git.openstack.org/openstack/ansible-role-container-registry + - git.openstack.org/openstack/kolla + - git.openstack.org/openstack/python-tripleoclient + - git.openstack.org/openstack/requirements + - git.openstack.org/openstack/tripleo-common + - git.openstack.org/openstack/tripleo-repos + irrelevant-files: + - ^.*\.rst$ + - ^releasenotes/.*$ + files: + # tripleo-ci + - ^playbooks/tripleo-buildcontainers/.*$ + # tripleo-common + - ^container-images/.*$ + - ^tripleo_common/image/.*$ + # python-tripleoclient + - ^tripleoclient/v1/container.*$ diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml index 72d122c98..a4c07ecbd 100644 --- a/zuul.d/layout.yaml +++ b/zuul.d/layout.yaml @@ -11,6 +11,7 @@ - tripleo-multinode-experimental - tripleo-undercloud-jobs - tripleo-multinode-branchful + - tripleo-build-containers-jobs check: jobs: - openstack-tox-linters