Fixing automated build and deployment. Corrected outdated file structure and added build cache to the action.
This commit is contained in:
parent
282048e62d
commit
cb9cff4421
1 changed files with 10 additions and 26 deletions
36
.github/workflows/build-and-deploy.yml
vendored
36
.github/workflows/build-and-deploy.yml
vendored
|
|
@ -28,37 +28,30 @@ jobs:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# --- NEW STEP TO FIX THE CACHING ERROR ---
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
ghcr.io/${{ github.repository }}/frontend
|
ghcr.io/${{ github.repository }}/web-app
|
||||||
ghcr.io/${{ github.repository }}/nodejs-backend
|
|
||||||
ghcr.io/${{ github.repository }}/rust-engine
|
ghcr.io/${{ github.repository }}/rust-engine
|
||||||
|
|
||||||
# --- Build and push one image for each service ---
|
# --- Build and push one image for each service ---
|
||||||
- name: Build and push frontend image 🚀
|
- name: Build and push web-app image 🚀
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ./frontend
|
context: ./web-app
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags_frontend }}
|
tags: ${{ steps.meta.outputs.tags_web-app }}
|
||||||
labels: ${{ steps.meta.outputs.labels_frontend }}
|
labels: ${{ steps.meta.outputs.labels_web-app }}
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
- name: Build and push Node.js backend image 🚀
|
- name: Build and push Rust engine 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
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ./rust-engine
|
context: ./rust-engine
|
||||||
|
|
@ -76,21 +69,12 @@ jobs:
|
||||||
username: ${{ secrets.SERVER_USERNAME }}
|
username: ${{ secrets.SERVER_USERNAME }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
script: |
|
script: |
|
||||||
# Navigate to your project directory on the server
|
|
||||||
cd /var/www/codered-astra
|
cd /var/www/codered-astra
|
||||||
|
|
||||||
# Export secrets as environment variables for Docker Compose
|
|
||||||
export GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}'
|
export GEMINI_API_KEY='${{ secrets.GEMINI_API_KEY }}'
|
||||||
export MYSQL_DATABASE='${{ secrets.MYSQL_DATABASE }}'
|
export MYSQL_DATABASE='${{ secrets.MYSQL_DATABASE }}'
|
||||||
export MYSQL_USER='${{ secrets.MYSQL_USER }}'
|
export MYSQL_USER='${{ secrets.MYSQL_USER }}'
|
||||||
export MYSQL_PASSWORD='${{ secrets.MYSQL_PASSWORD }}'
|
export MYSQL_PASSWORD='${{ secrets.MYSQL_PASSWORD }}'
|
||||||
export MYSQL_ROOT_PASSWORD='${{ secrets.MYSQL_ROOT_PASSWORD }}'
|
export MYSQL_ROOT_PASSWORD='${{ secrets.MYSQL_ROOT_PASSWORD }}'
|
||||||
|
|
||||||
# Set the image tag to the specific commit SHA for a precise deployment
|
|
||||||
export IMAGE_TAG=${{ github.sha }}
|
export IMAGE_TAG=${{ github.sha }}
|
||||||
|
|
||||||
# Pull the new images you just pushed to the registry
|
|
||||||
docker-compose pull
|
docker-compose pull
|
||||||
|
|
||||||
# Stop the old containers and start new ones with the updated images
|
|
||||||
docker-compose up -d --force-recreate
|
docker-compose up -d --force-recreate
|
||||||
Loading…
Add table
Add a link
Reference in a new issue