Skip to content

Commit

Permalink
install Docker compose in cli-plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Sjögren <[email protected]>
  • Loading branch information
konstruktoid committed Sep 2, 2023
1 parent 914e159 commit 6e24cc8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 39 deletions.
16 changes: 3 additions & 13 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,14 @@
- name: Verify Docker compose plugin is installed
become: true
become_user: "{{ docker_user }}"
environment:
PATH: "{{ docker_user_info.home }}/bin:{{ docker_user_info.home }}/.local/bin:{{ ansible_env.PATH }}"
ansible.builtin.command:
cmd: docker compose version
register: docker_compose_plugin
changed_when: false
failed_when: docker_compose_plugin.rc != 0
when: docker_rootful and docker_compose

- name: Verify that docker-compose is installed
become: true
become_user: "{{ docker_user }}"
environment:
PATH: "{{ docker_user_info.home }}/bin:{{ docker_user_info.home }}/.local/bin"
ansible.builtin.command:
cmd: docker-compose version
register: docker_compose_version
changed_when: false
failed_when: docker_compose_version.rc != 0
when: not docker_rootful and docker_compose
when: docker_compose

- name: Container verification block
environment:
Expand Down
54 changes: 54 additions & 0 deletions tasks/docker_compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- name: Install Docker compose
become: true
ansible.builtin.package:
name: docker-compose-plugin
state: present
when: docker_rootful
tags:
- apt
- dnf
- docker-compose

- name: Install rootless Docker compose
when: not docker_rootful
become: true
become_user: "{{ docker_user }}"
tags:
- docker-compose
block:
- name: Stat Compose in /bin dir
ansible.builtin.stat:
path: "{{ docker_user_info.home }}/bin/docker-compose"
register: docker_compose_bin

- name: Debug
ansible.builtin.debug:
msg: "{{ docker_compose_bin }}"

- name: Create cli-plugins directory
ansible.builtin.file:
path: "{{ docker_user_info.home }}/.docker/cli-plugins"
state: directory
mode: "0700"

- name: Download docker-compose
ansible.builtin.get_url:
url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_release }}/docker-compose-linux-x86_64"
dest: "{{ docker_user_info.home }}/.docker/cli-plugins/docker-compose"
checksum: sha256:{{ docker_compose_release_shasum }}
owner: "{{ docker_user }}"
mode: "0755"
when: docker_compose

- name: Remove Compose in /bin dir
ansible.builtin.file:
path: "{{ docker_user_info.home }}/bin/docker-compose"
state: absent
when: docker_compose_bin.stat.exists and not docker_compose_bin.stat.islnk

- name: Create Compose link
ansible.builtin.file:
src: "{{ docker_user_info.home }}/.docker/cli-plugins/docker-compose"
dest: "{{ docker_user_info.home }}/bin/docker-compose"
state: link
11 changes: 0 additions & 11 deletions tasks/docker_install_rootful.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,3 @@
- apt
- dnf
- docker

- name: Install Docker compose
become: true
ansible.builtin.package:
name: docker-compose-plugin
state: present
when: docker_compose
tags:
- apt
- dnf
- docker-compose
13 changes: 0 additions & 13 deletions tasks/docker_install_rootless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,6 @@
- --strip-components=1
remote_src: true

- name: Download docker-compose
become: true
become_user: "{{ docker_user }}"
ansible.builtin.get_url:
url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_release }}/docker-compose-linux-x86_64"
dest: "{{ docker_user_info.home }}/bin/docker-compose"
checksum: sha256:{{ docker_compose_release_shasum }}
owner: "{{ docker_user }}"
mode: "0755"
when: docker_compose
tags:
- docker-compose

- name: Add Docker systemd service
become: true
become_user: "{{ docker_user }}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/docker_service_rootful.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
tags:
- modprobe

- name: Install rootless docker
- name: Install rootless Docker
become: true
become_user: "{{ docker_user }}"
environment:
Expand Down
6 changes: 5 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
msg: slirp4netns (>= 0.4.0) is required, currently not available in Debian <= 10
when: docker_rootful and (ansible_distribution == "Debian" and ansible_distribution_major_version <= '10')

- name: Install and configure rootless docker
- name: Install and configure rootless Docker
ansible.builtin.include_tasks: docker_install_rootless.yml
when: not docker_rootful

- name: Install Docker Compose
ansible.builtin.include_tasks: docker_compose.yml
when: docker_compose

- name: Add user sudo alias
vars:
sudo_alias: >
Expand Down

0 comments on commit 6e24cc8

Please sign in to comment.