Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ jobs:
type=ref,event=branch
type=ref,event=pr

- name: Select release package version
id: release
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
version="${GITHUB_REF#refs/tags/v}"
if [[ -z "$version" ]]; then
echo "::error::Release tag has no package version"
exit 1
fi
printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT"
fi

- name: Build and push Docker image
id: build
uses: docker/build-push-action@v7
Expand All @@ -66,6 +79,8 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
XRCG_VERSION=${{ steps.release.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: mode=max
Expand Down
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Copy project files (including .git for version detection)
COPY . .

# Build the package
# flit_scm needs git metadata to determine version
# Filtered build contexts look dirty to SCM even at a release tag.
ARG XRCG_VERSION
RUN pip install --no-cache-dir build wheel && \
if [ -n "${XRCG_VERSION}" ]; then \
export SETUPTOOLS_SCM_PRETEND_VERSION="${XRCG_VERSION}"; \
fi && \
python -m build --sdist --wheel --outdir dist

# Runtime stage
Expand All @@ -30,8 +33,17 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Copy built wheels from builder
COPY --from=builder /build/dist /tmp/dist

# Install xrcg package
# Install xrcg and verify explicitly versioned builds before publishing.
ARG XRCG_VERSION
RUN pip install --no-cache-dir /tmp/dist/*.whl && \
if [ -n "${XRCG_VERSION}" ]; then \
python -c "import importlib.metadata as m, subprocess, sys; \
expected = sys.argv[1]; \
actual = m.version('xrcg'); \
cli = subprocess.check_output(['xrcg', '--version'], text=True).strip(); \
print(f'package={actual}; CLI={cli}; expected={expected}'); \
sys.exit(0 if actual == expected and cli == f'xrcg version {expected}' else 'Release version mismatch')" "${XRCG_VERSION}"; \
fi && \
rm -rf /tmp/dist

# Create a non-root user for security
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ function xrcg { docker run --rm -v ${PWD}:/work ghcr.io/xregistry/codegen/xrcg:l

> **Note:** File paths must be relative to your current directory due to Docker volume mapping.

For version-tagged releases, CI passes `XRCG_VERSION` from the tag. The package
build uses that version explicitly, and image construction fails if the installed
package or `xrcg --version` differs. This avoids `.dockerignore` exclusions making
the copied Git checkout appear dirty.

To build a versioned image locally from its release checkout:

```bash
docker build --build-arg XRCG_VERSION=0.11.7 -t xrcg:0.11.7 .
docker run --rm xrcg:0.11.7 --version
```

Leave `XRCG_VERSION` unset for development builds; Git-based version detection
remains unchanged.

### Python Package

Requires Python 3.10+:
Expand Down
Loading