Skip to content

Commit a8e8cf9

Browse files
committed
tests: Rebuild Docker containers
A few changes are bundled in this - Ansible 2.10.x and Mitogen 0.3.x are used to build nearly all images (Ansile 2.3.x is retained for CentOS 5, because it uses Python 2.4). - Tox is used to install/run Ansible, replacing build_docker_images.py - A static inventory, identifying containers by name rather than ID. - debian-test image is renamed to debian9-test - debian9-test image is now based on debian:9 - centos6-test image is now based on moreati/centos6-vault following the same scheme as centos5-test. - Images are now uploaded to Amazon Elastic Container Registry (ECR). See #809. - Debian recommended packages aren't installed (e.g. build-essential) - Python 2.x and Python 3.x are installed wherever available. - Python Virtualenv is installed wherever available.
1 parent 60fbea4 commit a8e8cf9

File tree

18 files changed

+177
-147
lines changed

18 files changed

+177
-147
lines changed

.ci/azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
Mito27Debian_27:
4646
python.version: '2.7'
4747
MODE: mitogen
48-
DISTRO: debian
48+
DISTRO: debian9
4949

5050
#MitoPy27CentOS6_26:
5151
#python.version: '2.7'
@@ -60,12 +60,12 @@ jobs:
6060
Mito37Debian_27:
6161
python.version: '3.7'
6262
MODE: mitogen
63-
DISTRO: debian
63+
DISTRO: debian9
6464

6565
Mito39Debian_27:
6666
python.version: '3.9'
6767
MODE: mitogen
68-
DISTRO: debian
68+
DISTRO: debian9
6969
VER: 2.10.0
7070

7171
#Py26CentOS7:

tests/ansible/integration/become/sudo_nonexistent.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
- name: Verify raw module output.
1414
assert:
15-
that: |
16-
out.failed and (
17-
('sudo: unknown user: slartibartfast' in out.msg) or
18-
('sudo: unknown user: slartibartfast' in out.module_stderr)
19-
)
15+
that:
16+
- out.failed
17+
# sudo-1.8.6p3-29.el6_10.3 on RHEL & CentOS 6.10 (final release)
18+
# removed user/group error messages, as defence against CVE-2019-14287.
19+
- >-
20+
('sudo: unknown user: slartibartfast' in out.module_stderr | default(out.msg))
21+
or (ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_version == '6.10')

tests/image_prep/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ See ../README.md for a (mostly) description of the accounts created.
1414

1515
## Building the containers
1616

17-
``./build_docker_images.sh``
18-
19-
Requires Ansible 2.3.x.x in order to target CentOS 5
17+
No single version of Ansible supports every Linux distribution that we target.
18+
To workaround this [Tox](https://tox.readthedocs.io) is used, to install and
19+
run multiple versions of Ansible, in Python virtualenvs.
2020

21+
``tox``
2122

2223
## Preparing an OS X box
2324

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- name: Start containers
2+
hosts: all
3+
strategy: mitogen_free
4+
gather_facts: false
5+
tasks:
6+
- name: Fetch container images
7+
docker_image:
8+
name: "{{ docker_base }}"
9+
delegate_to: localhost
10+
11+
- name: Start containers
12+
docker_container:
13+
name: "{{ inventory_hostname }}"
14+
image: "{{ docker_base }}"
15+
command: /bin/bash
16+
hostname: "mitogen-{{ inventory_hostname }}"
17+
detach: true
18+
interactive: true
19+
tty: true
20+
delegate_to: localhost
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- name: Prepare images
2+
hosts: all
3+
strategy: mitogen_free
4+
gather_facts: true
5+
tasks:
6+
- name: Commit containers
7+
command: >
8+
docker commit
9+
--change 'EXPOSE 22'
10+
--change 'CMD ["/usr/sbin/sshd", "-D"]'
11+
{{ inventory_hostname }}
12+
public.ecr.aws/n5z0e8q9/{{ inventory_hostname }}-test
13+
delegate_to: localhost
14+
15+
- name: Stop containers
16+
command: >
17+
docker rm -f {{ inventory_hostname }}
18+
delegate_to: localhost

tests/image_prep/_container_setup.yml

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,75 @@
11

22
- hosts: all
3-
vars_files:
4-
- shared_vars.yml
53
strategy: linear
64
gather_facts: false
75
tasks:
8-
- raw: >
9-
if ! python -c ''; then
10-
if type -p yum; then
11-
yum -y install python;
12-
else
13-
apt-get -y update && apt-get -y install python;
14-
fi;
6+
- name: Install bootstrap packages
7+
raw: |
8+
set -o errexit
9+
set -o nounset
10+
if type -p yum; then
11+
yum -y install {{ bootstrap_packages | join(' ') }}
12+
else
13+
apt-get -y update
14+
apt-get -y --no-install-recommends install {{ bootstrap_packages | join(' ') }}
1515
fi
16+
when: bootstrap_packages | length
1617

1718
- hosts: all
18-
vars_files:
19-
- shared_vars.yml
2019
strategy: mitogen_free
20+
# Resource limitation, my laptop freezes doing every container concurrently
21+
serial: 4
2122
# Can't gather facts before here.
2223
gather_facts: true
2324
vars:
2425
distro: "{{ansible_distribution}}"
25-
ver: "{{ansible_distribution_major_version}}"
26-
27-
packages:
28-
common:
29-
- openssh-server
30-
- rsync
31-
- strace
32-
- sudo
33-
Debian:
34-
"9":
35-
- libjson-perl
36-
- python-virtualenv
37-
- locales
38-
CentOS:
39-
"5":
40-
- perl
41-
- sudo
42-
#- perl-JSON -- skipped on CentOS 5, packages are a pain.
43-
"6":
44-
- perl-JSON
45-
"7":
46-
- perl-JSON
47-
- python-virtualenv
48-
4926
tasks:
5027
- when: ansible_virtualization_type != "docker"
5128
meta: end_play
5229

53-
- name: Ensure requisite Debian packages are installed
30+
- name: Ensure requisite apt packages are installed
5431
apt:
55-
name: "{{packages.common + packages[distro][ver]}}"
56-
state: installed
32+
name: "{{ common_packages + packages }}"
33+
state: present
34+
install_recommends: false
5735
update_cache: true
58-
when: distro == "Debian"
36+
when: ansible_pkg_mgr == 'apt'
5937

60-
- name: Ensure requisite Red Hat packaed are installed
38+
- name: Ensure requisite yum packages are installed
6139
yum:
62-
name: "{{packages.common + packages[distro][ver]}}"
63-
state: installed
40+
name: "{{ common_packages + packages }}"
41+
state: present
6442
update_cache: true
65-
when: distro == "CentOS"
66-
67-
- name: Clean up apt cache
68-
command: apt-get clean
69-
when: distro == "Debian"
43+
when: ansible_pkg_mgr == 'yum'
44+
45+
- name: Clean up package cache
46+
vars:
47+
clean_command:
48+
apt: apt-get clean
49+
yum: yum clean all
50+
command: "{{ clean_command[ansible_pkg_mgr] }}"
51+
args:
52+
warn: false
7053

7154
- name: Clean up apt package lists
7255
shell: rm -rf {{item}}/*
7356
with_items:
7457
- /var/cache/apt
7558
- /var/lib/apt/lists
76-
when: distro == "Debian"
59+
when: ansible_pkg_mgr == 'apt'
7760

78-
- name: Clean up yum cache
79-
command: yum clean all
80-
when: distro == "CentOS"
8161

8262
- name: Enable UTF-8 locale on Debian
8363
copy:
8464
dest: /etc/locale.gen
8565
content: |
8666
en_US.UTF-8 UTF-8
8767
fr_FR.UTF-8 UTF-8
88-
when: distro == "Debian"
68+
when: ansible_pkg_mgr == 'apt'
8969

9070
- name: Generate UTF-8 locale on Debian
9171
shell: locale-gen
92-
when: distro == "Debian"
72+
when: ansible_pkg_mgr == 'apt'
9373

9474
- name: Write Unicode into /etc/environment
9575
copy:
@@ -115,16 +95,6 @@
11595
permit :mitogen__group
11696
permit :root
11797
118-
- name: Vanilla Ansible needs simplejson on CentOS 5.
119-
shell: mkdir -p /usr/lib/python2.4/site-packages/simplejson/
120-
when: distro == "CentOS" and ver == "5"
121-
122-
- name: Vanilla Ansible needs simplejson on CentOS 5.
123-
synchronize:
124-
dest: /usr/lib/python2.4/site-packages/simplejson/
125-
src: ../../ansible_mitogen/compat/simplejson/
126-
when: distro == "CentOS" and ver == "5"
127-
12898
- name: Set root user password and shell
12999
user:
130100
name: root
@@ -182,8 +152,9 @@
182152
- name: Install CentOS wheel sudo rule
183153
lineinfile:
184154
path: /etc/sudoers
185-
line: "%wheel ALL=(ALL) ALL"
186-
when: distro == "CentOS"
155+
regexp: '#* *%wheel +ALL=(ALL) +ALL'
156+
line: "%wheel ALL=(ALL) ALL"
157+
when: ansible_os_family == 'RedHat'
187158

188159
- name: Enable SSH banner
189160
lineinfile:

tests/image_prep/_user_accounts.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
#
66

77
- hosts: all
8-
vars_files:
9-
- shared_vars.yml
108
gather_facts: true
119
strategy: mitogen_free
1210
become: true
1311
vars:
1412
distro: "{{ansible_distribution}}"
15-
ver: "{{ansible_distribution_major_version}}"
16-
1713
special_users:
1814
- has_sudo
1915
- has_sudo_nopw

tests/image_prep/ansible.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

22
[defaults]
3+
deprecation_warnings = false
34
strategy_plugins = ../../ansible_mitogen/plugins/strategy
45
retry_files_enabled = false
56
display_args_to_stdout = True
67
no_target_syslog = True
78
host_key_checking = False
9+
10+
[inventory]
11+
unparsed_is_fatal = true

tests/image_prep/build_docker_images.py

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
common_packages:
2+
- openssh-server
3+
- rsync
4+
- strace
5+
- sudo
6+
17
sudo_group:
28
MacOSX: admin
39
Debian: sudo

0 commit comments

Comments
 (0)