fix: harden deploy workflow (if guard, wget --fail, pip ansible, secret cleanup)

This commit is contained in:
LaurensBartelds committed 2026-04-24 09:27:55 +02:00
1 parent 5a96a3c5b7
commit 28e8c8c375
1 file changed
+15 -10
+15 -10
View File
@@ -9,22 +9,23 @@ on:
jobs: jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' timeout-minutes: 15
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps: steps:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install Ansible - name: Install Ansible
run: | run: pip3 install --quiet "ansible>=9,<11"
sudo apt-get update -qq
sudo apt-get install -y ansible
- name: Write SSH Key - name: Write SSH Key
run: | run: |
echo "${{ secrets.ANSIBLE_SSH_KEY }}" > /tmp/ansible_key printf '%s\n' "${{ secrets.ANSIBLE_SSH_KEY }}" > /tmp/ansible_key
chmod 600 /tmp/ansible_key chmod 600 /tmp/ansible_key
- name: Write Inventory - name: Write Inventory
# StrictHostKeyChecking=no is intentional for a known home-network host.
# To harden, add the host fingerprint as a secret and use a known_hosts file.
run: | run: |
printf '[orangepi]\norangepi ansible_host=%s ansible_user=%s ansible_ssh_private_key_file=/tmp/ansible_key ansible_ssh_common_args="-o StrictHostKeyChecking=no"\n' \ printf '[orangepi]\norangepi ansible_host=%s ansible_user=%s ansible_ssh_private_key_file=/tmp/ansible_key ansible_ssh_common_args="-o StrictHostKeyChecking=no"\n' \
"${{ secrets.ANSIBLE_HOST }}" \ "${{ secrets.ANSIBLE_HOST }}" \
@@ -34,15 +35,19 @@ jobs:
run: | run: |
TAG="${{ github.event.workflow_run.head_branch }}" TAG="${{ github.event.workflow_run.head_branch }}"
BASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}" BASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG}"
wget -q "${BASE_URL}/brainwave-arm64.tar.gz" wget --fail -q "${BASE_URL}/brainwave-arm64.tar.gz" || { echo "Failed to download ARM tarball from ${BASE_URL}"; exit 1; }
wget -q "${BASE_URL}/docker-compose.arm64.yml" wget --fail -q "${BASE_URL}/docker-compose.arm64.yml" || { echo "Failed to download docker-compose file from ${BASE_URL}"; exit 1; }
- name: Deploy via Ansible - name: Deploy via Ansible
env:
WORKSPACE: ${{ github.workspace }}
run: | run: |
ansible-playbook ansible/deploy.yml \ ansible-playbook ansible/deploy.yml \
-i /tmp/inventory.ini \ -i /tmp/inventory.ini \
-e "artifact_path=${{ github.workspace }}" -e "artifact_path=${WORKSPACE}"
- name: Cleanup SSH Key - name: Cleanup Secrets
if: always() if: always()
run: rm -f /tmp/ansible_key run: |
rm -f /tmp/ansible_key
rm -f /tmp/inventory.ini