lcc_tool/.gitea/workflows/build.yml

71 lines
No EOL
1.9 KiB
YAML

name: Build and Push Docker Image
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set image name and tags
id: meta
run: |
REPO_OWNER="${{ gitea.repository_owner }}"
REPO_NAME="lcc"
BRANCH_NAME="${{ gitea.ref_name }}"
SHA_SHORT="${{ gitea.sha }}"
SHA_SHORT=${SHA_SHORT:0:7}
IMAGE_BASE="git.avatic.de/${REPO_OWNER}/${REPO_NAME}"
# Basis-Tags
TAGS="${IMAGE_BASE}:${BRANCH_NAME}"
TAGS="${TAGS},${IMAGE_BASE}:${BRANCH_NAME}-${SHA_SHORT}"
# Latest tag nur für main branch
if [ "${{ gitea.ref_name }}" = "main" ]; then
TAGS="${TAGS},${IMAGE_BASE}:latest"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "image_base=${IMAGE_BASE}" >> $GITHUB_OUTPUT
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.avatic.de -u "${{ gitea.actor }}" --password-stdin
- name: Build Docker image
run: |
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.meta.outputs.tags }}"
# Build mit dem ersten Tag
docker build -t "${TAG_ARRAY[0]}" .
# Füge weitere Tags hinzu
for tag in "${TAG_ARRAY[@]:1}"; do
docker tag "${TAG_ARRAY[0]}" "$tag"
done
- name: Push Docker images
run: |
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.meta.outputs.tags }}"
# Push alle Tags
for tag in "${TAG_ARRAY[@]}"; do
echo "Pushing $tag"
docker push "$tag"
done
- name: Logout from registry
if: always()
run: docker logout git.avatic.de