Files
pyxray/.github/workflows/docker-build.yml
T
chuan 674c65c7f3
Docker Build / docker-build (push) Failing after 14s
ci: limit ubuntu edition
2026-05-27 10:19:47 +08:00

86 lines
2.3 KiB
YAML

name: Docker Build
on:
push:
branches:
- "**"
tags:
- "v*"
paths:
- ".github/workflows/**"
workflow_dispatch:
env:
REGISTRY: docker.pchuan.top
IMAGE_NAME: pyxray
APT_MIRROR: https://mirrors.ustc.edu.cn/debian
UV_INDEX_URL: https://pypi.mirrors.ustc.edu.cn/simple/
jobs:
docker-build:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Read project version
id: version
shell: bash
run: |
version="$(python - <<'PY'
import tomllib
with open("pyproject.toml", "rb") as f:
print(tomllib.load(f)["project"]["version"])
PY
)"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "image=${REGISTRY}/${IMAGE_NAME}" >> "$GITHUB_OUTPUT"
- name: Validate git tag version
if: startsWith(github.ref, 'refs/tags/')
shell: bash
env:
PROJECT_VERSION: ${{ steps.version.outputs.version }}
run: |
tag="${GITHUB_REF_NAME}"
expected="v${PROJECT_VERSION}"
if [ "$tag" != "$expected" ]; then
echo "Git tag '${tag}' does not match pyproject.toml version '${PROJECT_VERSION}'. Expected '${expected}'."
exit 1
fi
- name: Build Docker image
shell: bash
env:
IMAGE: ${{ steps.version.outputs.image }}
VERSION: ${{ steps.version.outputs.version }}
run: |
docker build \
--build-arg "APT_MIRROR=${APT_MIRROR}" \
--build-arg "UV_INDEX_URL=${UV_INDEX_URL}" \
-t "${IMAGE}:latest" \
-t "${IMAGE}:${VERSION}" \
.
- name: Login Docker registry
if: startsWith(github.ref, 'refs/tags/')
shell: bash
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${REGISTRY}" \
-u "${{ secrets.REGISTRY_USERNAME }}" \
--password-stdin
- name: Push Docker image
if: startsWith(github.ref, 'refs/tags/')
shell: bash
env:
IMAGE: ${{ steps.version.outputs.image }}
VERSION: ${{ steps.version.outputs.version }}
run: |
docker push "${IMAGE}:latest"
docker push "${IMAGE}:${VERSION}"