Skip to content

Commit

Permalink
[docker] Don't use docker-compose Python library anymore and bump Ans…
Browse files Browse the repository at this point in the history
…ible
  • Loading branch information
goldyfruit committed Jan 21, 2024
1 parent 21156a6 commit e440b85
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 64 deletions.
4 changes: 2 additions & 2 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ collections:
- name: ansible.posix
version: 1.5.4
- name: community.docker
version: 3.4.11
version: 3.6.0
- name: community.general
version: 8.0.2
version: 8.2.0
23 changes: 12 additions & 11 deletions ansible/roles/ovos_installer/tasks/docker/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
enabled: true
state: started

- name: Install Python docker and docker-compose libraries
ansible.builtin.pip:
name:
- docker==6.1.3
- docker-compose
virtualenv: "{{ ovos_installer_venv }}"
tags:
- always

- name: Clone ovos-docker and/or hivemind-docker repository
ansible.builtin.git:
repo: "{{ item.url }}"
dest: "{{ _ovos_installer_working_directory }}/{{ item.dest }}"
version: "{{ item.branch }}"
force: true
loop:
- {"url": "{{ ovos_installer_ovos_docker_repo_url }}", "branch": "{{ ovos_installer_ovos_docker_repo_branch }}", "dest": "ovos-docker", "state": "{{ true if (ovos_installer_profile != 'satellite' or ovos_installer_cleaning | bool) else false }}"}
- {"url": "{{ ovos_installer_hivemind_docker_repo_url }}", "branch": "{{ ovos_installer_hivemind_docker_repo_branch }}", "dest": "hivemind-docker", "state": "{{ true if (ovos_installer_profile == 'satellite' or ovos_installer_cleaning | bool) else false }}"}
- {
"url": "{{ ovos_installer_ovos_docker_repo_url }}",
"branch": "{{ ovos_installer_ovos_docker_repo_branch }}",
"dest": "ovos-docker",
"state": "{{ true if (ovos_installer_profile != 'satellite' or ovos_installer_cleaning | bool) else false }}",
}
- {
"url": "{{ ovos_installer_hivemind_docker_repo_url }}",
"branch": "{{ ovos_installer_hivemind_docker_repo_branch }}",
"dest": "hivemind-docker",
"state": "{{ true if (ovos_installer_profile == 'satellite' or ovos_installer_cleaning | bool) else false }}",
}
when: item.state | bool
tags:
- always
143 changes: 96 additions & 47 deletions ansible/roles/ovos_installer/tasks/docker/composer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,85 @@
register: _ovos_installer_timezone
changed_when: false

- name: Set _composition_directory fact
ansible.builtin.set_fact:
_composition_directory: "{{ _ovos_installer_working_directory }}/{{ _ovos_installer_project_name }}/compose"
tags:
- always

- name: Generate .env file for docker-compose
ansible.builtin.template:
src: docker/env.j2
dest: "{{ _ovos_installer_working_directory }}/{{ _ovos_installer_project_name }}/compose/.env"
dest: "{{ _composition_directory }}/.env"
owner: root
group: root
mode: '0644'
mode: "0644"
tags:
- always

# Required because docker-compose (not docker compose) doesn't support userns option
- name: Remove YAML x-podman function from composition files
vars:
_remove_x_podman_ovos: "{{ 'true' if ovos_installer_profile != 'satellite' else 'false' }}"
_remove_x_podman_satellite: "{{ 'true' if ovos_installer_profile == 'satellite' else 'false' }}"
ansible.builtin.lineinfile:
path: "{{ item.file }}"
search_string: "<<: *podman"
state: absent
loop:
- {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.yml", "state": "{{ _remove_x_podman_ovos }}"}
- {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.skills.yml", "state": "{{ _remove_x_podman_ovos }}"}
- {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.hivemind.yml", "state": "{{ _remove_x_podman_ovos }}"}
- {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.gui.yml", "state": "{{ _remove_x_podman_ovos }}"}
- {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.windows.yml", "state": "{{ _remove_x_podman_ovos }}"}
- {"file": "{{ _ovos_installer_working_directory }}/hivemind-docker/compose/docker-compose.satellite.yml", "state": "{{ _remove_x_podman_satellite }}"}
when: item.state | bool

- name: Remove DISPLAY variable if EGLFS is used
ansible.builtin.lineinfile:
path: "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.gui.yml"
path: "{{ _composition_directory }}/docker-compose.gui.yml"
search_string: "DISPLAY"
state: absent
when: ovos_installer_profile != 'satellite' and
ovos_installer_feature_gui | bool and
ovos_installer_display_server == 'N/A'
ovos_installer_feature_gui | bool and
ovos_installer_display_server == 'N/A'

- name: Define composition
vars:
_os_type: "{{ 'wsl2' if ansible_kernel is search('microsoft') else 'linux' }}"
ansible.builtin.set_fact:
_composition_files: "{{ _composition_files | default([]) + [item.file] }}"
loop:
- {"file": "docker-compose.yml", "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'linux') else 'false' }}"}
- {"file": "docker-compose.windows.yml", "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'wsl2') else 'false' }}"}
- {"file": "docker-compose.raspberrypi.yml", "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A') else 'false' }}"}
- {"file": "docker-compose.skills.yml", "state": "{{ 'false' if (ansible_memtotal_mb < 2048 and ovos_installer_profile != 'satellite' or not ovos_installer_feature_skills | bool) else 'true' }}"}
- {"file": "docker-compose.hivemind.yml", "state": "{{ 'true' if ovos_installer_profile == 'listener' else 'false' }}"}
- {"file": "docker-compose.gui.yml", "state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_feature_gui | bool) else 'false' }}"}
- {"file": "docker-compose.raspberrypi.gui.yml", "state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A' and ovos_installer_feature_gui | bool) else 'false' }}"}
- {"file": "docker-compose.satellite.yml", "state": "{{ 'true' if ovos_installer_profile == 'satellite' else 'false' }}"}
- {
"file": "docker-compose.yml",
"state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'linux') else 'false' }}",
}
- {
"file": "docker-compose.windows.yml",
"state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'wsl2') else 'false' }}",
}
- {
"file": "docker-compose.raspberrypi.yml",
"state": "{{ 'true' if (ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A') else 'false' }}",
}
- {
"file": "docker-compose.skills.yml",
"state": "{{ 'false' if (ansible_memtotal_mb < 2048 and ovos_installer_profile != 'satellite' or not ovos_installer_feature_skills | bool) else 'true' }}",
}
- {
"file": "docker-compose.hivemind.yml",
"state": "{{ 'true' if ovos_installer_profile == 'listener' else 'false' }}",
}
- {
"file": "docker-compose.gui.yml",
"state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_feature_gui | bool) else 'false' }}",
}
- {
"file": "docker-compose.raspberrypi.gui.yml",
"state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A' and ovos_installer_feature_gui | bool) else 'false' }}",
}
- {
"file": "docker-compose.satellite.yml",
"state": "{{ 'true' if ovos_installer_profile == 'satellite' else 'false' }}",
}
when: item.state | bool

- name: Merge composition files into compose.yaml
ansible.builtin.template:
src: docker/compose.yaml.j2
dest: "{{ _composition_directory }}/compose.yaml"

- name: Deploy docker-compose stack
become: true
become_user: "{{ ovos_installer_user }}"
vars:
_project_name: "{{ 'hivemind' if ovos_installer_profile == 'satellite' else 'ovos' }}"
community.docker.docker_compose:
project_src: "{{ _ovos_installer_working_directory }}/{{ _ovos_installer_project_name }}/compose"
community.docker.docker_compose_v2:
project_src: "{{ _composition_directory }}"
project_name: "{{ _project_name }}"
files: "{{ _composition_files }}"
pull: true
pull: always
remove_orphans: "{{ ovos_installer_docker_compose_remove_orphans }}"
remove_images: "{{ ovos_installer_docker_compose_remove_images }}"
remove_volumes: "{{ ovos_installer_docker_compose_remove_volumes }}"
Expand All @@ -95,18 +111,49 @@
become_user: "{{ ovos_installer_user }}"
vars:
_composition_mapping:
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.yml"}
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.raspberrypi.yml"}
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.skills.yml"}
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.hivemind.yml"}
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.gui.yml"}
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.raspberrypi.gui.yml"}
- {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.windows.yml"}
- {"src": "hivemind-docker", "name": "hivemind", "file": "docker-compose.satellite.yml"}
community.docker.docker_compose:
project_src: "{{ _ovos_installer_working_directory }}/{{ item.src }}/compose"
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.yml",
}
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.raspberrypi.yml",
}
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.skills.yml",
}
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.hivemind.yml",
}
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.gui.yml",
}
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.raspberrypi.gui.yml",
}
- {
"src": "ovos-docker",
"name": "ovos",
"file": "docker-compose.windows.yml",
}
- {
"src": "hivemind-docker",
"name": "hivemind",
"file": "docker-compose.satellite.yml",
}
community.docker.docker_compose_v2:
project_src: "{{ _composition_directory }}"
project_name: "{{ item.name }}"
files: "{{ item.file }}"
remove_orphans: "{{ ovos_installer_docker_compose_remove_orphans }}"
remove_images: "{{ ovos_installer_docker_compose_remove_images }}"
remove_volumes: "{{ ovos_installer_docker_compose_remove_volumes }}"
Expand All @@ -116,7 +163,7 @@
environment:
DOCKER_TIMEOUT: "900"
register: _composer_deletion
failed_when: _composer_deletion is not defined # We never want it to fail even if systemd unit doesn't exist
failed_when: _composer_deletion is not defined # We never want it to fail

- name: Remove directories
ansible.builtin.file:
Expand All @@ -133,3 +180,5 @@
loop:
- "{{ _ovos_installer_working_directory }}/ovos-docker"
- "{{ _ovos_installer_working_directory }}/hivemind-docker"
tags:
- always
3 changes: 3 additions & 0 deletions ansible/roles/ovos_installer/templates/docker/compose.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for _composition_file in _composition_files %}
{{ lookup('file', _composition_directory + '/' + _composition_file) }}
{% endfor %}
5 changes: 1 addition & 4 deletions utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,9 @@ function create_python_venv() {
# Install Ansible into the new Python virtual environment and install the
# Ansible collections required by the Ansible playbook as well. These
# collection will be installed under the /root/.ansible directory.
#
# NOTE: PyYAML is downgraded because of docker-compose Python library which
# does not support PyYAML > 5.3.1 version.
function install_ansible() {
echo -ne "➤ Installing Ansible requirements in Python virtualenv... "
pip3 install ansible==8.6.1 PyYAML==5.3.1 &>>"$LOG_FILE"
pip3 install ansible==9.1.0 docker==7.0.0 &>>"$LOG_FILE"
ansible-galaxy collection install -r ansible/requirements.yml &>>"$LOG_FILE"
echo -e "[$done_format]"
}
Expand Down

0 comments on commit e440b85

Please sign in to comment.