Compare commits

..
2 Commits
Author SHA1 Message Date
Chu Văn Hải d333ec2988 up 2025-12-08 17:50:09 +07:00
Chu Văn Hải f7f5b534a8 up 2025-12-08 17:46:35 +07:00
2 changed files with 30 additions and 11 deletions

No files matched your search

+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."
+1 -1
View File
@@ -35,4 +35,4 @@ jobs:
VAULT_PASSWORD: ${{ secrets.VAULT_PASSWORD }}
VAULT_ROLE: ${{ vars.VAULT_ROLE }}
VAULT_ADDR: ${{ vars.VAULT_ADDR || 'https://vault.nguoiduathu.eu.org' }}
DOCKER_REGISTRY: ${{ vars.DOCKER_REGISTRY || gitea.instance }}
DOCKER_REGISTRY: ${{ vars.DOCKER_REGISTRY || github.server_url }}