Skip to content

added check and validations using class-transformer #35

added check and validations using class-transformer

added check and validations using class-transformer #35

name: staging-pipeline
on:
workflow_dispatch:
push:
branches:
- develop
pull_request:
types: [closed]
branches:
- develop
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build_and_push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/generalmagicio/worldview-be:staging
deploy:
needs: publish
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy Staging
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
command_timeout: 200m
script: |
set -e
docker system prune -f
# Authenticate with GHCR
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
cd worldview-be
git checkout develop
git fetch origin develop
git reset --hard origin/develop
git pull origin develop
docker compose pull
rollout-deploy-1:
needs: deploy
runs-on: ubuntu-latest
env:
CONTAINER: 'worldview-be1'
steps:
- name: SSH and Redeploy Staging
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
envs: CONTAINER
script: |
## Update each backend service one by one
## First Deployment
export CONTAINER="${CONTAINER}"
cd worldview-be
docker compose rm -fs $CONTAINER
docker compose up --force-recreate -d $CONTAINER
# Wait for $CONTAINER to be healthy (timeout after 5 minutes)
echo "Waiting for $CONTAINER to become healthy..."
if ! timeout 300 bash -c 'until [ "$(docker inspect --format="{{json .State.Health.Status}}" $CONTAINER)" == "\"healthy\"" ]; do echo "Waiting for $CONTAINER to be healthy..."; sleep 5; done'; then
echo "Timeout waiting for $CONTAINER to become healthy"
echo "Container logs:"
docker logs $CONTAINER
exit 1
fi
# Check if $CONTAINER is healthy
if [ "$(docker inspect --format='{{json .State.Health.Status}}' $CONTAINER)" != "\"healthy\"" ]; then
echo "$CONTAINER is not healthy, stopping deployment"
echo "Container logs:"
docker logs $CONTAINER
exit 1
fi
echo "First deployment phase completed successfully"
rollout-deploy-2:
needs: rollout-deploy-1
runs-on: ubuntu-latest
env:
CONTAINER: 'worldview-be2'
steps:
- name: SSH and Redeploy Staging
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
envs: CONTAINER
script: |
## Update each backend service one by one
## Second Deployment
export CONTAINER="${CONTAINER}"
cd worldview-be
docker compose rm -fs $CONTAINER
docker compose up --force-recreate -d $CONTAINER
# Wait for $CONTAINER to be healthy (timeout after 5 minutes)
echo "Waiting for $CONTAINER to become healthy..."
if ! timeout 300 bash -c 'until [ "$(docker inspect --format="{{json .State.Health.Status}}" $CONTAINER)" == "\"healthy\"" ]; do echo "Waiting for $CONTAINER to be healthy..."; sleep 5; done'; then
echo "Timeout waiting for $CONTAINER to become healthy"
echo "Container logs:"
docker logs $CONTAINER
exit 1
fi
# Check if $CONTAINER is healthy
if [ "$(docker inspect --format='{{json .State.Health.Status}}' $CONTAINER)" != "\"healthy\"" ]; then
echo "$CONTAINER is not healthy, stopping deployment"
echo "Container logs:"
docker logs $CONTAINER
exit 1
fi
echo "Second deployment phase completed successfully"