67 lines
No EOL
2.1 KiB
YAML
67 lines
No EOL
2.1 KiB
YAML
# .github/workflows/build-and-deploy.yml
|
|
|
|
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: ["main"]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
name: Build Images and Deploy to Server
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# --- Build and push one image for each service ---
|
|
- name: Build and push web-app image 🚀
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./web-app
|
|
push: true
|
|
tags: ghcr.io/${{ github.repository }}/web-app:${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Build and push Rust engine image ⚙️
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./rust-engine
|
|
push: true
|
|
tags: ghcr.io/${{ github.repository }}/rust-engine:${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# --- Deploy the new images to your server ---
|
|
- name: Deploy to server via SSH ☁️
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: ${{ secrets.SERVER_USERNAME }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
script: |
|
|
cd /var/www/codered-astra
|
|
export GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}'
|
|
export MYSQL_DATABASE='${{ secrets.MYSQL_DATABASE }}'
|
|
export MYSQL_USER='${{ secrets.MYSQL_USER }}'
|
|
export MYSQL_PASSWORD='${{ secrets.MYSQL_PASSWORD }}'
|
|
export MYSQL_ROOT_PASSWORD='${{ secrets.MYSQL_ROOT_PASSWORD }}'
|
|
export IMAGE_TAG=${{ github.sha }}
|
|
docker-compose pull
|
|
docker-compose up -d --force-recreate |