name: CI/CD - ERP Core Monorepo
on:
pull_request:
branches:
- production
types:
- closed
jobs:
backend-build-and-deploy:
name: Build & Deploy ERP Core 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.ERPCORE }}@gitea.hexdive.com/New_REP_SYSTEM/ERP-core.git \
.
- name: Restore backend
run: dotnet restore Backend/ERPCore.sln
- name: Publish backend
run: |
rm -rf /tmp/erpcore-deploy
mkdir -p /tmp/erpcore-deploy
dotnet publish Backend/ERPCore/ERPCore.csproj \
-c Release \
-r linux-x64 \
--self-contained true \
-o /tmp/erpcore-deploy
- name: Stop backend service
run: systemctl stop erpcore.service
- name: Copy backend to deploy folder
run: |
mkdir -p /home/erp/core/publish
rm -rf /home/erp/core/publish/*
cp -r /tmp/erpcore-deploy/* /home/erp/core/publish/
- name: Fix backend ownership and permissions
run: |
chown -R erpuser:erpuser /home/erp/core/publish
find /home/erp/core/publish -type d -exec chmod 755 {} +
find /home/erp/core/publish -type f -exec chmod 644 {} +
chmod +x /home/erp/core/publish/ERPCore
- name: Restart backend service
run: systemctl restart erpcore.service
- name: Verify backend
run: |
systemctl is-active erpcore.service && echo "Backend service running" || echo "Backend service failed"
frontend-build-and-deploy:
name: Build & Deploy ERP Core Frontend
runs-on: linux
needs: backend-build-and-deploy
if: github.event.pull_request.merged == true
steps:
- name: Checkout code
run: |
git clone \
--depth 1 \
--branch Production \
https://oauth2:${{ secrets.ERPCORE }}@gitea.hexdive.com/New_REP_SYSTEM/ERP-core.git \
.
- name: Build frontend Docker image
run: docker build -t erpcore-frontend:latest Frontend/erp-system
- name: Stop & remove existing frontend container
run: |
docker stop erpcore-frontend 2>/dev/null || true
docker rm erpcore-frontend 2>/dev/null || true
- name: Start frontend container
run: |
docker run -d \
--name erpcore-frontend \
-p 6702:6702 \
--add-host=host.docker.internal:host-gateway \
-e BACKEND_ORIGIN=http://host.docker.internal:6701 \
--restart unless-stopped \
--memory="512m" \
--cpus="1.0" \
--cap-drop ALL \
--security-opt no-new-privileges \
erpcore-frontend:latest
- name: Remove old frontend images
run: docker image prune -f
- name: Verify frontend
run: |
docker ps --filter name=erpcore-frontend --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" \
| grep erpcore-frontend && echo "Frontend container running" || echo "Frontend container failed"
This commit is contained in:
@@ -13,41 +13,16 @@ namespace Distribution.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_DeliveryRuns_Routes_FK_RouteId",
|
||||
table: "DeliveryRuns");
|
||||
DropForeignKeyIfExists(migrationBuilder, "DeliveryRuns", "FK_DeliveryRuns_Routes_FK_RouteId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "DeliveryRuns", "FK_DeliveryRuns_Warehouses_FK_SourceWarehouseId");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_DeliveryRuns_Warehouses_FK_SourceWarehouseId",
|
||||
table: "DeliveryRuns");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_DeliveryTasks_Orders_FK_OrderId",
|
||||
table: "DeliveryTasks");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_LoadingSheetItems_LoadingSheets_FK_LoadingSheetId",
|
||||
table: "LoadingSheetItems");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_LoadingSheets_Warehouses_FK_SourceWarehouseId",
|
||||
table: "LoadingSheets");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Payments_Sales_FK_SaleId",
|
||||
table: "Payments");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Payments_Stores_FK_StoreId",
|
||||
table: "Payments");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_SaleReturns_Orders_FK_OrderId",
|
||||
table: "SaleReturns");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_SchemeRedemptions_Orders_FK_OrderId",
|
||||
table: "SchemeRedemptions");
|
||||
DropForeignKeyIfExists(migrationBuilder, "DeliveryTasks", "FK_DeliveryTasks_Orders_FK_OrderId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "LoadingSheetItems", "FK_LoadingSheetItems_LoadingSheets_FK_LoadingSheetId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "LoadingSheets", "FK_LoadingSheets_Warehouses_FK_SourceWarehouseId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "Payments", "FK_Payments_Sales_FK_SaleId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "Payments", "FK_Payments_Stores_FK_StoreId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "SaleReturns", "FK_SaleReturns_Orders_FK_OrderId");
|
||||
DropForeignKeyIfExists(migrationBuilder, "SchemeRedemptions", "FK_SchemeRedemptions_Orders_FK_OrderId");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderItems");
|
||||
@@ -58,57 +33,20 @@ namespace Distribution.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "Sales");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Payments_FK_SaleId",
|
||||
table: "Payments");
|
||||
DropIndexIfExists(migrationBuilder, "Payments", "IX_Payments_FK_SaleId");
|
||||
DropIndexIfExists(migrationBuilder, "LoadingSheets", "IX_LoadingSheets_FK_SourceWarehouseId");
|
||||
DropIndexIfExists(migrationBuilder, "DeliveryRuns", "IX_DeliveryRuns_FK_RouteId");
|
||||
DropIndexIfExists(migrationBuilder, "DeliveryRuns", "IX_DeliveryRuns_FK_SourceWarehouseId");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_LoadingSheets_FK_SourceWarehouseId",
|
||||
table: "LoadingSheets");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_DeliveryRuns_FK_RouteId",
|
||||
table: "DeliveryRuns");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_DeliveryRuns_FK_SourceWarehouseId",
|
||||
table: "DeliveryRuns");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "FK_SaleId",
|
||||
table: "Payments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DispatchConfirmedAt",
|
||||
table: "LoadingSheets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DispatchConfirmedBy",
|
||||
table: "LoadingSheets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "QuantityReceived",
|
||||
table: "LoadingSheetItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "QuantityResolved",
|
||||
table: "LoadingSheetItems");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ActivatedAt",
|
||||
table: "DeliveryRuns");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "FK_RouteId",
|
||||
table: "DeliveryRuns");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "FK_SourceWarehouseId",
|
||||
table: "DeliveryRuns");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "RideType",
|
||||
table: "DeliveryRuns");
|
||||
DropColumnIfExists(migrationBuilder, "Payments", "FK_SaleId");
|
||||
DropColumnIfExists(migrationBuilder, "LoadingSheets", "DispatchConfirmedAt");
|
||||
DropColumnIfExists(migrationBuilder, "LoadingSheets", "DispatchConfirmedBy");
|
||||
DropColumnIfExists(migrationBuilder, "LoadingSheetItems", "QuantityReceived");
|
||||
DropColumnIfExists(migrationBuilder, "LoadingSheetItems", "QuantityResolved");
|
||||
DropColumnIfExists(migrationBuilder, "DeliveryRuns", "ActivatedAt");
|
||||
DropColumnIfExists(migrationBuilder, "DeliveryRuns", "FK_RouteId");
|
||||
DropColumnIfExists(migrationBuilder, "DeliveryRuns", "FK_SourceWarehouseId");
|
||||
DropColumnIfExists(migrationBuilder, "DeliveryRuns", "RideType");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "FK_OrderId",
|
||||
@@ -957,5 +895,66 @@ namespace Distribution.Migrations
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
}
|
||||
|
||||
private static void DropForeignKeyIfExists(MigrationBuilder migrationBuilder, string tableName, string constraintName)
|
||||
{
|
||||
migrationBuilder.Sql($"""
|
||||
SET @sql = IF(
|
||||
EXISTS(
|
||||
SELECT 1
|
||||
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
|
||||
WHERE CONSTRAINT_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = '{tableName}'
|
||||
AND CONSTRAINT_NAME = '{constraintName}'
|
||||
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
|
||||
),
|
||||
'ALTER TABLE `{tableName}` DROP FOREIGN KEY `{constraintName}`',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
""");
|
||||
}
|
||||
|
||||
private static void DropIndexIfExists(MigrationBuilder migrationBuilder, string tableName, string indexName)
|
||||
{
|
||||
migrationBuilder.Sql($"""
|
||||
SET @sql = IF(
|
||||
EXISTS(
|
||||
SELECT 1
|
||||
FROM INFORMATION_SCHEMA.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = '{tableName}'
|
||||
AND INDEX_NAME = '{indexName}'
|
||||
),
|
||||
'DROP INDEX `{indexName}` ON `{tableName}`',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
""");
|
||||
}
|
||||
|
||||
private static void DropColumnIfExists(MigrationBuilder migrationBuilder, string tableName, string columnName)
|
||||
{
|
||||
migrationBuilder.Sql($"""
|
||||
SET @sql = IF(
|
||||
EXISTS(
|
||||
SELECT 1
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = '{tableName}'
|
||||
AND COLUMN_NAME = '{columnName}'
|
||||
),
|
||||
'ALTER TABLE `{tableName}` DROP COLUMN `{columnName}`',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
""");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user