Using reusable action for Ansible Playbook actions.
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
name: Gitea Branch PR, Cloudflare DNS, README generation, & Docker Deployment
|
name: Gitea Branch PR, Cloudflare DNS, README generation, & Docker Deployment
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches-ignore:
|
branches-ignore:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- '**.yml'
|
- '**.yml'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-and-create-pr:
|
check-and-create-pr:
|
||||||
name: Check and Create PR
|
name: Check and Create PR
|
||||||
@@ -14,14 +12,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install tea
|
- name: Install tea
|
||||||
uses: supplypike/setup-bin@v4
|
uses: supplypike/setup-bin@v4
|
||||||
with:
|
with:
|
||||||
uri: 'https://gitea.com/gitea/tea/releases/download/v0.9.2/tea-0.9.2-linux-amd64'
|
uri: 'https://gitea.com/gitea/tea/releases/download/v0.9.2/tea-0.9.2-linux-amd64'
|
||||||
name: 'tea'
|
name: 'tea'
|
||||||
version: '0.9.2'
|
version: '0.9.2'
|
||||||
|
|
||||||
- name: Check if open PR exists
|
- name: Check if open PR exists
|
||||||
id: check-opened-pr-step
|
id: check-opened-pr-step
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
@@ -34,7 +30,6 @@ jobs:
|
|||||||
pr_exists=$(tea pr list --repo ${{ github.repository }} --state open --fields index,title,head | egrep ${{ github.ref_name }} | tail -1 | wc -l)
|
pr_exists=$(tea pr list --repo ${{ github.repository }} --state open --fields index,title,head | egrep ${{ github.ref_name }} | tail -1 | wc -l)
|
||||||
echo ${pr_exists}
|
echo ${pr_exists}
|
||||||
echo "exists=$pr_exists" >> $GITHUB_OUTPUT
|
echo "exists=$pr_exists" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Create PR
|
- name: Create PR
|
||||||
if: ${{ steps.check-opened-pr-step.outputs.exists == '0' }}
|
if: ${{ steps.check-opened-pr-step.outputs.exists == '0' }}
|
||||||
run: |
|
run: |
|
||||||
@@ -43,7 +38,6 @@ jobs:
|
|||||||
pr_index_new=$(expr ${pr_index_old} + 1)
|
pr_index_new=$(expr ${pr_index_old} + 1)
|
||||||
echo "New PR index: ${pr_index_new}"
|
echo "New PR index: ${pr_index_new}"
|
||||||
tea pr c -r ${{ github.repository }} -t "Automated PR for ${{ github.ref_name }} - ${pr_index_new}" -d "Automatically created PR for branch: ${{ github.ref_name }}" -a ${{ github.actor }}
|
tea pr c -r ${{ github.repository }} -t "Automated PR for ${{ github.ref_name }} - ${pr_index_new}" -d "Automatically created PR for branch: ${{ github.ref_name }}" -a ${{ github.actor }}
|
||||||
|
|
||||||
docker-compose-ansible-lints:
|
docker-compose-ansible-lints:
|
||||||
name: Docker Compose & Ansible Lints
|
name: Docker Compose & Ansible Lints
|
||||||
needs: [check-and-create-pr]
|
needs: [check-and-create-pr]
|
||||||
@@ -54,32 +48,35 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install jq
|
- name: Install jq
|
||||||
uses: dcarbone/install-jq-action@v3.0.1
|
uses: dcarbone/install-jq-action@v3.0.1
|
||||||
|
|
||||||
- name: Install Vault
|
- name: Install Vault
|
||||||
uses: cpanato/vault-installer@main
|
uses: cpanato/vault-installer@main
|
||||||
with:
|
with:
|
||||||
vault-release: '1.18.3'
|
vault-release: '1.18.3'
|
||||||
|
- name: Install Ansible
|
||||||
- uses: getsentry/action-setup-venv@v2.1.0
|
uses: alex-oleshkevich/setup-ansible@v1.0.1
|
||||||
id: venv
|
|
||||||
with:
|
with:
|
||||||
python-version: 3.11.11
|
version: "2.18.1"
|
||||||
install-cmd: pip install hvac
|
- name: Install hvac (Python library for HashiCorp Vault)
|
||||||
|
uses: insightsengineering/pip-action@v2
|
||||||
- name: Ansible Lint
|
|
||||||
uses: ansible/ansible-lint@v24.12.2
|
|
||||||
with:
|
with:
|
||||||
working_directory: "ansible"
|
packages: hvac
|
||||||
requirements_file: "collections/requirements.yml"
|
- name: Ansible Playbook Dry Run
|
||||||
|
uses: arillso/action.playbook@0.0.8
|
||||||
- name: Generate .env file for docker compose linting
|
with:
|
||||||
|
galaxy_collections_path: ansible/collections
|
||||||
|
galaxy_requirements_file: ansible/collections/requirements.yml
|
||||||
|
inventory: ansible/ansible-inventory
|
||||||
|
playbook: ansible/docker_config_deploy.yml
|
||||||
|
check: true
|
||||||
|
diff: true
|
||||||
|
vault_password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
|
||||||
|
verbose: 1
|
||||||
|
- name: Generate .env file for Docker Compose Dry Run
|
||||||
run: |
|
run: |
|
||||||
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
|
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
|
||||||
|
- name: Docker Compose Dry Run
|
||||||
- name: Docker Compose Lint
|
|
||||||
uses: yu-ichiro/spin-up-docker-compose-action@v1
|
uses: yu-ichiro/spin-up-docker-compose-action@v1
|
||||||
with:
|
with:
|
||||||
file: docker-compose.yml
|
file: docker-compose.yml
|
||||||
@@ -89,7 +86,6 @@ jobs:
|
|||||||
up-opts: --dry-run -d --remove-orphans
|
up-opts: --dry-run -d --remove-orphans
|
||||||
env:
|
env:
|
||||||
DOCKER_HOST: tcp://dockerproxy:2375
|
DOCKER_HOST: tcp://dockerproxy:2375
|
||||||
|
|
||||||
cloudflare-dns-setup:
|
cloudflare-dns-setup:
|
||||||
name: Cloudflare DNS Setup
|
name: Cloudflare DNS Setup
|
||||||
needs: [docker-compose-ansible-lints]
|
needs: [docker-compose-ansible-lints]
|
||||||
@@ -97,20 +93,16 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install jq
|
- name: Install jq
|
||||||
uses: dcarbone/install-jq-action@v3.0.1
|
uses: dcarbone/install-jq-action@v3.0.1
|
||||||
|
|
||||||
- name: Install yq
|
- name: Install yq
|
||||||
uses: dcarbone/install-yq-action@v1
|
uses: dcarbone/install-yq-action@v1
|
||||||
|
|
||||||
- name: Install flarectl
|
- name: Install flarectl
|
||||||
uses: supplypike/setup-bin@v4
|
uses: supplypike/setup-bin@v4
|
||||||
with:
|
with:
|
||||||
uri: 'https://github.com/cloudflare/cloudflare-go/releases/download/v0.113.0/flarectl_0.113.0_linux_amd64.tar.gz'
|
uri: 'https://github.com/cloudflare/cloudflare-go/releases/download/v0.113.0/flarectl_0.113.0_linux_amd64.tar.gz'
|
||||||
name: 'flarectl'
|
name: 'flarectl'
|
||||||
version: '0.113.0'
|
version: '0.113.0'
|
||||||
|
|
||||||
- name: Grab Subdomains from Docker Compose & Cloudflare
|
- name: Grab Subdomains from Docker Compose & Cloudflare
|
||||||
id: grab-subdomains
|
id: grab-subdomains
|
||||||
env:
|
env:
|
||||||
@@ -121,7 +113,6 @@ jobs:
|
|||||||
yq '.services[].labels.swag_url' docker-compose.yml | egrep -v 'null' | sed -e 's|"||g' | awk -F'.' '{print $1}' | sort > compose_subdomains.txt
|
yq '.services[].labels.swag_url' docker-compose.yml | egrep -v 'null' | sed -e 's|"||g' | awk -F'.' '{print $1}' | sort > compose_subdomains.txt
|
||||||
echo "Grabbing subdomains from Cloudflare..."
|
echo "Grabbing subdomains from Cloudflare..."
|
||||||
flarectl --json dns list --zone "trez.wtf" --type=CNAME --content "trez.wtf" | jq '.[].Name' | sed -e 's|"||g' | awk -F"." '{print $1}' | sort > cloudflare_subdomains.txt
|
flarectl --json dns list --zone "trez.wtf" --type=CNAME --content "trez.wtf" | jq '.[].Name' | sed -e 's|"||g' | awk -F"." '{print $1}' | sort > cloudflare_subdomains.txt
|
||||||
|
|
||||||
- name: Compare Subdomains
|
- name: Compare Subdomains
|
||||||
id: compare-subdomains
|
id: compare-subdomains
|
||||||
uses: LouisBrunner/diff-action@v2.2.0
|
uses: LouisBrunner/diff-action@v2.2.0
|
||||||
@@ -131,7 +122,6 @@ jobs:
|
|||||||
mode: addition
|
mode: addition
|
||||||
tolerance: mixed-better
|
tolerance: mixed-better
|
||||||
output: domain_compare.txt
|
output: domain_compare.txt
|
||||||
|
|
||||||
- name: Create Subdomains
|
- name: Create Subdomains
|
||||||
if: steps.compare-subdomains.outputs.output != ''
|
if: steps.compare-subdomains.outputs.output != ''
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
@@ -143,7 +133,6 @@ jobs:
|
|||||||
echo "Creating $subdomain.trez.wtf..."
|
echo "Creating $subdomain.trez.wtf..."
|
||||||
flarectl dns create --zone "trez.wtf" --name "${subdomain}" --type=CNAME --content "trez.wtf" --proxy true
|
flarectl dns create --zone "trez.wtf" --name "${subdomain}" --type=CNAME --content "trez.wtf" --proxy true
|
||||||
done
|
done
|
||||||
|
|
||||||
regenerate-readme:
|
regenerate-readme:
|
||||||
name: Update README
|
name: Update README
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -153,33 +142,27 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install yq
|
- name: Install yq
|
||||||
uses: dcarbone/install-yq-action@v1
|
uses: dcarbone/install-yq-action@v1
|
||||||
|
|
||||||
- name: Generate service list
|
- name: Generate service list
|
||||||
run: |
|
run: |
|
||||||
yq '.services | to_entries | map({"service": .key, "image": .value.image})' docker-compose.yml > services.yml
|
yq '.services | to_entries | map({"service": .key, "image": .value.image})' docker-compose.yml > services.yml
|
||||||
|
|
||||||
- name: Generate Markdown Table
|
- name: Generate Markdown Table
|
||||||
uses: gazab/create-markdown-table@v1
|
uses: gazab/create-markdown-table@v1
|
||||||
id: service-table
|
id: service-table
|
||||||
with:
|
with:
|
||||||
file: ./services.yml
|
file: ./services.yml
|
||||||
|
|
||||||
- name: Regenerate README
|
- name: Regenerate README
|
||||||
run: |
|
run: |
|
||||||
echo "# List of Services" > README.md
|
echo "# List of Services" > README.md
|
||||||
echo -e "\n\n" >> README.md
|
echo -e "\n\n" >> README.md
|
||||||
echo "${{ steps.service-table.outputs.table }}" >> README.md
|
echo "${{ steps.service-table.outputs.table }}" >> README.md
|
||||||
|
|
||||||
- name: Add/Commit README.md
|
- name: Add/Commit README.md
|
||||||
id: commit-readme
|
id: commit-readme
|
||||||
uses: EndBug/add-and-commit@v9
|
uses: EndBug/add-and-commit@v9
|
||||||
with:
|
with:
|
||||||
message: "chore: Update README"
|
message: "chore: Update README"
|
||||||
add: "README.md"
|
add: "README.md"
|
||||||
|
|
||||||
pr-merge:
|
pr-merge:
|
||||||
name: PR Merge
|
name: PR Merge
|
||||||
needs: [regenerate-readme]
|
needs: [regenerate-readme]
|
||||||
@@ -187,14 +170,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install tea
|
- name: Install tea
|
||||||
uses: supplypike/setup-bin@v4
|
uses: supplypike/setup-bin@v4
|
||||||
with:
|
with:
|
||||||
uri: 'https://gitea.com/gitea/tea/releases/download/v0.9.2/tea-0.9.2-linux-amd64'
|
uri: 'https://gitea.com/gitea/tea/releases/download/v0.9.2/tea-0.9.2-linux-amd64'
|
||||||
name: 'tea'
|
name: 'tea'
|
||||||
version: '0.9.2'
|
version: '0.9.2'
|
||||||
|
|
||||||
- name: PR Merge
|
- name: PR Merge
|
||||||
id: pr_merge
|
id: pr_merge
|
||||||
run: |
|
run: |
|
||||||
@@ -204,7 +185,6 @@ jobs:
|
|||||||
pr_index=$(tea pr ls --repo ${{ github.repository }} --state open --fields index,title,head,state --output csv | egrep ${{ github.ref_name }} | awk -F, '{print $1}' | sed -e 's|"||g')
|
pr_index=$(tea pr ls --repo ${{ github.repository }} --state open --fields index,title,head,state --output csv | egrep ${{ github.ref_name }} | awk -F, '{print $1}' | sed -e 's|"||g')
|
||||||
echo "${pr_index}"
|
echo "${pr_index}"
|
||||||
tea pr m --repo ${{ github.repository }} --title "Auto Merge of PR #${pr_index} - ${{ github.ref_name }}" --message "Merged by ${{ github.actor }}" --output table ${pr_index}
|
tea pr m --repo ${{ github.repository }} --title "Auto Merge of PR #${pr_index} - ${{ github.ref_name }}" --message "Merged by ${{ github.actor }}" --output table ${pr_index}
|
||||||
|
|
||||||
ansible-config-docker-compose-deploy:
|
ansible-config-docker-compose-deploy:
|
||||||
name: Deploy via Ansible & Docker Compose
|
name: Deploy via Ansible & Docker Compose
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -219,25 +199,20 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Install Ansible
|
|
||||||
uses: alex-oleshkevich/setup-ansible@v1.0.1
|
|
||||||
with:
|
|
||||||
version: "2.18.1"
|
|
||||||
|
|
||||||
- name: Install Vault
|
- name: Install Vault
|
||||||
uses: cpanato/vault-installer@main
|
uses: cpanato/vault-installer@main
|
||||||
|
- name: Ansible Playbook Dry Run
|
||||||
- name: Run Ansible Playbook for Docker Service Configs
|
uses: arillso/action.playbook@0.0.8
|
||||||
uses: actions-ansible@v2
|
|
||||||
with:
|
with:
|
||||||
playbook: ./ansible/docker_config_deploy.yml
|
galaxy_collections_path: ansible/collections
|
||||||
inventory: ./ansible/ansible-inventory
|
galaxy_requirements_file: ansible/collections/requirements.yml
|
||||||
|
inventory: ansible/ansible-inventory
|
||||||
|
playbook: ansible/docker_config_deploy.yml
|
||||||
|
vault_password: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
|
||||||
|
verbose: 1
|
||||||
- name: Generate .env file for deployment
|
- name: Generate .env file for deployment
|
||||||
run: |
|
run: |
|
||||||
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
|
vault kv get -format=json rinoa-docker/env | jq -r '.data.data' | jq -r 'keys[] as $k | "\($k)='\''\(.[$k])'\''"' > .env
|
||||||
|
|
||||||
- name: Docker Compose Deployment
|
- name: Docker Compose Deployment
|
||||||
uses: keatonLiu/docker-compose-remote-action@v1.2
|
uses: keatonLiu/docker-compose-remote-action@v1.2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
**/.cache.ggshield
|
**/.cache.ggshield
|
||||||
|
ansible/collections/ansible_collections/
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
ansible-navigator:
|
|
||||||
logging:
|
|
||||||
level: debug
|
|
||||||
append: false
|
|
||||||
file: $PWD/.logs/ansible-navigator.log
|
|
||||||
|
|
||||||
playbook-artifact:
|
|
||||||
enable: true
|
|
||||||
save-as: "$PWD/.logs/{playbook_name}-artifact-{time_stamp}.json"
|
|
||||||
Reference in New Issue
Block a user