56 lines
1.7 KiB
YAML
56 lines
1.7 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master ]
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
|
|
|
|
optional-deploy:
|
|
runs-on: ubuntu-latest
|
|
needs: build-and-push
|
|
if: ${{ secrets.DEPLOY_HOST && secrets.DEPLOY_USER && secrets.DEPLOY_PASSWORD }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install sshpass
|
|
run: sudo apt-get update && sudo apt-get install -y sshpass
|
|
|
|
- name: Copy files and restart remote compose
|
|
env:
|
|
HOST: ${{ secrets.DEPLOY_HOST }}
|
|
USER: ${{ secrets.DEPLOY_USER }}
|
|
PASS: ${{ secrets.DEPLOY_PASSWORD }}
|
|
IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
|
|
run: |
|
|
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $USER@$HOST "mkdir -p ~/wm2026_deploy && exit"
|
|
sshpass -p "$PASS" scp -o StrictHostKeyChecking=no docker-compose.yml $USER@$HOST:~/wm2026_deploy/
|
|
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no $USER@$HOST "cd ~/wm2026_deploy && docker pull $IMAGE || true && docker-compose up -d --build"
|