76 lines
1.7 KiB
YAML
76 lines
1.7 KiB
YAML
name: Docker
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
IMAGE_NAME: fsadmin/md-to-html
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Prepare tags
|
|
id: meta
|
|
shell: sh
|
|
run: |
|
|
set -eu
|
|
|
|
if [ -z "${{ vars.REGISTRY }}" ]; then
|
|
echo "::error::Set the REGISTRY repository variable to your Gitea registry host."
|
|
exit 1
|
|
fi
|
|
|
|
image="${{ vars.REGISTRY }}/${IMAGE_NAME}"
|
|
short_sha="$(printf '%s' "${GITHUB_SHA}" | cut -c1-12)"
|
|
|
|
{
|
|
echo "image=${image}"
|
|
echo "tags<<EOF"
|
|
echo "${image}:${short_sha}"
|
|
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
|
|
echo "${image}:latest"
|
|
fi
|
|
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
|
|
echo "${image}:${GITHUB_REF_NAME}"
|
|
fi
|
|
echo "EOF"
|
|
} >> "${GITHUB_OUTPUT}"
|
|
|
|
- name: Login to registry
|
|
run: |
|
|
printf '%s' "${{ secrets.REGISTRY_PASSWORD }}" \
|
|
| docker login "${{ vars.REGISTRY }}" \
|
|
--username "${{ secrets.REGISTRY_USERNAME }}" \
|
|
--password-stdin
|
|
|
|
- name: Build and push image
|
|
env:
|
|
DOCKER_BUILDKIT: "1"
|
|
run: |
|
|
set -eu
|
|
|
|
tags=""
|
|
while IFS= read -r tag; do
|
|
tags="${tags} -t ${tag}"
|
|
done <<'EOF'
|
|
${{ steps.meta.outputs.tags }}
|
|
EOF
|
|
|
|
docker build ${tags} .
|
|
|
|
while IFS= read -r tag; do
|
|
docker push "${tag}"
|
|
done <<'EOF'
|
|
${{ steps.meta.outputs.tags }}
|
|
EOF
|