2023-07-09 03:43:52 +00:00
|
|
|
name: homelab-ci
|
|
|
|
|
2023-07-20 04:33:42 +00:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
- testing
|
2023-07-09 03:43:52 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
homelab-ci:
|
2024-05-02 04:57:31 +00:00
|
|
|
runs-on: macos-13
|
2023-07-09 03:43:52 +00:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Cache Vagrant boxes
|
|
|
|
uses: actions/cache@v3
|
|
|
|
with:
|
|
|
|
path: ~/.vagrant.d/boxes
|
|
|
|
key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-vagrant-
|
|
|
|
|
2024-05-02 04:57:31 +00:00
|
|
|
- name: Install VirtualBox
|
|
|
|
run: brew install --cask virtualbox
|
|
|
|
|
|
|
|
- name: Install Vagrant
|
|
|
|
run: brew install --cask vagrant
|
|
|
|
|
2023-07-09 03:43:52 +00:00
|
|
|
- name: Install Ansible
|
2024-05-02 04:57:31 +00:00
|
|
|
run: brew install ansible
|
2023-07-09 03:43:52 +00:00
|
|
|
|
|
|
|
- name: Software Versions
|
|
|
|
run: |
|
2024-05-02 04:57:31 +00:00
|
|
|
printf "VirtualBox "; vboxmanage --version
|
2023-07-09 03:43:52 +00:00
|
|
|
vagrant --version
|
|
|
|
ansible --version
|
|
|
|
|
2024-05-02 04:57:31 +00:00
|
|
|
- name: Install nmap
|
|
|
|
run: brew install nmap
|
|
|
|
|
2023-07-09 03:43:52 +00:00
|
|
|
- name: Vagrant Up with Dockerbox Playbook
|
2024-05-02 04:57:31 +00:00
|
|
|
env:
|
|
|
|
SSH_AUTH_SOCK: ''
|
2023-07-09 03:43:52 +00:00
|
|
|
run: |
|
2024-05-02 04:57:31 +00:00
|
|
|
set +x
|
|
|
|
ssh-add -D && echo "[homelab-ci] SSH Agent disabled"
|
|
|
|
PLAYBOOK=dockerbox vagrant up --debug &
|
|
|
|
VAGRANT_UP_PID=$!
|
|
|
|
echo "[homelab-ci] Waiting for VM to start..."
|
|
|
|
TIMEOUT=600
|
|
|
|
ELAPSED=0
|
|
|
|
SLEEP_DURATION=10
|
|
|
|
SSH_AVAILABLE=0
|
|
|
|
while [[ $ELAPSED -lt $TIMEOUT ]]; do
|
|
|
|
PRIVATE_KEY="$(find .vagrant -name "private_key" 2>/dev/null | sort)"
|
|
|
|
HOST_IP="$(vagrant ssh-config | grep HostName | awk '{print $2}')"
|
|
|
|
echo "[homelab-ci] Checking SSH connection availability..."
|
|
|
|
echo "[homelab-ci] Private Key: $PRIVATE_KEY"
|
|
|
|
echo "[homelab-ci] Host IP: $HOST_IP"
|
|
|
|
echo "[homelab-ci] Running nmap to check open ports..."
|
|
|
|
nmap -p 22 "$HOST_IP" | grep "22/tcp open" && SSH_AVAILABLE=1 || SSH_AVAILABLE=0
|
|
|
|
if [[ $SSH_AVAILABLE -eq 1 ]]; then
|
|
|
|
echo "[homelab-ci] SSH port is open, attempting connection..."
|
|
|
|
ssh -vvv -i "$PRIVATE_KEY" \
|
|
|
|
-o UserKnownHostsFile=/dev/null \
|
|
|
|
-o StrictHostKeyChecking=no \
|
|
|
|
-v vagrant@"$HOST_IP" && break || echo "[homelab-ci] SSH connection failed, retrying..."
|
|
|
|
else
|
|
|
|
echo "[homelab-ci] SSH port not open, retrying in $SLEEP_DURATION seconds..."
|
|
|
|
fi
|
|
|
|
sleep $SLEEP_DURATION
|
|
|
|
((ELAPSED+=SLEEP_DURATION))
|
|
|
|
done
|
|
|
|
if [[ $SSH_AVAILABLE -ne 1 ]]; then
|
|
|
|
echo "[homelab-ci] Timeout reached without successful SSH connection."
|
|
|
|
fi
|
|
|
|
wait $VAGRANT_UP_PID # Ensure the Vagrant up process completes
|