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:
|
||||
push:
|
||||
branches: [ dev ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
ENV_NAME: dev
|
||||
IMAGE_NAME: csa-backend
|
||||
REGISTRY: ${{ secrets.REGISTRY_URL }}
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: npm
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Create Backend Deployment Files
|
||||
- name: Set image tag
|
||||
run: |
|
||||
mkdir -p backend-tar
|
||||
tar \
|
||||
--exclude=node_modules \
|
||||
--exclude=backend-tar \
|
||||
-czf backend-tar/backend.tar.gz .
|
||||
echo "IMAGE_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
||||
|
||||
- name: Upload To VPS
|
||||
uses: appleboy/scp-action@v0.1.7
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
username: ${{ secrets.VPS_USERNAME }}
|
||||
password: ${{ secrets.VPS_PASSWORD }}
|
||||
port: ${{ secrets.VPS_PORT }}
|
||||
source: "backend-tar/backend.tar.gz"
|
||||
target: "/tmp/"
|
||||
|
||||
- name: Deploy on VPS
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.VPS_HOST }}
|
||||
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"
|
||||
TAR_FILE="/tmp/backend-tar/backend.tar.gz"
|
||||
|
||||
echo "Using uploaded TAR file at $TAR_FILE"
|
||||
|
||||
cd /tmp
|
||||
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
|
||||
- name: Login to registry
|
||||
run: |
|
||||
echo "⏳ Waiting backend to boot..."
|
||||
sleep 10
|
||||
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY \
|
||||
-u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
||||
|
||||
STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://103.14.20.74:3000/api-management/test)
|
||||
echo "HTTP Status: $STATUS"
|
||||
- name: Build and push image
|
||||
run: |
|
||||
docker build -t $REGISTRY/$IMAGE_NAME:$IMAGE_TAG .
|
||||
docker push $REGISTRY/$IMAGE_NAME:$IMAGE_TAG
|
||||
|
||||
if [ "$STATUS" -ne 200 ]; then
|
||||
echo "Deployment failed!"
|
||||
exit 1
|
||||
fi
|
||||
- name: Clone manifest repo
|
||||
run: |
|
||||
git clone https://oauth2:${{ secrets.MANIFEST_REPO_TOKEN }}@${{ secrets.MANIFEST_REPO_URL }} manifest
|
||||
cd manifest
|
||||
git checkout dev
|
||||
|
||||
- name: Update kustomization (DEV)
|
||||
run: |
|
||||
cd manifest/overlays
|
||||
kustomize edit set image $REGISTRY/$IMAGE_NAME=$REGISTRY/$IMAGE_NAME:$IMAGE_TAG
|
||||
|
||||
- name: Commit manifest update
|
||||
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})
|
||||
|
||||
- name: Cleanup workspace
|
||||
run: |
|
||||
rm -rf manifest
|
||||
Loading…
Reference in New Issue