Files
test_repo/.gitea/workflows/build-and-push.yaml
gitea_admin 652e738681
Some checks failed
Build and Push Container Image / build-and-push (push) Failing after 2s
Update .gitea/workflows/build-and-push.yaml
2026-05-11 07:46:09 +00:00

93 lines
3.0 KiB
YAML

name: Build and Push Container Image
on:
push:
branches:
- main
tags:
- "v*"
jobs:
build-and-push:
runs-on: orchestration-platform
container:
image: docker:27-cli
steps:
- name: Install tools
run: |
apk add --no-cache git
- name: Checkout code
run: |
git clone --depth 1 --branch "${GITHUB_REF_NAME}" "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" .
- name: Check Dockerfile
run: |
test -f Dockerfile || { echo "Dockerfile not found"; exit 1; }
- name: Determine image metadata
id: meta
run: |
REGISTRY_HOST=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||; s|/.*$||')
IMAGE="${REGISTRY_HOST}/${{ gitea.repository }}"
if echo "${{ gitea.ref }}" | grep -q '^refs/tags/'; then
TAG=$(echo "${{ gitea.ref }}" | sed 's|refs/tags/v\?||')
EXTRA_TAG=""
else
TAG="latest"
EXTRA_TAG="main-${{ gitea.sha }}"
fi
echo "registry_host=${REGISTRY_HOST}" >> "$GITHUB_OUTPUT"
echo "image=${IMAGE}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "extra_tag=${EXTRA_TAG}" >> "$GITHUB_OUTPUT"
- name: Login to Gitea registry
run: |
REGISTRY_USERNAME="${{ secrets.REGISTRY_USERNAME }}"
REGISTRY_TOKEN="${{ secrets.REGISTRY_TOKEN }}"
if [ -z "${REGISTRY_USERNAME}" ]; then
REGISTRY_USERNAME="${{ gitea.actor }}"
fi
if [ -z "${REGISTRY_USERNAME}" ]; then
echo "Registry username is missing. Set REGISTRY_USERNAME or run the workflow with a valid Gitea actor."
exit 1
fi
if [ -z "${REGISTRY_TOKEN}" ]; then
echo "Registry token is missing. Set REGISTRY_TOKEN as a repository or organization secret."
exit 1
fi
echo "${REGISTRY_TOKEN}" | docker login \
"${{ steps.meta.outputs.registry_host }}" \
--username "${REGISTRY_USERNAME}" \
--password-stdin
- name: Build image
run: |
docker build \
--label "org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}" \
--label "org.opencontainers.image.revision=${{ gitea.sha }}" \
-t "${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.tag }}" \
.
- name: Add trace tag
if: ${{ steps.meta.outputs.extra_tag != '' }}
run: |
docker tag \
"${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.tag }}" \
"${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.extra_tag }}"
- name: Push image
run: |
docker push "${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.tag }}"
if [ -n "${{ steps.meta.outputs.extra_tag }}" ]; then
docker push "${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.extra_tag }}"
fi