86 lines
3.1 KiB
YAML
86 lines
3.1 KiB
YAML
name: CI/CD - ERP Distribution
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- production
|
|
types:
|
|
- closed
|
|
jobs:
|
|
build-and-deploy-backend:
|
|
name: Build & Deploy Backend
|
|
runs-on: linux
|
|
if: github.event.pull_request.merged == true
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
git clone \
|
|
--depth 1 \
|
|
--branch production \
|
|
https://oauth2:${{ secrets.DISTRIBUTION }}@gitea.hexdive.com/New_REP_SYSTEM/ERP_Distribution.git \
|
|
.
|
|
- name: Restore
|
|
run: dotnet restore Distribution/Distribution.csproj
|
|
- name: Publish
|
|
run: |
|
|
rm -rf /tmp/erpdistribution-deploy
|
|
mkdir -p /tmp/erpdistribution-deploy
|
|
dotnet publish Distribution/Distribution.csproj \
|
|
-c Release \
|
|
-r linux-x64 \
|
|
--self-contained true \
|
|
-o /tmp/erpdistribution-deploy
|
|
- name: Stop service
|
|
run: systemctl stop erpdistribution.service
|
|
- name: Copy to deploy folder
|
|
run: |
|
|
mkdir -p /home/distribution/core/publish
|
|
rm -rf /home/distribution/core/publish/*
|
|
cp -r /tmp/erpdistribution-deploy/* /home/distribution/core/publish/
|
|
- name: Fix ownership and permissions
|
|
run: |
|
|
chown -R distributionuser:distributionuser /home/distribution/core/publish
|
|
find /home/distribution/core/publish -type d -exec chmod 755 {} +
|
|
find /home/distribution/core/publish -type f -exec chmod 644 {} +
|
|
chmod +x /home/distribution/core/publish/Distribution
|
|
- name: Restart service
|
|
run: systemctl restart erpdistribution.service
|
|
- name: Verify
|
|
run: |
|
|
systemctl is-active erpdistribution.service && echo "✅ Service running" || echo "❌ Service failed"
|
|
|
|
build-and-deploy-frontend:
|
|
name: Build & Deploy Frontend
|
|
runs-on: linux
|
|
if: github.event.pull_request.merged == true
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
git clone \
|
|
--depth 1 \
|
|
--branch production \
|
|
https://oauth2:${{ secrets.DISTRIBUTION }}@gitea.hexdive.com/New_REP_SYSTEM/ERP_Distribution.git \
|
|
.
|
|
- name: Build Docker image
|
|
run: docker build -t erpdistributionfe:latest ./distribution_fe
|
|
- name: Stop & remove existing container
|
|
run: |
|
|
docker stop erpdistributionfe 2>/dev/null || true
|
|
docker rm erpdistributionfe 2>/dev/null || true
|
|
- name: Start container
|
|
run: |
|
|
docker run -d \
|
|
--name erpdistributionfe \
|
|
-p 8801:3000 \
|
|
--restart unless-stopped \
|
|
--memory="512m" \
|
|
--cpus="1.0" \
|
|
--cap-drop ALL \
|
|
--security-opt no-new-privileges \
|
|
erpdistributionfe:latest
|
|
- name: Remove old images
|
|
run: docker image prune -f
|
|
- name: Verify
|
|
run: |
|
|
docker ps --filter name=erpdistributionfe --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" \
|
|
| grep erpdistributionfe && echo "✅ Container running" || echo "❌ Container failed"
|