CI: improve Docker setup (#550)

* Cache has already been updated a few lines before.

* When skipping Docker cleanup, create flag to avoid the expensive part of the setup (including package manager cache update) to be run again.
This commit is contained in:
Felix Fontein 2023-01-08 22:21:59 +01:00 committed by GitHub
parent dc5af8985b
commit 134d32cae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 32 deletions

View File

@ -35,7 +35,6 @@
apt: apt:
name: '{{ docker_packages if needs_docker_daemon else docker_cli_packages }}' name: '{{ docker_packages if needs_docker_daemon else docker_cli_packages }}'
state: present state: present
update_cache: true
always: always:
- name: Restore /usr/sbin/policy-rc.d (if needed) - name: Restore /usr/sbin/policy-rc.d (if needed)

View File

@ -14,40 +14,53 @@
- name: Detect whether we are running inside a container - name: Detect whether we are running inside a container
current_container_facts: current_container_facts:
- name: Determine whether Docker Daemon needs to be installed - name: Look for marker whether Docker was already set up
set_fact: stat:
needs_docker_daemon: '{{ not ansible_module_running_in_container }}' path: /root/community.docker-docker-is-set-up
register: docker_setup_marker
- name: Include distribution specific variables - when: not docker_setup_marker.stat.exists
include_vars: "{{ lookup('first_found', params) }}" block:
vars: - name: Determine whether Docker Daemon needs to be installed
params: set_fact:
files: needs_docker_daemon: '{{ not ansible_module_running_in_container }}'
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml"
- default.yml
paths:
- "{{ role_path }}/vars"
- name: Include distribution specific tasks - name: Include distribution specific variables
include_tasks: "{{ lookup('first_found', params) }}" include_vars: "{{ lookup('first_found', params) }}"
vars: vars:
params: params:
files: files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml" - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml" - "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}.yml" - "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml" - "{{ ansible_facts.os_family }}.yml"
paths: - default.yml
- "{{ role_path }}/tasks" paths:
- "{{ role_path }}/vars"
- name: Make sure that docker is running - name: Include distribution specific tasks
service: include_tasks: "{{ lookup('first_found', params) }}"
name: docker vars:
state: started params:
when: not ansible_module_running_in_container files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml"
paths:
- "{{ role_path }}/tasks"
- name: Make sure that docker is running
service:
name: docker
state: started
when: not ansible_module_running_in_container
- name: Set marker that Docker was already set up
file:
path: /root/community.docker-docker-is-set-up
state: touch
when: docker_skip_cleanup
# Detect docker API version # Detect docker API version
- name: Check Docker API version - name: Check Docker API version