Use a common python build/install role

In order to radically simplify how we prepare the service
venvs, we use a common role to do the wheel builds and the
venv preparation. This makes the process far simpler to
understand, because the role does its own building and
installing. It also reduces the code maintenance burden,
because instead of duplicating the build processes in the
repo_build role and the service role - we only have it all
done in a single place.

We also change the role venv tag var to use the integrated
build's common venv tag so that we can remove the role's
venv tag in group_vars in the integrated build. This reduces
memory consumption and also reduces the duplication.

This is by no means the final stop in the simplification
process, but it is a step forward. The will be work to follow
which:

1. Replaces 'developer mode' with an equivalent mechanism
   that uses the common role and is simpler to understand.
   We will also simplify the provisioning of pip install
   arguments when doing this.

This patch also cleans up the unnecessary tags and makes a
few changes to the role to tidy things up a bit.

Depends-On: https://review.openstack.org/598957
Change-Id: I61d005d4732bd1d6cf4125cbf1adfdb1479a4b1b
Implements: blueprint python-build-install-simplification
Signed-off-by: Jesse Pretorius <jesse.pretorius@rackspace.co.uk>
This commit is contained in:
Jesse Pretorius 2018-09-03 18:07:15 +01:00 committed by Jesse Pretorius (odyssey4me)
parent 63f9e0f1a9
commit 0fc824798e
10 changed files with 75 additions and 193 deletions

View File

@ -26,8 +26,19 @@ zaqar_service_setup_host: "{{ openstack_service_setup_host | default('localhost'
zaqar_package_state: "latest"
zaqar_pip_package_state: "latest"
# TODO(odyssey4me):
# This can be simplified once all the roles are using
# python_venv_build. We can then switch to using a
# set of constraints in pip.conf inside the venv,
# perhaps prepared by giving a giving a list of
# constraints to the role.
zaqar_pip_install_args: >-
{{ zaqar_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
{{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''), '') }}
{{ pip_install_options | default('') }}
# Name of the virtual env to deploy into
zaqar_venv_tag: untagged
zaqar_venv_tag: "{{ venv_tag | default('untagged') }}"
zaqar_bin: "/openstack/venvs/zaqar-{{ zaqar_venv_tag }}/bin"
# venv_download, even when true, will use the fallback method of building the

View File

@ -13,28 +13,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Restart zaqar api
service:
name: "{{ zaqar_api_program_name }}"
state: "restarted"
pattern: "{{ zaqar_api_program_name }}"
- name: Restart Apache
service:
name: "apache2"
state: "restarted"
pattern: "apache2"
register: apache_restart
until: apache_restart is success
retries: 5
delay: 2
when:
- zaqar_install_apache | bool
listen:
- "Restart zaqar services"
- "venv_changed"
- name: Restart Nginx
service:
name: "nginx"
state: "restarted"
pattern: "nginx"
register: nginx_restart
until: nginx_restart is success
retries: 5
delay: 2
when:
- zaqar_install_nginx | bool
listen:
- "Restart zaqar services"
- "venv_changed"

View File

@ -29,15 +29,9 @@
- include: zaqar_post_install.yml
- include: zaqar_service_setup.yml
when: inventory_hostname == groups['zaqar_all'][0]
run_once: yes
- include: zaqar_apache.yml
static: no
when: zaqar_install_apache | bool
- include: zaqar_nginx.yml
static: no
when: zaqar_install_nginx | bool
- include: "zaqar_{{ (zaqar_install_apache | bool) | ternary('apache', 'nginx') }}.yml"
- name: Flush handlers
meta: flush_handlers

View File

@ -22,8 +22,6 @@
mode: "0755"
notify:
- Restart Apache
tags:
- zaqar-httpd
- name: Add zaqar apache configuration files
template:
@ -36,8 +34,6 @@
- { src: "zaqar-httpd.conf.j2", dest: "/etc/apache2/sites-available/zaqar-httpd.conf" }
notify:
- Restart Apache
tags:
- zaqar-httpd
- name: Disable default apache site
file:
@ -45,8 +41,6 @@
state: "absent"
notify:
- Restart Apache
tags:
- zaqar-httpd
- name: Enabled zaqar vhost
file:
@ -55,8 +49,6 @@
state: "link"
notify:
- Restart Apache
tags:
- zaqar-httpd
- name: Ensure Apache ServerName
lineinfile:
@ -64,8 +56,6 @@
line: "ServerName {{ inventory_hostname }}"
notify:
- Restart Apache
tags:
- zaqar-httpd
- name: Ensure Apache ServerTokens
lineinfile:
@ -74,8 +64,6 @@
line: "ServerTokens Prod"
notify:
- Restart Apache
tags:
- zaqar-httpd
- name: Ensure Apache ServerSignature
lineinfile:
@ -84,5 +72,3 @@
line: "ServerSignature Off"
notify:
- Restart Apache
tags:
- zaqar-httpd

View File

@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- include: install-apt.yml
static: no
when: ansible_pkg_mgr == 'apt'
tags:
- install-apt
# TODO(odyssey4me):
# This can be simplified once all the roles are using
# python_venv_build. We can then switch to using a
# set of constraints in pip.conf inside the venv,
# perhaps prepared by giving a giving a list of
# constraints to the role.
- name: Create developer mode constraint file
copy:
dest: "/opt/developer-pip-constraints.txt"
@ -28,112 +28,24 @@
{% endfor %}
when:
- zaqar_developer_mode | bool
- not zaqar_local_mode | bool
tags:
- zaqar-install
- zaqar-pip-packages
- name: Retrieve checksum for venv download
uri:
url: "{{ zaqar_venv_download_url | replace('tgz', 'checksum') }}"
return_content: yes
register: zaqar_venv_checksum
when: zaqar_venv_download | bool
tags:
- zaqar-install
- zaqar-pip-packages
- name: Ensure remote wheel building is disabled in developer mode
set_fact:
venv_build_host: "{{ ansible_hostname }}"
when:
- zaqar_developer_mode | bool
- name: Attempt venv download
get_url:
url: "{{ zaqar_venv_download_url }}"
dest: "/var/cache/{{ zaqar_venv_download_url | basename }}"
checksum: "sha1:{{ zaqar_venv_checksum.content | trim }}"
register: zaqar_get_venv
when: zaqar_venv_download | bool
tags:
- zaqar-install
- zaqar-pip-packages
- name: Copy pre-build venv package
copy:
src: "{{ zaqar_venv_localpath }}"
dest: "/var/cache/"
register: zaqar_get_venv
when: zaqar_local_mode | bool
tags:
- zaqar-install
- zaqar-pip-packages
- name: Remove existing venv
file:
path: "{{ zaqar_bin | dirname }}"
state: absent
when: zaqar_get_venv is changed
tags:
- zaqar-install
- zaqar-pip-packages
- name: Create zaqar venv dir
file:
path: "{{ zaqar_bin | dirname }}"
state: directory
register: zaqar_venv_dir
when: zaqar_get_venv is changed
tags:
- zaqar-install
- zaqar-pip-packages
- name: Unarchive pre-built venv
unarchive:
src: "/var/cache/{{ zaqar_venv_download_url | basename }}"
dest: "{{ zaqar_bin | dirname }}"
copy: "no"
when: zaqar_get_venv is changed
# notify:
# - Restart zaqar api
tags:
- zaqar-install
- zaqar-pip-packages
- name: Install pip packages (venv)
pip:
name: "{{ zaqar_pip_packages }}"
state: "{{ zaqar_pip_package_state }}"
virtualenv: "{{ zaqar_bin | dirname }}"
virtualenv_site_packages: "no"
extra_args: >-
{{ zaqar_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
{{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
{{ pip_install_options | default('') }}
register: install_packages
until: install_packages is success
retries: 5
delay: 2
when: zaqar_get_venv | failed or zaqar_get_venv | skipped
# notify:
# - Restart zaqar api
tags:
- zaqar-install
- zaqar-pip-packages
# NOTE(odyssey4me):
# We reinitialize the venv to ensure that the right
# version of python is in the venv, but we do not
# want virtualenv to also replace pip, setuptools
# and wheel so we tell it not to.
# We do not use --always-copy for CentOS/SuSE due
# to https://github.com/pypa/virtualenv/issues/565
- name: Update virtualenv path
shell: |
find {{ zaqar_bin }} -name \*.pyc -delete
sed -si '1s/^.*python.*$/#!{{ zaqar_bin | replace ('/','\/') }}\/python/' {{ zaqar_bin }}/*
virtualenv {{ zaqar_bin | dirname }} \
{{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} \
--no-pip \
--no-setuptools \
--no-wheel
when: zaqar_get_venv is changed
tags:
- skip_ansible_lint
- zaqar-install
- zaqar-pip-packages
- name: Install the python venv
include_role:
name: "python_venv_build"
private: yes
vars:
venv_build_distro_package_list: "{{ zaqar_devel_distro_packages }}"
venv_install_destination_path: "{{ zaqar_bin | dirname }}"
venv_install_distro_package_list: "{{ zaqar_package_list }}"
venv_pip_install_args: "{{ zaqar_pip_install_args }}"
venv_pip_packages: "{{ zaqar_pip_packages }}"
venv_facts_when_changed:
- section: "zaqar"
option: "venv_tag"
value: "{{ zaqar_venv_tag }}"

View File

@ -22,8 +22,6 @@
mode: "0755"
notify:
- Restart Nginx
tags:
- zaqar-nginx
# Actually, we should also add an upstart script to automatically start uWSGI
# at boot time. Here is just for testing purpose.
@ -38,9 +36,6 @@
--vacuum
notify:
- Restart Nginx
tags:
- zaqar-nginx
- skip_ansible_lint
- name: Add zaqar nginx configuration file
template:
@ -50,8 +45,6 @@
group: "root"
notify:
- Restart Nginx
tags:
- zaqar-nginx
- name: Enabled zaqar vhost
file:
@ -60,5 +53,3 @@
state: "link"
notify:
- Restart Nginx
tags:
- zaqar-nginx

View File

@ -22,17 +22,13 @@
mode: "0644"
config_overrides: "{{ zaqar_zaqar_conf_overrides }}"
config_type: "ini"
# notify: Restart zaqar api
tags:
- zaqar-config
- zaqar-post-install
notify:
- Restart zaqar services
- name: Copy zaqar logging config
copy:
src: "logging.conf"
dest: "/etc/zaqar/logging.conf"
# notify: Restart zaqar api
tags:
- zaqar-config
- zaqar-post-install
notify:
- Restart zaqar services

View File

@ -18,8 +18,6 @@
name: "{{ zaqar_system_group_name }}"
state: "present"
system: "yes"
tags:
- zaqar-group
- name: Create the zaqar system user
user:
@ -30,8 +28,6 @@
system: "yes"
createhome: "yes"
home: "{{ zaqar_system_user_home }}"
tags:
- zaqar-user
- name: Create zaqar dir
file:
@ -48,8 +44,6 @@
- { path: "/var/www/cgi-bin", owner: root, group: root }
- { path: "/var/www/cgi-bin/zaqar" }
- { path: "/var/cache/zaqar", mode: "0700" }
tags:
- zaqar-dirs
- name: Test for log directory or link
shell: |
@ -62,9 +56,6 @@
register: log_dir
failed_when: false
changed_when: log_dir.rc != 0
tags:
- zaqar-dirs
- zaqar-logs
- name: Create zaqar log dir
file:
@ -74,6 +65,3 @@
group: "{{ zaqar_system_group_name }}"
mode: "0755"
when: log_dir.rc != 0
tags:
- zaqar-dirs
- zaqar-logs

View File

@ -16,8 +16,10 @@
## APT Cache options
cache_timeout: 600
zaqar_devel_distro_packages:
- git
zaqar_distro_packages:
- "{% if zaqar_developer_mode %}git{% endif %}"
- gcc
- libxml2-dev
- libxslt1-dev
@ -25,7 +27,10 @@ zaqar_distro_packages:
- python2.7-dev
- python-dev
- zlib1g-dev
- "{% if zaqar_install_apache %}apache2{% endif %}"
- "{% if zaqar_install_apache %}libapache2-mod-wsgi{% endif %}"
- "{% if zaqar_install_nginx %}nginx{% endif %}"
zaqar_apache_distro_packages:
- apache2
- libapache2-mod-wsgi
zaqar_nginx_distro_packages:
- nginx

View File

@ -1,5 +1,5 @@
---
# Copyright 2016, Rackspace US, Inc.
# Copyright 2018, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -13,19 +13,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Install zaqar apt packages
apt:
pkg: "{{ item }}"
state: "{{ zaqar_package_state }}"
update_cache: yes
cache_valid_time: "{{ cache_timeout }}"
register: install_apt_packages
until: install_apt_packages is success
retries: 5
delay: 2
with_items: "{{ zaqar_distro_packages }}"
when:
- item != ''
tags:
- zaqar-apt-packages
#
# Compile a list of the distro packages to install based on
# the options enabled.
#
zaqar_package_list: |-
{% set packages = zaqar_distro_packages %}
{% if zaqar_install_apache | bool %}
{% set _ = packages.extend(zaqar_apache_distro_packages) %}
{% elif zaqar_install_nginx | bool %}
{% set _ = packages.extend(zaqar_nginx_distro_packages) %}
{% endif %}
{{ packages }}