All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m10s
68 lines
2.0 KiB
YAML
68 lines
2.0 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Determine Image Tag
|
|
id: tag
|
|
run: |
|
|
# Prüfe ob es ein Git Tag ist
|
|
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
|
# Verwende den Tag-Namen (z.B. v1.0.0)
|
|
TAG="${{ github.ref_name }}"
|
|
elif [[ "${{ github.ref_name }}" == "main" ]]; then
|
|
# Für main Branch: verwende 'latest'
|
|
TAG="latest"
|
|
else
|
|
# Für andere Branches: verwende Branch-Name + kurzen Commit-SHA
|
|
TAG="${{ github.ref_name }}-${{ github.sha }}"
|
|
TAG="${TAG:0:50}" # Limit auf 50 Zeichen
|
|
fi
|
|
echo "IMAGE_TAG=${TAG}" >> $GITHUB_OUTPUT
|
|
echo "📦 Image Tag: ${TAG}"
|
|
|
|
- name: Create .env file from secrets and variables
|
|
run: |
|
|
cd docker
|
|
cat > .env << EOF
|
|
REGISTRY_URL=${{ vars.REGISTRY_URL }}
|
|
NAMESPACE=${{ vars.NAMESPACE }}
|
|
REPO_NAME=${{ vars.REPO_NAME }}
|
|
IMAGE_TAG=${{ steps.tag.outputs.IMAGE_TAG }}
|
|
CI_GITEA_USER=${{ secrets.CI_GITEA_USER }}
|
|
CI_GITEA_TOKEN=${{ secrets.CI_GITEA_TOKEN }}
|
|
EOF
|
|
echo "✅ .env file created with IMAGE_TAG=${{ steps.tag.outputs.IMAGE_TAG }}"
|
|
|
|
- name: Build Docker Image
|
|
run: |
|
|
cd docker
|
|
chmod +x build.sh
|
|
./build.sh
|
|
|
|
- name: Push Docker Image to Registry
|
|
run: |
|
|
cd docker
|
|
chmod +x push.sh
|
|
./push.sh
|
|
|
|
- name: Summary
|
|
run: |
|
|
echo "🎉 Build and Push completed successfully!"
|
|
echo "📦 Image: ${{ vars.REGISTRY_URL }}/${{ vars.NAMESPACE }}/${{ vars.REPO_NAME }}:${{ steps.tag.outputs.IMAGE_TAG }}"
|