This commit is contained in:
Chu Văn Hải committed 2025-12-08 17:46:35 +07:00
1 parent 6eb82fc05b
commit f7f5b534a8
1 file changed
+29 -10
+29 -10
View File
@@ -72,9 +72,9 @@ on:
type: string
jobs:
# ============================================================================
# =============================================================================
# JOB 1: PREPARE - AUTO-DETECT FRAMEWORK AND SETTINGS
# ============================================================================
# =============================================================================
prepare:
runs-on: ubuntu-22.04
outputs:
@@ -126,17 +126,17 @@ jobs:
BUILD_CMD=""
START_CMD=""
if [ -f "package.json" ]; then
BUILD_CMD=$(grep -o '"build": "[^"]*"' package.json | sed 's/"build": "\(.*\)"/\1/' || echo "")
START_CMD=$(grep -o '"start": "[^"]*"' package.json | sed 's/"start": "\(.*\)"/\1/' || echo "")
BUILD_CMD=$(grep -o '"build": "[^"]*"' package.json | sed 's/"build": "\(.*\)"//' || echo "")
START_CMD=$(grep -o '"start": "[^"]*"' package.json | sed 's/"start": "\(.*\)"//' || echo "")
fi
echo "✓ Detected build command: ${BUILD_CMD}"
echo "✓ Detected start command: ${START_CMD}"
echo "BUILD_COMMAND=${BUILD_CMD}" >> $GITEA_OUTPUT
echo "START_COMMAND=${START_CMD}" >> $GITEA_OUTPUT
# ============================================================================
# =============================================================================
# JOB 2: GENERATE DOCKERFILE
# ============================================================================
# =============================================================================
generate-dockerfile:
runs-on: ubuntu-22.04
needs: prepare
@@ -160,9 +160,9 @@ jobs:
# For now, we assume a Dockerfile exists in the calling repo.
echo "dockerfile_path=./Dockerfile" >> $GITEA_OUTPUT
# ============================================================================
# =============================================================================
# JOB 3: BUILD AND PUSH DOCKER IMAGE
# ============================================================================
# =============================================================================
build:
runs-on: ubuntu-22.04
needs: [prepare, generate-dockerfile]
@@ -218,9 +218,9 @@ jobs:
secrets: |
env=${{ steps.vault.outputs.DOTENV_CONTENTS }}
# ============================================================================
# =============================================================================
# JOB 4: DEPLOY WITH ANSIBLE
# ============================================================================
# =============================================================================
deploy:
runs-on: ubuntu-22.04
needs: [prepare, build] # This job runs only after 'prepare' and 'build' jobs succeed.
@@ -309,3 +309,22 @@ jobs:
docker_registry=${{ secrets.DOCKER_REGISTRY }} \
$auth_method_var" \
--vault-password-file .vault_pass
cleanup:
name: Cleanup old images
runs-on: ubuntu-22.04
needs: deploy
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Clean up old Docker images and cache
run: |
echo "🧹 Cleaning up old Docker images and build cache..."
# Prune images older than 7 days (168 hours)
docker image prune -af --filter "until=168h" || echo "Docker image prune failed, continuing."
# Prune buildx cache
docker buildx prune -af --filter "until=168h" || echo "Docker buildx prune failed, continuing."
echo "✅ Cleanup finished."