49 lines
1.7 KiB
YAML
49 lines
1.7 KiB
YAML
name: Validate and Deploy Homelab
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
|
|
jobs:
|
|
test-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout Repository Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Verify Compose File Validity
|
|
env:
|
|
DB_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
|
|
DB_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
|
|
run: docker compose config
|
|
|
|
# --- DEPLOYMENT PHASE ---
|
|
|
|
- name: Set up SSH Private Key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
# Scan the host key to prevent SSH hanging on a manual confirmation prompt
|
|
ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
|
|
|
|
- name: Create Remote Docker Context
|
|
run: |
|
|
# Define a remote endpoint pointing to your live server over SSH
|
|
docker context create homelab-target \
|
|
--docker "host=ssh://${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}"
|
|
|
|
- name: Deploy Containers to Live Server
|
|
env:
|
|
# Pass your production secrets to the live deployment step
|
|
DB_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
|
|
DB_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
|
|
run: |
|
|
echo "Switching Docker context to live server..."
|
|
docker context use homelab-target
|
|
|
|
echo "Pulling latest images and starting services remotely..."
|
|
# The --project-directory . flag ensures it reads the docker-compose file fetched by Git
|
|
docker compose --project-directory . up -d --remove-orphans
|