Add optimized Gitea CI/CD workflows for Docker builds
Some checks failed
Auto Build and Push Docker Image / build (push) Failing after 1m17s
Some checks failed
Auto Build and Push Docker Image / build (push) Failing after 1m17s
Features: - docker-autobuild.yaml: Automated builds on push to main/master - Path ignores for markdown/docs files - Docker Buildx with caching support - Automatic cleanup after builds - docker-build.yaml: Manual builds with flexible options - Custom version tags - Additional tags support (e.g., stable,production) - Toggle latest tag - Docker Buildx with layer caching Both workflows: - Use registry credentials from Gitea secrets - Support local registry at 192.168.88.201:5000 - Proper login/logout handling - Optimized for sticker-bot project
This commit is contained in:
63
.gitea/workflows/docker-autobuild.yaml
Normal file
63
.gitea/workflows/docker-autobuild.yaml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
name: Auto Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
- '.gitignore'
|
||||||
|
- 'data/**'
|
||||||
|
- '.env.example'
|
||||||
|
|
||||||
|
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 }}"
|
||||||
|
|
||||||
|
# Versionierung: v{run_number}-autobuild
|
||||||
|
VERSION="v${{ gitea.run_number }}-autobuild"
|
||||||
|
FULL_IMAGE_PATH="$REGISTRY/$IMAGE_NAME"
|
||||||
|
|
||||||
|
echo "========================================"
|
||||||
|
echo "Building Docker Image"
|
||||||
|
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:latest \
|
||||||
|
-t $FULL_IMAGE_PATH:$VERSION \
|
||||||
|
.
|
||||||
|
|
||||||
|
# Push images
|
||||||
|
docker push $FULL_IMAGE_PATH:latest
|
||||||
|
docker push $FULL_IMAGE_PATH:$VERSION
|
||||||
|
|
||||||
|
echo "✅ Successfully built and pushed:"
|
||||||
|
echo " - $FULL_IMAGE_PATH:latest"
|
||||||
|
echo " - $FULL_IMAGE_PATH:$VERSION"
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
docker logout 192.168.88.201:5000 || true
|
||||||
|
docker system prune -f || true
|
||||||
90
.gitea/workflows/docker-build.yaml
Normal file
90
.gitea/workflows/docker-build.yaml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
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
|
||||||
Reference in New Issue
Block a user