diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index b82162a..1faed35 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -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. @@ -308,4 +308,23 @@ jobs: docker_image_full=${{ needs.build.outputs.image_name }}:${{ needs.build.outputs.image_tag }} \ docker_registry=${{ secrets.DOCKER_REGISTRY }} \ $auth_method_var" \ - --vault-password-file .vault_pass \ No newline at end of file + --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."