Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 1m23s
Remove docker/setup-buildx-action step which requires special Docker daemon configuration. Use plain docker build commands instead for better compatibility with Gitea Actions runner. This simplifies the workflow and works with the standard catthehacker/ubuntu:act-latest images that have Docker CLI pre-installed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
2.5 KiB
YAML
75 lines
2.5 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Determine image tags
|
|
id: tags
|
|
run: |
|
|
REGISTRY="10.0.1.10"
|
|
REPO_OWNER="${{ gitea.repository_owner }}"
|
|
REPO_NAME="${{ gitea.repository }}"
|
|
|
|
# Extract repository name without owner
|
|
REPO_NAME_ONLY=$(echo "$REPO_NAME" | cut -d'/' -f2)
|
|
|
|
# Base image path
|
|
IMAGE_BASE="${REGISTRY}/${REPO_OWNER}/${REPO_NAME_ONLY}"
|
|
|
|
# Determine tag based on ref
|
|
if [[ "${{ gitea.ref }}" == refs/tags/* ]]; then
|
|
# Tag push - use the tag name
|
|
TAG_NAME="${{ gitea.ref_name }}"
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:${TAG_NAME}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=true" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ gitea.ref_name }}" == "main" ]]; then
|
|
# Main branch - use commit SHA and latest
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:${{ gitea.sha_short }}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=true" >> $GITHUB_OUTPUT
|
|
else
|
|
# Other branches - use branch name
|
|
BRANCH_TAG=$(echo "${{ gitea.ref_name }}" | sed 's/\//-/g')
|
|
echo "IMAGE_TAG=${IMAGE_BASE}:${BRANCH_TAG}" >> $GITHUB_OUTPUT
|
|
echo "PUSH_LATEST=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
echo "IMAGE_LATEST=${IMAGE_BASE}:latest" >> $GITHUB_OUTPUT
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
run: |
|
|
echo "${{ secrets.PERSONAL_TOKEN }}" | docker login 10.0.1.10 -u "${{ gitea.actor }}" --password-stdin
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
echo "Building Docker image..."
|
|
if [[ "${{ steps.tags.outputs.PUSH_LATEST }}" == "true" ]]; then
|
|
docker build -t ${{ steps.tags.outputs.IMAGE_TAG }} -t ${{ steps.tags.outputs.IMAGE_LATEST }} .
|
|
else
|
|
docker build -t ${{ steps.tags.outputs.IMAGE_TAG }} .
|
|
fi
|
|
|
|
- name: Push Docker image
|
|
run: |
|
|
echo "Pushing Docker image to registry..."
|
|
docker push ${{ steps.tags.outputs.IMAGE_TAG }}
|
|
|
|
if [[ "${{ steps.tags.outputs.PUSH_LATEST }}" == "true" ]]; then
|
|
echo "Pushing latest tag..."
|
|
docker push ${{ steps.tags.outputs.IMAGE_LATEST }}
|
|
fi
|
|
|
|
echo "Build and push completed successfully!"
|
|
echo "Image available at ${{ steps.tags.outputs.IMAGE_TAG }}"
|