Skip to content

Commit

Permalink
Feat: Added cron support
Browse files Browse the repository at this point in the history
  • Loading branch information
SamJUK committed Jul 17, 2024
1 parent 09489d5 commit 9d3a30d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ None.

Available variables are listed below, along with default values (see defaults/main.yml):

```yaml
ecomscan_cron: true
```
Boolean to set if ecomscan should be run by cron (@Note: This requires a CRON schedule to be installed on your system)
```yaml
ecomscan_cron_expr: "0 */4 * * *"
```
Cron expresion to define how frequently to run the schedule scans
```yaml
ecomscan_binary_download: true
```
Expand Down
18 changes: 5 additions & 13 deletions _local_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

set -e

VERSIONS=(
"ubuntu:22.04"
"debian:12.6"
"rockylinux:9.3"
"fedora:39"
)

for VER in "${VERSIONS[@]}"; do
MOLECULE_DISTRO=$(echo "$VER" | awk -F: '{print $1}') \
MOLECULE_DISTRO_VER=$(echo "$VER" | awk -F: '{print $2}') \
VERSIONS=$(yq '.jobs.molecule.strategy.matrix.distro | map(.image + ":" + .version)' .github/workflows/ci.yml -o shell | awk -F= '{print $2}' | tr -d "'")
while IFS= read -r VER; do
export MOLECULE_DISTRO=$(echo "$VER" | awk -F: '{print $1}')
export MOLECULE_DISTRO_VER=$(echo "$VER" | awk -F: '{print $2}')
molecule test
done


done <<< "$VERSIONS"
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ecomscan_cron: true
ecomscan_cron_expr: "0 */4 * * *"
ecomscan_binary_download: true
ecomscan_binary_source: https://ecomscan.com/downloads/linux-amd64/ecomscan
ecomscan_binary_directory: ~/bin
Expand Down
6 changes: 6 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
- name: Test
hosts: all
pre_tasks:
- name: Ensure /etc/cron.d/ exists
ansible.builtin.file:
path: /etc/cron.d/
state: directory
mode: '0755'

- name: Create Simulated ENV
ansible.builtin.file:
path: /var/www/vhosts/magento2/htdocs/
Expand Down
12 changes: 12 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
mode: '0744'
when: ecomscan_binary_download

- name: Configure Cron
ansible.builtin.copy:
content: >
{{ ecomscan_cron_expr }} {{ ansible_user | default('root') }} {{ ecomscan_binary_path }}
--monitor={{ ecomscan_report_email }}
--key={{ ecomscan_key }}
{{ ecomscan_project_root }}
dest: "/etc/cron.d/ecomscan-{{ inventory_hostname }}"
mode: "644"
when: ecomscan_cron

- name: Perform Ecomscan
ansible.builtin.command:
cmd: >
Expand Down

0 comments on commit 9d3a30d

Please sign in to comment.