Skip to content

Commit

Permalink
docker: add additional packages into hold
Browse files Browse the repository at this point in the history
removed docker-switch and changed tasks into cleanup
can be disabled by the user in case they want to install it themselves
  • Loading branch information
saltydk committed Sep 27, 2023
1 parent 8155a8c commit 39c14ea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
35 changes: 21 additions & 14 deletions roles/docker/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ containerd_io_filepath: "/usr/bin/containerd"

containerd_io_dpkg: "containerd.io"

# Docker Compose

compose_cli_name: "Docker Compose"

compose_cli_package: "docker-compose-plugin"

compose_cli_filepath: "docker compose"

compose_cli_dpkg: "docker-compose-plugin"

# Docker Rootless Extras

docker_rootless_name: "Docker Rootless Extras"

docker_rootless_package: "docker-ce-rootless-extras"

docker_rootless_filepath: "/usr/bin/rootlesskit"

docker_rootless_dpkg: "docker-ce-rootless-extras"

# Misc

docker_package_state: "{{ 'latest' if (docker_version is defined and docker_version | lower == 'latest') else 'present' }}"
Expand Down Expand Up @@ -113,17 +133,4 @@ fuse_overlayfs_release_lookup_command: |
# Docker Compose
################################

compose_install_switch: true

compose_switch_github_endpoint: "latest"

compose_switch_releases_url: "{{ cvm }}https://api.github.com/repos/docker/compose-switch/releases/{{ compose_switch_github_endpoint }}"

compose_switch_releases_download_url: https://github.com/docker/compose-switch/releases/download

compose_switch_release_lookup_command: |
curl -s {{ compose_switch_releases_url }} \
| jq -r ".assets[] | select(.name | test(\"docker-compose-linux-amd64\")) \
| .browser_download_url"
compose_switch_download_backup_url: "https://github.com/docker/compose-switch/releases/download/v1.0.4/docker-compose-linux-amd64"
compose_cleanup_switch: "{{ compose_install_switch | default(true) }}"
2 changes: 2 additions & 0 deletions roles/docker/tasks/subtasks/binary/binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
- 'containerd_io'
- 'docker_ce'
- 'docker_ce_cli'
- 'compose_cli'
- 'docker_rootless'

- name: Binary | Install apparmor
ansible.builtin.apt:
Expand Down
2 changes: 1 addition & 1 deletion roles/docker/tasks/subtasks/binary/binary2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
when: put_docker_dpkg_into_hold

- name: Binary | Get '{{ vars[item ~ '_name'] }}' version
ansible.builtin.shell: "{{ vars[item ~ '_filepath'] }} --version | head -n 1 | awk '{ print $3 }' | sed 's/,$//'"
ansible.builtin.shell: "{{ vars[item ~ '_filepath'] }} '{{ 'version' if item == 'compose_cli' else '--version' }}' | head -n 1 | awk '{ print {{ '$4' if item == 'compose_cli' else '$3' }} }' | sed 's/,$//' | sed 's/v//'"
register: binary_version
ignore_errors: true
changed_when: false
Expand Down
49 changes: 20 additions & 29 deletions roles/docker/tasks/subtasks/compose.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
#########################################################################
# Title: Saltbox: Docker | Compose Tasks #
# Title: Saltbox: Docker | Compose Switch Tasks #
# Author(s): salty #
# URL: https://github.com/saltyorg/Saltbox #
# -- #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Install Compose Switch
when: compose_install_switch
- name: Cleanup Compose Switch
when: compose_cleanup_switch
block:
- name: "Get URL for latest Compose release"
ansible.builtin.shell: "{{ compose_switch_release_lookup_command }}"
args:
executable: /bin/bash
register: compose_switch_download_url
ignore_errors: true

- name: Download Compose Switch
ansible.builtin.shell: curl -SL {{ compose_switch_download_url.stdout | default(compose_switch_download_backup_url, true) }} -o /usr/local/bin/compose-switch

- name: Make docker-compose executable
ansible.builtin.file:
dest: "/usr/local/bin/compose-switch"
mode: a+x

- name: Check if Docker Compose V1 is installed
- name: Check if '/usr/local/bin/compose-switch' exists
ansible.builtin.stat:
path: "/usr/local/bin/docker-compose"
register: docker_compose_v1
path: '/usr/local/bin/compose-switch'
register: compose_switch_cleanup_path

- name: Rename Docker Compose V1 binary
ansible.builtin.command: mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v1
when: docker_compose_v1.stat.exists
- name: Run tasks if '/usr/local/bin/compose-switch' exists
when: compose_switch_cleanup_path.stat.exists
block:
- name: Remove docker-compose alternatives
ansible.builtin.shell: update-alternatives --remove-all docker-compose
ignore_errors: true

- name: Define alternatives group for docker-compose command - Entry 1
ansible.builtin.shell: update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/docker-compose-v1 1
when: docker_compose_v1.stat.exists
- name: Delete '/usr/local/bin/compose-switch'
ansible.builtin.file:
dest: "/usr/local/bin/compose-switch"
state: absent

- name: Define alternatives group for docker-compose command - Entry 2
ansible.builtin.shell: update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
- name: Delete '/usr/local/bin/docker-compose-v1'
ansible.builtin.file:
dest: "/usr/local/bin/docker-compose-v1"
state: absent
2 changes: 1 addition & 1 deletion roles/docker/templates/docker-update-hosts.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExecStart=/usr/local/bin/docker-update-hosts
RuntimeMaxSec={{ docker_update_hosts_service_runtime_max }}
Restart=always
RestartSec=20s
StartLimitIntervalSec=0
StartLimitInterval=0

[Install]
WantedBy=docker.service

0 comments on commit 39c14ea

Please sign in to comment.