Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 14 additions & 227 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -1,279 +1,66 @@
name: Deploy GranCaffe Production


on:

push:
branches:
- develop

- main
workflow_dispatch:



permissions:

contents: read
packages: write



env:

IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/grancaffe



jobs:


build-and-deploy:


name: Build Docker image and deploy

name: Build and Deploy Production
runs-on: ubuntu-latest



steps:


########################################
# Checkout
########################################

- name: Checkout source code

- name: Checkout repository
uses: actions/checkout@v4



########################################
# Docker Buildx
########################################

- name: Setup Docker Buildx

uses: docker/setup-buildx-action@v3



########################################
# Login GHCR
########################################

- name: Login GitHub Container Registry

- name: Login to GHCR
uses: docker/login-action@v3

with:

registry: ghcr.io

username: ${{ github.actor }}

password: ${{ secrets.GITHUB_TOKEN }}



########################################
# Docker metadata
########################################

- name: Docker metadata

id: meta

uses: docker/metadata-action@v5

with:

images: ${{ env.IMAGE_NAME }}

tags: |

type=raw,value=latest

type=sha



########################################
# Build and push image
########################################

- name: Build and push Docker image

- name: Build and Push Docker Image
uses: docker/build-push-action@v6


with:

context: .

file: ./Dockerfile

push: true


platforms: linux/amd64


tags: |

${{ steps.meta.outputs.tags }}


labels: |

${{ steps.meta.outputs.labels }}


build-args: |

GIT_COMMIT=${{ github.sha }}

GIT_BRANCH=${{ github.ref_name }}


${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: |

type=gha


cache-to: |

type=gha,mode=max





########################################
# Deploy DigitalOcean
########################################

- name: Deploy to DigitalOcean Droplet


- name: Deploy to DigitalOcean
uses: appleboy/ssh-action@v1.2.0


with:


host: ${{ secrets.DO_HOST }}


username: ${{ secrets.DO_USER }}


key: ${{ secrets.DO_SSH_KEY }}


script: |


set -e



echo "Go to application directory"


cd /opt/grancaffe




echo "Login GHCR"


echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u romamatran --password-stdin




echo "Pull latest image"


echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io \
-u ${{ github.repository_owner }} \
--password-stdin
docker compose pull




echo "Restart containers"


docker compose up -d --remove-orphans




echo "Cleanup old images"


docker image prune -f




echo "Deployment completed"





########################################
# Verify
########################################

- name: Health check


- name: Verify deployment
uses: appleboy/ssh-action@v1.2.0


with:


host: ${{ secrets.DO_HOST }}


username: ${{ secrets.DO_USER }}


key: ${{ secrets.DO_SSH_KEY }}


script: |


set -e



echo "Containers status"


docker ps



echo "Waiting application startup"


sleep 20




echo "Checking HTTP"


docker ps
curl --fail http://localhost:5000



echo "Application is running"
echo "GranCaffe is running"
Loading
Loading