Files

81 lines
2.7 KiB
YAML

# Template action to generate OCI-compliant containers
# Don't forget to change the template variables if any were missed
name: Build and Publish Container
on:
push:
tags:
- 'v*'
jobs:
build-and-push:
runs-on: alpine-latest
steps:
- name: Install Dependencies
shell: sh
run: |
if command -v apk >/dev/null 2>&1; then
apk add --no-cache bash docker-cli docker-cli-buildx git
elif command -v apt-get >/dev/null 2>&1; then
apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq bash docker.io git docker-buildx
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Get full git history
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.TOKEN }}
- name: Normalize release version
id: version
shell: sh
run: |
ORG_REPO="$(printf '%s' "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')"
echo "image_base=${{ secrets.REGISTRY }}/${ORG_REPO}" >> "${GITHUB_OUTPUT}"
TAG="${GITHUB_REF_NAME#v}"
PRERELEASE=""
case "$TAG" in
*-*) PRERELEASE="-${TAG#*-}"; TAG="${TAG%%-*}";;
esac
IFS='.' read -r MAJOR MINOR PATCH <<EOF
$TAG
EOF
MAJOR="${MAJOR:-0}"
MINOR="${MINOR:-0}"
PATCH="${PATCH:-0}"
VERSION="${MAJOR}.${MINOR}.${PATCH}${PRERELEASE}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
- name: Extract metadata (labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.version.outputs.image_base }}
labels: |
org.opencontainers.image.title=Maestro
org.opencontainers.image.vendor=Dcntrlized
org.opencontainers.image.description=Central Dcntrlized service orchestrator
org.opencontainers.image.authors=Admin <[email protected]>
org.opencontainers.image.version=${{ steps.version.outputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ steps.version.outputs.image_base }}:${{ steps.version.outputs.version }}
${{ steps.version.outputs.image_base }}:latest
labels: ${{ steps.meta.outputs.labels }}
build-args: |
IMAGE_VERSION=${{ steps.version.outputs.version }}
IMAGE_REVISION=${{ gitea.sha }}