update(ci): add latest workflowfile for dev
This commit is contained in:
parent
41fc40ac0f
commit
e4e613763b
|
|
@ -1,105 +1,56 @@
|
||||||
name: Deploy Backend CIFO Superapps
|
name: Deploy Backend Development Environment
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ dev ]
|
branches: [ dev ]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
ENV_NAME: dev
|
||||||
|
IMAGE_NAME: csa-backend
|
||||||
|
REGISTRY: ${{ secrets.REGISTRY_URL }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
build-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Set image tag
|
||||||
uses: actions/setup-node@v4
|
run: |
|
||||||
with:
|
echo "IMAGE_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
||||||
node-version: '20'
|
|
||||||
cache: npm
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Login to registry
|
||||||
run: npm install
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY \
|
||||||
|
-u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||||
|
|
||||||
- name: Create Backend Deployment Files
|
- name: Build and push image
|
||||||
run: |
|
run: |
|
||||||
mkdir -p backend-tar
|
docker build -t $REGISTRY/$IMAGE_NAME:$IMAGE_TAG .
|
||||||
tar \
|
docker push $REGISTRY/$IMAGE_NAME:$IMAGE_TAG
|
||||||
--exclude=node_modules \
|
|
||||||
--exclude=backend-tar \
|
|
||||||
-czf backend-tar/backend.tar.gz .
|
|
||||||
|
|
||||||
- name: Upload To VPS
|
- name: Clone manifest repo
|
||||||
uses: appleboy/scp-action@v0.1.7
|
run: |
|
||||||
with:
|
git clone https://oauth2:${{ secrets.MANIFEST_REPO_TOKEN }}@${{ secrets.MANIFEST_REPO_URL }} manifest
|
||||||
host: ${{ secrets.VPS_HOST }}
|
cd manifest
|
||||||
username: ${{ secrets.VPS_USERNAME }}
|
git checkout dev
|
||||||
password: ${{ secrets.VPS_PASSWORD }}
|
|
||||||
port: ${{ secrets.VPS_PORT }}
|
|
||||||
source: "backend-tar/backend.tar.gz"
|
|
||||||
target: "/tmp/"
|
|
||||||
|
|
||||||
- name: Deploy on VPS
|
- name: Update kustomization (DEV)
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
run: |
|
||||||
with:
|
cd manifest/overlays
|
||||||
host: ${{ secrets.VPS_HOST }}
|
kustomize edit set image $REGISTRY/$IMAGE_NAME=$REGISTRY/$IMAGE_NAME:$IMAGE_TAG
|
||||||
username: ${{ secrets.VPS_USERNAME }}
|
|
||||||
password: ${{ secrets.VPS_PASSWORD }}
|
|
||||||
port: ${{ secrets.VPS_PORT }}
|
|
||||||
script: |
|
|
||||||
set -e
|
|
||||||
echo "🚀 Starting deployment..."
|
|
||||||
|
|
||||||
DEPLOY_DIR="/home/${{ secrets.VPS_USERNAME }}/backend-cifo-superapps"
|
- name: Commit manifest update
|
||||||
TAR_FILE="/tmp/backend-tar/backend.tar.gz"
|
run: |
|
||||||
|
cd manifest
|
||||||
|
git config user.name "csa-ci"
|
||||||
|
git config user.email "ci@gitea.local"
|
||||||
|
git commit -am "deploy(${ENV_NAME}): update backend image to $IMAGE_TAG"
|
||||||
|
git push origin (${ENV_NAME})
|
||||||
|
|
||||||
echo "Using uploaded TAR file at $TAR_FILE"
|
- name: Cleanup workspace
|
||||||
|
run: |
|
||||||
cd /tmp
|
rm -rf manifest
|
||||||
rm -rf backend-temp
|
|
||||||
mkdir backend-temp
|
|
||||||
|
|
||||||
echo "Extracting archive..."
|
|
||||||
tar -xzf $TAR_FILE -C backend-temp
|
|
||||||
|
|
||||||
echo "Cleaning deploy directory safely (preserving .env & .git)..."
|
|
||||||
echo '${{ secrets.VPS_PASSWORD }}' | sudo -S sh -c "
|
|
||||||
cd $DEPLOY_DIR
|
|
||||||
for item in * .*; do
|
|
||||||
if [ \"\$item\" != \".\" ] && [ \"\$item\" != \"..\" ] && [ \"\$item\" != \".env\" ] && [ \"\$item\" != \".git\" ]; then
|
|
||||||
rm -rf \"\$item\"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "Copying new backend..."
|
|
||||||
echo '${{ secrets.VPS_PASSWORD }}' | sudo -S cp -r backend-temp/* "$DEPLOY_DIR"
|
|
||||||
|
|
||||||
echo '${{ secrets.VPS_PASSWORD }}' | sudo -S chown -R ${{ secrets.VPS_USERNAME }}:${{ secrets.VPS_USERNAME }} "$DEPLOY_DIR"
|
|
||||||
|
|
||||||
cd "$DEPLOY_DIR"
|
|
||||||
npm install
|
|
||||||
|
|
||||||
# Prisma CMS
|
|
||||||
npx prisma generate --schema=./prisma/schema.cms.prisma
|
|
||||||
npx prisma migrate deploy --schema=./prisma/schema.cms.prisma
|
|
||||||
|
|
||||||
echo "🔄 Restarting backend service..."
|
|
||||||
echo '${{ secrets.VPS_PASSWORD }}' | sudo systemctl restart cifosuperapps-backend.service
|
|
||||||
|
|
||||||
rm -rf $TAR_FILE
|
|
||||||
rm -rf /tmp/backend-temp
|
|
||||||
|
|
||||||
- name: Healthcheck
|
|
||||||
run: |
|
|
||||||
echo "⏳ Waiting backend to boot..."
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://103.14.20.74:3000/api-management/test)
|
|
||||||
echo "HTTP Status: $STATUS"
|
|
||||||
|
|
||||||
if [ "$STATUS" -ne 200 ]; then
|
|
||||||
echo "Deployment failed!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
Loading…
Reference in New Issue