Files
SPARC/.gitea/workflows/build.yaml
T
0xWheatyz 7b61be1a4a
Build and Push Docker Image / build-and-push (push) Failing after 32s
fix: use sh instead of bash and replace checkout action with git
- Use sh (built into Alpine) instead of bash to avoid install errors
- Replace actions/checkout@v4 with direct git clone commands
- Add ca-certificates for HTTPS support
- Faster and more reliable for lightweight Alpine containers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-06 02:58:28 +00:00

103 lines
3.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: Install dependencies
shell: sh
run: |
apk add --no-cache git wget ca-certificates
- name: Install Kaniko
shell: sh
run: |
wget -O /usr/local/bin/executor https://github.com/GoogleContainerTools/kaniko/releases/download/v1.23.2/executor-linux-amd64
chmod +x /usr/local/bin/executor
- name: Checkout code
shell: sh
run: |
git clone https://gitea.leeworks.dev/${{ gitea.repository }}.git .
git checkout ${{ gitea.sha }}
- name: Determine image tags
id: tags
shell: sh
run: |
REGISTRY="gitea.leeworks.dev"
REPO_OWNER="${{ gitea.repository_owner }}"
REPO_NAME="${{ gitea.repository }}"
# Extract repository name without owner
REPO_NAME_ONLY=$(echo "$REPO_NAME" | cut -d'/' -f2)
# Convert to lowercase for Docker registry compatibility
REPO_OWNER_LOWER=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]')
REPO_NAME_LOWER=$(echo "$REPO_NAME_ONLY" | tr '[:upper:]' '[:lower:]')
# Base image path
IMAGE_BASE="${REGISTRY}/${REPO_OWNER_LOWER}/${REPO_NAME_LOWER}"
# 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 (shortened to 7 chars) and latest
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
echo "IMAGE_TAG=${IMAGE_BASE}:${SHORT_SHA}" >> $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: Setup Kaniko config
shell: sh
run: |
mkdir -p /kaniko/.docker
cat > /kaniko/.docker/config.json <<EOF
{
"auths": {
"gitea.leeworks.dev": {
"auth": "$(echo -n "${{ gitea.actor }}:${{ secrets.PERSONAL_TOKEN }}" | base64)"
}
}
}
EOF
- name: Build and push with Kaniko
shell: sh
run: |
echo "Building and pushing image with Kaniko..."
if [[ "${{ steps.tags.outputs.PUSH_LATEST }}" == "true" ]]; then
/usr/local/bin/executor \
--context=/workspace/${{ gitea.repository }} \
--dockerfile=Dockerfile \
--destination=${{ steps.tags.outputs.IMAGE_TAG }} \
--destination=${{ steps.tags.outputs.IMAGE_LATEST }}
else
/usr/local/bin/executor \
--context=/workspace/${{ gitea.repository }} \
--dockerfile=Dockerfile \
--destination=${{ steps.tags.outputs.IMAGE_TAG }}
fi
echo "Build and push completed successfully!"
echo "Image available at ${{ steps.tags.outputs.IMAGE_TAG }}"