85 lines
2.3 KiB
YAML
85 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="$(awk -F '"' '/^version = / { print $2; exit }' pyproject.toml)"
|
|
|
|
if [ -z "$version" ]; then
|
|
echo "Failed to read project.version from pyproject.toml."
|
|
exit 1
|
|
fi
|
|
|
|
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}"
|