diff --git a/.github/workflows/test_linting.yml b/.github/workflows/test_linting.yml index c8c1497e..462607d6 100644 --- a/.github/workflows/test_linting.yml +++ b/.github/workflows/test_linting.yml @@ -30,6 +30,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: "3.11" + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install test dependencies. run: | diff --git a/.github/workflows/test_plugins.yml b/.github/workflows/test_plugins.yml index 8564a82e..045f5212 100644 --- a/.github/workflows/test_plugins.yml +++ b/.github/workflows/test_plugins.yml @@ -172,6 +172,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: "3.11" + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -179,6 +181,44 @@ jobs: python3 -m pip install "ansible-core>=2.19,<2.20" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/test_role_beats.yml b/.github/workflows/test_role_beats.yml index ecdbe64c..9e9d1ceb 100644 --- a/.github/workflows/test_role_beats.yml +++ b/.github/workflows/test_role_beats.yml @@ -56,6 +56,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -63,6 +65,44 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/test_role_elasticsearch.yml b/.github/workflows/test_role_elasticsearch.yml index af73ecc3..73218066 100644 --- a/.github/workflows/test_role_elasticsearch.yml +++ b/.github/workflows/test_role_elasticsearch.yml @@ -55,6 +55,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -62,6 +64,44 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/test_role_kibana.yml b/.github/workflows/test_role_kibana.yml index dd11e841..c6bd3dd4 100644 --- a/.github/workflows/test_role_kibana.yml +++ b/.github/workflows/test_role_kibana.yml @@ -56,6 +56,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -63,6 +65,44 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/test_role_logstash.yml b/.github/workflows/test_role_logstash.yml index 011ca4e4..8bd4255e 100644 --- a/.github/workflows/test_role_logstash.yml +++ b/.github/workflows/test_role_logstash.yml @@ -56,6 +56,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -63,6 +65,44 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/test_role_repos.yml b/.github/workflows/test_role_repos.yml index 4b9a4bae..7e3135ae 100644 --- a/.github/workflows/test_role_repos.yml +++ b/.github/workflows/test_role_repos.yml @@ -59,6 +59,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -66,6 +68,44 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/test_roles_pr.yml b/.github/workflows/test_roles_pr.yml index 074f4c61..2f4edef1 100644 --- a/.github/workflows/test_roles_pr.yml +++ b/.github/workflows/test_roles_pr.yml @@ -23,6 +23,13 @@ on: - '.github/workflows/test_roles_pr.yml' merge_group: +# Cancel outdated pipeline runs when a new push occurs in the pull request and a new pipeline starts. +# The merge queue is not affected because each merge attempt uses a new temporary branch with a unique name, +# so github.ref is different each time. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: lint_collection: if: github.event.pull_request.draft == false @@ -61,6 +68,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -68,6 +77,45 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE @@ -116,6 +164,8 @@ jobs: uses: actions/setup-python@v6 with: python-version: ${{ matrix.python_version }} + cache: 'pip' + cache-dependency-path: requirements-test.txt - name: Install dependencies run: | @@ -123,6 +173,45 @@ jobs: python3 -m pip install "${{ matrix.ansible_version }}" python3 -m pip install -r requirements-test.txt + - name: Get latest Elasticsearch release + id: elastic-version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Restore Elastic apt cache + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + uses: actions/cache/restore@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + + - name: Debug - apt cache contents + if: contains(matrix.distro, 'ubuntu') || contains(matrix.distro, 'debian') + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" + + - name: Ensure apt cache directory exists + run: mkdir -p /tmp/elastic-apt-cache + - name: Install collection run: | mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE diff --git a/.github/workflows/warm_apt_cache.yml b/.github/workflows/warm_apt_cache.yml new file mode 100644 index 00000000..c20a05e3 --- /dev/null +++ b/.github/workflows/warm_apt_cache.yml @@ -0,0 +1,96 @@ +--- +name: Warm Elastic apt cache +on: + push: + branches: + - main + schedule: + - cron: '0 3 * * *' + workflow_dispatch: + +jobs: + warm_cache: + runs-on: ubuntu-latest + permissions: + actions: write + + strategy: + fail-fast: false + matrix: + release: + - 8 + + steps: + - name: Get latest Elasticsearch release + id: elastic-version + run: | + curl -fsSL \ + "https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt/dists/stable/main/binary-amd64/Packages.gz" \ + -o /tmp/Packages.gz + VERSION=$(zcat /tmp/Packages.gz \ + | awk '$1=="Package:" && $2=="elasticsearch"{p=1} p && $1=="Version:"{print $2; p=0}' \ + | sort -V \ + | tail -n 1) + rm -f /tmp/Packages.gz + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Debug - latest Elasticsearch version + run: echo "Latest Elasticsearch ${{ matrix.release }}.x = ${{ steps.elastic-version.outputs.version }}" + + - name: Debug - list existing apt caches + env: + GH_TOKEN: ${{ github.token }} + run: | + WANT_KEY="${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }}" + echo "=== Looking for key: ${WANT_KEY} ===" + echo "=== All caches in repo ===" + gh api "repos/${{ github.repository }}/actions/caches?per_page=100" \ + | jq -r '.actions_caches[] | "\(.key) size=\(.size_in_bytes) created=\(.created_at)"' + echo "=== Total cache count in repo ===" + gh api "repos/${{ github.repository }}/actions/caches?per_page=1" | jq '.total_count' + + - name: Restore Elastic apt cache + id: apt-cache + uses: actions/cache@v5 + with: + path: /tmp/elastic-apt-cache + key: ${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }} + restore-keys: | + ${{ runner.os }}-apt-elastic-${{ matrix.release }}. + save-always: true + + - name: Pre-download Elastic packages to apt cache + if: steps.apt-cache.outputs.cache-hit != 'true' + run: | + mkdir -p /tmp/elastic-apt-cache + curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch \ + | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch.gpg + echo "deb [signed-by=/usr/share/keyrings/elasticsearch.gpg] https://artifacts.elastic.co/packages/${{ matrix.release }}.x/apt stable main" \ + | sudo tee /etc/apt/sources.list.d/elastic.list + sudo apt-get update -q + sudo apt-get install -y --download-only \ + -o Dir::Cache::archives=/tmp/elastic-apt-cache \ + elasticsearch logstash kibana filebeat + sudo rm -f /tmp/elastic-apt-cache/lock + sudo rm -rf /tmp/elastic-apt-cache/partial + + - name: Delete outdated Elastic apt caches + if: steps.apt-cache.outputs.cache-hit != 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + CURRENT_KEY="${{ runner.os }}-apt-elastic-${{ steps.elastic-version.outputs.version }}" + echo "Keeping cache: ${CURRENT_KEY}" + gh api "repos/${{ github.repository }}/actions/caches?key=${{ runner.os }}-apt-elastic-${{ matrix.release }}.&per_page=100" \ + | jq -r --arg current "${CURRENT_KEY}" '.actions_caches[] | select(.key != $current) | .id' \ + | while read -r CACHE_ID; do + echo "Deleting outdated cache id=${CACHE_ID}" + gh api --method DELETE "repos/${{ github.repository }}/actions/caches/${CACHE_ID}" + done + + - name: Debug - apt cache contents + run: | + echo "=== /tmp/elastic-apt-cache/ ===" + ls -lh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(empty or does not exist)" + echo "=== Total size ===" + du -sh /tmp/elastic-apt-cache/ 2>/dev/null || echo "(n/a)" diff --git a/molecule/beats_default/molecule.yml b/molecule/beats_default/molecule.yml index a6458a8d..04afbfc8 100644 --- a/molecule/beats_default/molecule.yml +++ b/molecule/beats_default/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/beats_default/prepare.yml b/molecule/beats_default/prepare.yml index 9cc68f65..27a36564 100644 --- a/molecule/beats_default/prepare.yml +++ b/molecule/beats_default/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/beats_extended/molecule.yml b/molecule/beats_extended/molecule.yml index 231a8323..2c3ebf19 100644 --- a/molecule/beats_extended/molecule.yml +++ b/molecule/beats_extended/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/beats_extended/prepare.yml b/molecule/beats_extended/prepare.yml index 9cc68f65..27a36564 100644 --- a/molecule/beats_extended/prepare.yml +++ b/molecule/beats_extended/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/elasticsearch_default/molecule.yml b/molecule/elasticsearch_default/molecule.yml index 5779b9cd..6b5210d2 100644 --- a/molecule/elasticsearch_default/molecule.yml +++ b/molecule/elasticsearch_default/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true @@ -23,6 +24,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/elasticsearch_default/prepare.yml b/molecule/elasticsearch_default/prepare.yml index 2bf1ed5e..1774f749 100644 --- a/molecule/elasticsearch_default/prepare.yml +++ b/molecule/elasticsearch_default/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/elasticsearch_roles_calculation/molecule.yml b/molecule/elasticsearch_roles_calculation/molecule.yml index caed77d0..a1f4d4e2 100644 --- a/molecule/elasticsearch_roles_calculation/molecule.yml +++ b/molecule/elasticsearch_roles_calculation/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true @@ -23,6 +24,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true @@ -33,6 +35,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/elasticsearch_roles_calculation/prepare.yml b/molecule/elasticsearch_roles_calculation/prepare.yml index fa5412f2..8a76c45f 100644 --- a/molecule/elasticsearch_roles_calculation/prepare.yml +++ b/molecule/elasticsearch_roles_calculation/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Refresh apt cache ansible.builtin.apt: update_cache: yes diff --git a/molecule/elasticstack_default/molecule.yml b/molecule/elasticstack_default/molecule.yml index 21623b6f..1131b0e6 100644 --- a/molecule/elasticstack_default/molecule.yml +++ b/molecule/elasticstack_default/molecule.yml @@ -16,6 +16,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true @@ -28,6 +29,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/elasticstack_default/prepare.yml b/molecule/elasticstack_default/prepare.yml index 545d0b4c..f07307ae 100644 --- a/molecule/elasticstack_default/prepare.yml +++ b/molecule/elasticstack_default/prepare.yml @@ -21,6 +21,11 @@ enabled: yes when: ansible_os_family == "RedHat" + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/kibana_default/molecule.yml b/molecule/kibana_default/molecule.yml index 06044bca..d47297a1 100644 --- a/molecule/kibana_default/molecule.yml +++ b/molecule/kibana_default/molecule.yml @@ -11,6 +11,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/kibana_default/prepare.yml b/molecule/kibana_default/prepare.yml index 7761965f..c3546b8b 100644 --- a/molecule/kibana_default/prepare.yml +++ b/molecule/kibana_default/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages needed for Debian ansible.builtin.apt: name: diff --git a/molecule/logstash_pinned_version/molecule.yml b/molecule/logstash_pinned_version/molecule.yml index 067f9c4f..a76b3ee7 100644 --- a/molecule/logstash_pinned_version/molecule.yml +++ b/molecule/logstash_pinned_version/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/logstash_pinned_version/prepare.yml b/molecule/logstash_pinned_version/prepare.yml index 9cc68f65..27a36564 100644 --- a/molecule/logstash_pinned_version/prepare.yml +++ b/molecule/logstash_pinned_version/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/logstash_pipelines/molecule.yml b/molecule/logstash_pipelines/molecule.yml index bad53617..18e9a185 100644 --- a/molecule/logstash_pipelines/molecule.yml +++ b/molecule/logstash_pipelines/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/logstash_pipelines/prepare.yml b/molecule/logstash_pipelines/prepare.yml index 8a568980..c8fb13af 100644 --- a/molecule/logstash_pipelines/prepare.yml +++ b/molecule/logstash_pipelines/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/plugins/molecule.yml b/molecule/plugins/molecule.yml index 90a13bde..5e703286 100644 --- a/molecule/plugins/molecule.yml +++ b/molecule/plugins/molecule.yml @@ -13,6 +13,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/plugins/prepare.yml b/molecule/plugins/prepare.yml index 76776e21..48dc97a1 100644 --- a/molecule/plugins/prepare.yml +++ b/molecule/plugins/prepare.yml @@ -6,6 +6,11 @@ ansible.builtin.debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install packages for Debian ansible.builtin.apt: name: diff --git a/molecule/repos_default/molecule.yml b/molecule/repos_default/molecule.yml index a2e83a8a..e28787fa 100644 --- a/molecule/repos_default/molecule.yml +++ b/molecule/repos_default/molecule.yml @@ -11,6 +11,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/repos_default/prepare.yml b/molecule/repos_default/prepare.yml index e15902d2..3b2affbf 100644 --- a/molecule/repos_default/prepare.yml +++ b/molecule/repos_default/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install requirements for Debian ansible.builtin.apt: name: diff --git a/molecule/repos_oss/molecule.yml b/molecule/repos_oss/molecule.yml index 208559b6..4cf55478 100644 --- a/molecule/repos_oss/molecule.yml +++ b/molecule/repos_oss/molecule.yml @@ -11,6 +11,7 @@ platforms: command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /tmp/elastic-apt-cache:/opt/elastic-apt-cache:ro cgroupns_mode: host privileged: true pre_build_image: true diff --git a/molecule/repos_oss/prepare.yml b/molecule/repos_oss/prepare.yml index e15902d2..3b2affbf 100644 --- a/molecule/repos_oss/prepare.yml +++ b/molecule/repos_oss/prepare.yml @@ -6,6 +6,11 @@ debug: var: ansible_facts.discovered_interpreter_python + - name: Populate apt cache from runner pre-downloaded packages + ansible.builtin.shell: | + cp /opt/elastic-apt-cache/*.deb /var/cache/apt/archives/ 2>/dev/null || true + when: ansible_os_family == "Debian" + - name: Install requirements for Debian ansible.builtin.apt: name: diff --git a/test.md b/test.md new file mode 100644 index 00000000..e69de29b