name: Manual Build and Push Docker Image on: workflow_dispatch: inputs: tag_name: description: 'Version tag (e.g., 1.0.0, v1.0.0). Leave empty for auto-generated v{run_number}.' required: false default: '' additional_tags: description: 'Additional tags (comma-separated, e.g., stable,production)' required: false default: '' push_latest: description: 'Also push as latest?' required: true default: 'true' type: boolean jobs: build: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Docker Registry run: | echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin 192.168.88.201:5000 || true - name: Build and Push Docker Image run: | REGISTRY="192.168.88.201:5000" IMAGE_NAME="${{ gitea.repository }}" FULL_IMAGE_PATH="$REGISTRY/$IMAGE_NAME" # Determine version if [ -z "${{ github.event.inputs.tag_name }}" ]; then VERSION="v${{ gitea.run_number }}" else VERSION="${{ github.event.inputs.tag_name }}" fi echo "========================================" echo "Building Docker Image (Manual)" echo "Registry: $REGISTRY" echo "Image: $IMAGE_NAME" echo "Version: $VERSION" echo "========================================" # Build with cache docker build \ --cache-from $FULL_IMAGE_PATH:latest \ -t $FULL_IMAGE_PATH:$VERSION \ . # Push versioned tag docker push $FULL_IMAGE_PATH:$VERSION echo "✅ Pushed: $FULL_IMAGE_PATH:$VERSION" # Push latest if enabled if [ "${{ github.event.inputs.push_latest }}" = "true" ]; then docker tag $FULL_IMAGE_PATH:$VERSION $FULL_IMAGE_PATH:latest docker push $FULL_IMAGE_PATH:latest echo "✅ Pushed: $FULL_IMAGE_PATH:latest" fi # Push additional tags if [ -n "${{ github.event.inputs.additional_tags }}" ]; then IFS=',' read -ra TAGS <<< "${{ github.event.inputs.additional_tags }}" for tag in "${TAGS[@]}"; do tag=$(echo $tag | xargs) # trim whitespace docker tag $FULL_IMAGE_PATH:$VERSION $FULL_IMAGE_PATH:$tag docker push $FULL_IMAGE_PATH:$tag echo "✅ Pushed: $FULL_IMAGE_PATH:$tag" done fi echo "========================================" echo "Build completed successfully!" echo "========================================" - name: Cleanup if: always() run: | docker logout 192.168.88.201:5000 || true docker system prune -f || true