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 31 additions and 12 deletions

No files matched your search

+30 -11
View File
@@ -72,9 +72,9 @@ on:
type: string type: string
jobs: jobs:
# ============================================================================ # =============================================================================
# JOB 1: PREPARE - AUTO-DETECT FRAMEWORK AND SETTINGS # JOB 1: PREPARE - AUTO-DETECT FRAMEWORK AND SETTINGS
# ============================================================================ # =============================================================================
prepare: prepare:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
outputs: outputs:
@@ -126,17 +126,17 @@ jobs:
BUILD_CMD="" BUILD_CMD=""
START_CMD="" START_CMD=""
if [ -f "package.json" ]; then if [ -f "package.json" ]; then
BUILD_CMD=$(grep -o '"build": "[^"]*"' package.json | sed 's/"build": "\(.*\)"/\1/' || echo "") BUILD_CMD=$(grep -o '"build": "[^"]*"' package.json | sed 's/"build": "\(.*\)"//' || echo "")
START_CMD=$(grep -o '"start": "[^"]*"' package.json | sed 's/"start": "\(.*\)"/\1/' || echo "") START_CMD=$(grep -o '"start": "[^"]*"' package.json | sed 's/"start": "\(.*\)"//' || echo "")
fi fi
echo "✓ Detected build command: ${BUILD_CMD}" echo "✓ Detected build command: ${BUILD_CMD}"
echo "✓ Detected start command: ${START_CMD}" echo "✓ Detected start command: ${START_CMD}"
echo "BUILD_COMMAND=${BUILD_CMD}" >> $GITEA_OUTPUT echo "BUILD_COMMAND=${BUILD_CMD}" >> $GITEA_OUTPUT
echo "START_COMMAND=${START_CMD}" >> $GITEA_OUTPUT echo "START_COMMAND=${START_CMD}" >> $GITEA_OUTPUT
# ============================================================================ # =============================================================================
# JOB 2: GENERATE DOCKERFILE # JOB 2: GENERATE DOCKERFILE
# ============================================================================ # =============================================================================
generate-dockerfile: generate-dockerfile:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: prepare needs: prepare
@@ -160,9 +160,9 @@ jobs:
# For now, we assume a Dockerfile exists in the calling repo. # For now, we assume a Dockerfile exists in the calling repo.
echo "dockerfile_path=./Dockerfile" >> $GITEA_OUTPUT echo "dockerfile_path=./Dockerfile" >> $GITEA_OUTPUT
# ============================================================================ # =============================================================================
# JOB 3: BUILD AND PUSH DOCKER IMAGE # JOB 3: BUILD AND PUSH DOCKER IMAGE
# ============================================================================ # =============================================================================
build: build:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: [prepare, generate-dockerfile] needs: [prepare, generate-dockerfile]
@@ -218,9 +218,9 @@ jobs:
secrets: | secrets: |
env=${{ steps.vault.outputs.DOTENV_CONTENTS }} env=${{ steps.vault.outputs.DOTENV_CONTENTS }}
# ============================================================================ # =============================================================================
# JOB 4: DEPLOY WITH ANSIBLE # JOB 4: DEPLOY WITH ANSIBLE
# ============================================================================ # =============================================================================
deploy: deploy:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: [prepare, build] # This job runs only after 'prepare' and 'build' jobs succeed. needs: [prepare, build] # This job runs only after 'prepare' and 'build' jobs succeed.
@@ -308,4 +308,23 @@ jobs:
docker_image_full=${{ needs.build.outputs.image_name }}:${{ needs.build.outputs.image_tag }} \ docker_image_full=${{ needs.build.outputs.image_name }}:${{ needs.build.outputs.image_tag }} \
docker_registry=${{ secrets.DOCKER_REGISTRY }} \ docker_registry=${{ secrets.DOCKER_REGISTRY }} \
$auth_method_var" \ $auth_method_var" \
--vault-password-file .vault_pass --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_PASSWORD: ${{ secrets.VAULT_PASSWORD }}
VAULT_ROLE: ${{ vars.VAULT_ROLE }} VAULT_ROLE: ${{ vars.VAULT_ROLE }}
VAULT_ADDR: ${{ vars.VAULT_ADDR || 'https://vault.nguoiduathu.eu.org' }} 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 }}