Skip to content

Commit

Permalink
OPSEXP-2972 Workaround apache mirror flakiness with controller cache (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gionn authored Nov 28, 2024
1 parent 8883dfb commit 2fdff56
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 18 deletions.
33 changes: 33 additions & 0 deletions .github/actions/cache-downloads/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Cache downloads'
description: 'Cache downloads to speed up the workflow'
inputs:
cache-name:
description: 'A keyword to compose the cache final name'
required: true
default: 'default'
cache-version:
description: 'Increase to force recreating the cache'
required: true
default: "1"
runs:
using: "composite"
steps:
- name: Restore downloaded artifacts
id: artifacts-cache
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: 'downloads/**'
key: cache-downloads-v${{ inputs.cache-version }}-${{ inputs.cache-name }}-${{ hashFiles('group_vars/all.yml') }}-${{ hashFiles('playbooks/prefetch-artifacts.yml') }}

- name: Prefetch artifacts
shell: bash
if: steps.artifacts-cache.outputs.cache-hit != 'true'
run: |
pipenv run ansible-playbook -i inventory_local.yml playbooks/prefetch-artifacts.yml
- name: Save downloaded artifacts
uses: actions/cache/save@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
if: steps.artifacts-cache.outputs.cache-hit != 'true'
with:
path: 'downloads/**'
key: ${{ steps.artifacts-cache.outputs.cache-primary-key }}
3 changes: 3 additions & 0 deletions .github/actions/molecule_integration_ec2/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ runs:
- name: Setup workspace
uses: ./.github/actions/setup-workspace

- name: Cache downloads
uses: ./.github/actions/cache-downloads

- name: Generate unique id
shell: bash
run: echo "MOLECULE_IT_ID=$(date +%s%4N)" >> $GITHUB_ENV
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/community.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
! startsWith(github.head_ref, 'next/') && ! contains(github.event.pull_request.labels.*.name, 'ci-prerelease')
runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
molecule_distro:
- image: ubuntu:22.04
Expand Down Expand Up @@ -62,10 +62,17 @@ jobs:

- name: Install and cache ansible galaxy dependencies
uses: ./.github/actions/galaxy
with:
cache-name: community

- name: Setup workspace
uses: ./.github/actions/setup-workspace

- name: Cache downloads
uses: ./.github/actions/cache-downloads
with:
cache-name: community

- name: Run tests
env:
MOLECULE_ROLE_IMAGE: ${{ matrix.molecule_distro.image }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ jobs:
- name: Setup workspace
uses: ./.github/actions/setup-workspace

- name: Cache downloads
uses: ./.github/actions/cache-downloads
with:
cache-name: ${{ inputs.galaxy_cache }}

- name: Run tests
env:
MOLECULE_ROLE_IMAGE: ${{ inputs.os_distribution }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/enteprise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
outputs:
dtas_version: ${{ steps.jobvars.outputs.dtas_version }}
strategy:
fail-fast: true
fail-fast: false
matrix:
molecule_distro:
- image: ubuntu:22.04
Expand Down Expand Up @@ -89,6 +89,9 @@ jobs:
- name: Setup workspace
uses: ./.github/actions/setup-workspace

- name: Cache downloads
uses: ./.github/actions/cache-downloads

- name: Run tests
env:
MOLECULE_ROLE_IMAGE: ${{ matrix.molecule_distro.image }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,7 @@ $RECYCLE.BIN/

# End of https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode
*.zip

apache-activemq-*-bin.tar.gz
apache-tomcat-*.tar.gz
downloads/
2 changes: 2 additions & 0 deletions inventory_local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
all:
vars:
ansible_connection: local
# reuse the same python interpreter as the one used to run the playbook
ansible_python_interpreter: "{{ ansible_playbook_python }}"

children:
repository:
Expand Down
36 changes: 36 additions & 0 deletions playbooks/prefetch-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Download artifacts from flaky mirrors and cache them on the controller for later use.
# Particularly useful when running on CI or nodes with limited internet access.
# Run with `ansible-playbook -i inventory_local.yml playbooks/prefetch-artifacts.yml`
- name: Download and cache artifacts on the controller
hosts: localhost
gather_facts: true
tasks:
- name: Include common vars
ansible.builtin.include_vars: ../roles/common/{{ item }}/main.yml
loop: ["defaults", "vars"]

- name: Set path for local download
ansible.builtin.stat:
path: "{{ lookup('env', 'GITHUB_WORKSPACE') | default(lookup('env', 'PWD'), True) }}"
register: local_path

- name: Create download location
ansible.builtin.file:
path: "{{ local_path.stat.path }}/downloads"
state: directory
mode: "0755"
register: download_path

- name: Download ActiveMQ archive
ansible.builtin.get_url:
url: "{{ dependencies_url.activemq }}"
checksum: sha512:{{ dependencies_url.activemq_sha512_checksum_url }}
dest: "{{ download_path.path }}/apache-activemq-{{ dependencies_version.activemq }}-bin.tar.gz"
mode: "0644"

- name: Download Tomcat archive
ansible.builtin.get_url:
url: "{{ dependencies_url.tomcat }}"
checksum: sha512:{{ dependencies_url.tomcat_sha512_checksum_url }}
dest: "{{ download_path.path }}/apache-tomcat-{{ dependencies_version.tomcat }}.tar.gz"
mode: "0644"
36 changes: 23 additions & 13 deletions roles/activemq/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
---
- name: Download activemq tar
- name: Set path for local download
delegate_to: localhost
ansible.builtin.stat:
path: "{{ lookup('env', 'GITHUB_WORKSPACE') | default(lookup('env', 'PWD'), True) }}"
register: local_path

- name: Create download location
delegate_to: localhost
ansible.builtin.file:
path: "{{ local_path.stat.path }}/downloads"
state: directory
mode: "0755"
register: download_path

- name: Download ActiveMQ archive # noqa ignore-errors
delegate_to: localhost
ansible.builtin.get_url:
url: "{{ dependencies_url.activemq }}"
checksum: sha512:{{ dependencies_url.activemq_sha512_checksum_url }}
dest: "{{ download_location }}/apache-activemq-{{ activemq_version }}-bin.tar.gz"
dest: "{{ download_path.path }}/apache-activemq-{{ activemq_version }}-bin.tar.gz"
mode: "0644"
register: activemq_download
async: 900
poll: 0
changed_when: false
ignore_errors: true

- name: Check on activemq download async task
ansible.builtin.async_status:
jid: "{{ activemq_download.ansible_job_id }}"
register: job_result
until: job_result.finished
delay: 5
retries: 300
- name: Copy archive to target
ansible.builtin.copy:
src: "{{ download_path.path }}/apache-activemq-{{ activemq_version }}-bin.tar.gz"
dest: "{{ download_location }}/apache-activemq-{{ activemq_version }}-bin.tar.gz"
mode: "0644"

- name: Install ActiveMQ
become: true
Expand Down
26 changes: 23 additions & 3 deletions roles/tomcat/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
---

Check warning on line 1 in roles/tomcat/tasks/main.yml

View workflow job for this annotation

GitHub Actions / kics

[INFO] Risky File Permissions

Some modules could end up creating new files on disk with permissions that might be too open or unpredictable
# tasks file for base-tomcat
- name: Download Tomcat
- name: Set path for local download
delegate_to: localhost
ansible.builtin.stat:
path: "{{ lookup('env', 'GITHUB_WORKSPACE') | default(lookup('env', 'PWD'), True) }}"
register: local_path

- name: Create download location
delegate_to: localhost
ansible.builtin.file:
path: "{{ local_path.stat.path }}/downloads"
state: directory
mode: "0755"
register: download_path

- name: Download Tomcat archive # noqa ignore-errors
delegate_to: localhost
ansible.builtin.get_url:
url: "{{ dependencies_url.tomcat }}"
checksum: sha512:{{ dependencies_url.tomcat_sha512_checksum_url }}
dest: "{{ download_path.path }}/apache-tomcat-{{ dependencies_version.tomcat }}.tar.gz"
mode: "0644"
ignore_errors: true

- name: Copy archive to target
ansible.builtin.copy:
src: "{{ download_path.path }}/apache-tomcat-{{ dependencies_version.tomcat }}.tar.gz"
dest: "{{ download_location }}/apache-tomcat-{{ dependencies_version.tomcat }}.tar.gz"
timeout: 600
mode: "0644"

- name: Install Tomcat {{ dependencies_version.tomcat }}
Expand Down

0 comments on commit 2fdff56

Please sign in to comment.