Updated deployment action to build all sections and deploy to the cloud server.
This commit is contained in:
parent
a3e52fbee3
commit
5b82bf9390
1 changed files with 74 additions and 35 deletions
109
.github/workflows/build-and-deploy.yml
vendored
109
.github/workflows/build-and-deploy.yml
vendored
|
|
@ -1,56 +1,95 @@
|
||||||
# For information on GITHUB_TOKEN: https://docs.github.com/en/actions/concepts/security/github_token
|
# .github/workflows/build-and-deploy.yml
|
||||||
# For information on github.actor: https://github.com/orgs/community/discussions/62108
|
|
||||||
|
|
||||||
name: Build and Deploy
|
name: Build and Deploy
|
||||||
|
|
||||||
|
# This workflow runs only on pushes to the 'main' branch
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
branches: ["main"]
|
|
||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
|
|
||||||
env:
|
|
||||||
CONTAINER_NAME: codered-astra
|
|
||||||
CONTAINER_TAG: ghcr.io/${{ github.repository_owner }}/codered-astra:latest
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# Set permissions for the job
|
build-and-deploy:
|
||||||
build:
|
# Set permissions for the job to read contents and write to GitHub Packages
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
attestations: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
name: Build Docker Image
|
name: Build Images and Deploy to Server
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Log in to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }} # User that commits
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
uses: docker/setup-buildx-action@v3
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
|
|
||||||
with:
|
with:
|
||||||
context: .
|
images: |
|
||||||
platforms: linux/amd64
|
ghcr.io/${{ github.repository }}/frontend
|
||||||
push: true
|
ghcr.io/${{ github.repository }}/nodejs-backend
|
||||||
tags: ${{ env.CONTAINER_TAG }}
|
ghcr.io/${{ github.repository }}/rust-engine
|
||||||
|
|
||||||
# WIP: For deployment
|
# --- Build and push one image for each service ---
|
||||||
deploy:
|
- name: Build and push frontend image 🚀
|
||||||
name: Deploy Docker Image to Server
|
uses: docker/build-push-action@v6
|
||||||
runs-on: self-hosted
|
with:
|
||||||
needs: build
|
context: ./frontend
|
||||||
steps:
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags_frontend }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels_frontend }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Build and push Node.js backend image 🚀
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./nodejs-backend
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags_nodejs-backend }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels_nodejs-backend }}
|
||||||
|
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: ${{ steps.meta.outputs.tags_rust-engine }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels_rust-engine }}
|
||||||
|
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: |
|
||||||
|
# Navigate to your project directory on the server
|
||||||
|
cd /var/www/codered-astra
|
||||||
|
|
||||||
|
# Export secrets as environment variables for Docker Compose
|
||||||
|
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 }}'
|
||||||
|
|
||||||
|
# Set the image tag to the specific commit SHA for a precise deployment
|
||||||
|
export IMAGE_TAG=${{ github.sha }}
|
||||||
|
|
||||||
|
# Pull the new images you just pushed to the registry
|
||||||
|
docker-compose pull
|
||||||
|
|
||||||
|
# Stop the old containers and start new ones with the updated images
|
||||||
|
docker-compose up -d --force-recreate
|
||||||
Loading…
Add table
Add a link
Reference in a new issue