Import the tripleo-image-serve role

The tripleo-image-serve role from tripleo-common has been imported.
This role will now be tested with molecule running in containers
allowing us to validate the role functionality on both CENT7 and
F28.

Change-Id: I56a390f05193c7c004b7c1254575bddbb9d027fc
Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
Kevin Carter
2019-06-24 08:34:01 -05:00
committed by Kevin Carter (cloudnull)
parent 2135446a35
commit fb866f7319
15 changed files with 437 additions and 0 deletions
@@ -0,0 +1,23 @@
==========================
Role - tripleo-image-serve
==========================
This role provides for the following services:
* tripleo-image-serve
Default variables
~~~~~~~~~~~~~~~~~
.. literalinclude:: ../../../tripleo_ansible/roles/tripleo-image-serve/defaults/main.yml
:language: yaml
:start-after: under the License.
Example playbook
~~~~~~~~~~~~~~~~
.. literalinclude:: ../../../tripleo_ansible/roles/tripleo-image-serve/molecule/default/playbook.yml
:language: yaml
:start-after: under the License.
+6
View File
@@ -280,3 +280,9 @@ basepython = {[testenv:mol]basepython}
deps = {[testenv:mol]deps}
changedir = {toxinidir}/tripleo_ansible/roles/tripleo-container-rm
commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py --scenario=docker_rm
[testenv:mol-tripleo-image-serve]
basepython = {[testenv:mol]basepython}
deps = {[testenv:mol]deps}
changedir = {toxinidir}/tripleo_ansible/roles/tripleo-image-serve
commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py
@@ -0,0 +1,4 @@
tripleo-container-tag
=====================
An Ansible role to deploy an apache based container image serving service.
@@ -0,0 +1,32 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# All variables intended for modification should place placed in this file.
# NOTE(cloudnull): This role used to use a non-namespaced option, which has a high
# probability of creating conflicts with other roles in the greater
# ansible ecosystem. To ensure that we're able to retain existing
# variable functionality the "modules" option will supersede
# "tripleo_modules" if defined. This default should be removed
# just as soon as we're validate that the non-namespaced option
# is no longer in use.
# defaults file for apache-image-serve
tripleo_container_registry_host: "{{ container_registry_host | default('localhost') }}"
tripleo_container_registry_port: "{{ container_registry_port | default('8787') }}"
tripleo_image_data_dir: "{{ image_data_dir | default('/var/lib/image-serve') }}"
@@ -0,0 +1,30 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: restart httpd
command: /bin/true
notify:
- Image-Serve | reload systemd
- Image-Serve | reload httpd
listen: "restart httpd service"
- name: Image-Serve | reload httpd
systemd:
name: httpd
state: restarted
enabled: true
daemon_reload: true
@@ -0,0 +1,44 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
galaxy_info:
author: OpenStack
description: TripleO OpenStack Role -- tripleo-image-serve
company: Red Hat
license: Apache-2.0
min_ansible_version: 2.7
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: Fedora
versions:
- 28
- name: CentOS
versions:
- 7
galaxy_tags:
- tripleo
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies: []
@@ -0,0 +1,36 @@
# Molecule managed
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
{% for pkg in item.easy_install | default([]) %}
# install pip for centos where there is no python-pip rpm in default repos
RUN easy_install {{ pkg }}
{% endfor %}
CMD ["sh", "-c", "while true; do sleep 10000; done"]
@@ -0,0 +1,68 @@
---
driver:
name: docker
log: true
platforms:
- name: centos7
hostname: centos7
image: centos:7
dockerfile: Dockerfile
pkg_extras: python-setuptools
easy_install:
- pip
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
command: /sbin/init
tmpfs:
- /run
- /tmp
capabilities:
- ALL # CENT7 requires all due to the age of the software
volumes:
- /run/udev:/run/udev:ro
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: fedora28
hostname: fedora28
image: fedora:28
dockerfile: Dockerfile
pkg_extras: python*-setuptools
environment:
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
command: /sbin/init
privileged: true
tmpfs:
- /run
- /tmp
capabilities:
- SYS_ADMIN
volumes:
- /run/udev:/run/udev:ro
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
lint:
enabled: false
verifier:
name: testinfra
lint:
name: flake8
@@ -0,0 +1,21 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Converge
hosts: all
roles:
- role: "tripleo-image-serve"
@@ -0,0 +1,21 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Prepare
hosts: all
roles:
- role: test_deps
@@ -0,0 +1,43 @@
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_package_installed(host):
assert host.package("httpd").is_installed
def test_image_serve_conf_exists(host):
assert host.file("/etc/httpd/conf.d/image-serve.conf").exists
def test_image_serve_dir_exists(host):
assert host.file("/var/lib/image-serve").exists
def test_httpd_running(host):
assert host.service("httpd").is_running
def test_httpd_enabled(host):
assert host.service("httpd").is_enabled
@@ -0,0 +1,15 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
@@ -0,0 +1,54 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: ensure apache is installed
package:
name: httpd
state: present
- name: create image data directory
file:
state: directory
path: "{{ tripleo_image_data_dir }}/v2"
mode: 0755
owner: root
group: root
setype: httpd_sys_content_t
- name: create /v2/ response file
copy:
content: "{}"
dest: "{{ tripleo_image_data_dir }}/v2/index.json"
mode: 0644
owner: root
group: root
setype: httpd_sys_content_t
- name: Add listen line
lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: '^\s*Listen(.*)$'
line: '# Listen \1'
- name: manage /etc/httpd/conf.d/image-serve.conf
template:
src: image-serve.conf.j2
dest: /etc/httpd/conf.d/image-serve.conf
notify: Image-Serve | reload httpd
- name: force systemd to reread configs
meta: flush_handlers
@@ -0,0 +1,31 @@
# {{ ansible_managed }}
Listen {{ tripleo_container_registry_port }}
<VirtualHost {{ tripleo_container_registry_host }}:{{ tripleo_container_registry_port }}>
DocumentRoot {{ tripleo_image_data_dir }}
ErrorLog "/var/log/httpd/image_serve_error.log"
ServerSignature Off
CustomLog "/var/log/httpd/image_serve_access.log" combined
SetEnvIf X-Forwarded-Proto https HTTPS=1
RedirectMatch ^/$ /v2
<Directory {{ tripleo_image_data_dir }}>
# This assumes a file exists containing {} at
# {{ tripleo_image_data_dir }}/index.json
DirectoryIndex index.json
Options FollowSymLinks MultiViews
AllowOverride FileInfo
Require all granted
Header set Docker-Distribution-Api-Version registry/2.0
</Directory>
<LocationMatch "^/v2/.*/.*/blobs/sha256:.*$">
SetEnvIf Request_URI "sha256:(.*)$" digest=sha256:$1
Header set Docker-Content-Digest "%{digest}e"
Header set ETag "%{digest}e"
Header set Cache-Control "max-age=31536000"
Header set Content-Type "application/octet-stream"
</LocationMatch>
</VirtualHost>
+9
View File
@@ -14,6 +14,7 @@
- tripleo-ansible-centos-7-molecule-tripleo-ssh-known-hosts
- tripleo-ansible-centos-7-molecule-tripleo-container-tag
- tripleo-ansible-centos-7-molecule-tripleo-container-rm
- tripleo-ansible-centos-7-molecule-tripleo-image-serve
gate:
jobs:
- tripleo-ansible-centos-7-molecule-aide
@@ -28,6 +29,7 @@
- tripleo-ansible-centos-7-molecule-tripleo-ssh-known-hosts
- tripleo-ansible-centos-7-molecule-tripleo-container-tag
- tripleo-ansible-centos-7-molecule-tripleo-container-rm
- tripleo-ansible-centos-7-molecule-tripleo-image-serve
name: tripleo-ansible-molecule-jobs
- job:
files:
@@ -117,3 +119,10 @@
parent: tripleo-ansible-centos-sudo
vars:
tox_envlist: mol-tripleo-container-rm
- job:
files:
- ^tripleo_ansible/roles/tripleo-image-serve/.*
name: tripleo-ansible-centos-7-molecule-tripleo-image-serve
parent: tripleo-ansible-centos
vars:
tox_envlist: mol-tripleo-image-serve