Run tests on EC2
This commit is contained in:
parent
4efcad9869
commit
9b141583a6
111
.github/workflows/main.yml
vendored
111
.github/workflows/main.yml
vendored
@ -1,66 +1,61 @@
|
|||||||
---
|
---
|
||||||
name: Molecule tests for Wazuh Ansible
|
name: do-the-job
|
||||||
on: [pull_request, workflow_dispatch, release]
|
on: [push, pull_request, workflow_dispatch, release]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
start-runner:
|
||||||
scenario-default:
|
name: Start self-hosted EC2 runner
|
||||||
name: Default scenario (smoke)
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
label: ${{ steps.start-ec2-runner.outputs.label }}
|
||||||
|
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the codebase.
|
- name: Configure AWS credentials
|
||||||
uses: actions/checkout@v2
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
|
|
||||||
- name: Hack to get setup-python to work on act. See act issue 251
|
|
||||||
run: |
|
|
||||||
# Hack to get setup-python to work on act
|
|
||||||
if [ ! -f "/etc/lsb-release" ] ; then
|
|
||||||
echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Set up Python 3.
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
- name: Install poetry
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
run: pip3 install poetry
|
- name: Start EC2 runner
|
||||||
|
id: start-ec2-runner
|
||||||
- name: Install dependencies
|
uses: machulav/ec2-github-runner@v2
|
||||||
run: poetry install
|
with:
|
||||||
|
mode: start
|
||||||
- name: Run Molecule tests.
|
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
|
||||||
run: poetry run molecule test -s default
|
ec2-image-id: ami-123
|
||||||
env:
|
ec2-instance-type: t3.nano
|
||||||
PY_COLORS: '1'
|
subnet-id: subnet-123
|
||||||
ANSIBLE_FORCE_COLOR: '1'
|
security-group-id: sg-123
|
||||||
|
iam-role-name: my-role-name # optional, requires additional permissions
|
||||||
scenario-distributed-wazuh:
|
aws-resource-tags: > # optional, requires additional permissions
|
||||||
name: Distributed Wazuh
|
[
|
||||||
|
{"Key": "Name", "Value": "ec2-github-runner"},
|
||||||
|
{"Key": "GitHubRepository", "Value": "${{ github.repository }}"}
|
||||||
|
]
|
||||||
|
do-the-job:
|
||||||
|
name: Do the job on the runner
|
||||||
|
needs: start-runner # required to start the main job when the runner is ready
|
||||||
|
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
|
||||||
|
steps:
|
||||||
|
- name: Hello World
|
||||||
|
run: echo 'Hello World!'
|
||||||
|
stop-runner:
|
||||||
|
name: Stop self-hosted EC2 runner
|
||||||
|
needs:
|
||||||
|
- start-runner # required to get output from the start-runner job
|
||||||
|
- do-the-job # required to wait when the main job is done
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the codebase.
|
- name: Configure AWS credentials
|
||||||
uses: actions/checkout@v2
|
uses: aws-actions/configure-aws-credentials@v1
|
||||||
|
|
||||||
- name: Hack to get setup-python to work on act. See act issue 251
|
|
||||||
run: |
|
|
||||||
if [ ! -f "/etc/lsb-release" ] ; then
|
|
||||||
echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Set up Python 3.
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
- name: Install poetry
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
run: pip3 install poetry
|
- name: Stop EC2 runner
|
||||||
|
uses: machulav/ec2-github-runner@v2
|
||||||
- name: Install dependencies
|
with:
|
||||||
run: poetry install
|
mode: stop
|
||||||
|
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
|
||||||
- name: Run Molecule tests.
|
label: ${{ needs.start-runner.outputs.label }}
|
||||||
run: poetry run molecule test -s distributed-wazuh
|
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
|
||||||
env:
|
|
||||||
PY_COLORS: '1'
|
|
||||||
ANSIBLE_FORCE_COLOR: '1'
|
|
||||||
Loading…
Reference in New Issue
Block a user