Skip to content

Commit 261fc54

Browse files
fix(ci): wait for PyPI simple index before Docker build (#218)
* fix(ci): wait for PyPI simple index before Docker build JSON API readiness is not enough for pip inside the image build; also verify simple-index listing and wheel URL reachability, and retry pip install in the Dockerfile when CDN edges lag (#217). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(ci): wrap long yamllint line in Docker PyPI wait Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent dfc11aa commit 261fc54

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

.github/workflows/publish-docker.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,42 @@ jobs:
5454
echo "minor=$MINOR"
5555
} >> "$GITHUB_OUTPUT"
5656
57+
# JSON API can return 200 before the simple index / CDN edges that pip
58+
# hits inside the Docker build. Require JSON + simple-index listing +
59+
# a reachable wheel URL before building (see #217).
5760
- name: Wait for PyPI package
5861
env:
5962
VERSION: ${{ steps.version.outputs.version }}
6063
PACKAGE: create-awesome-python-app
6164
run: |
6265
set -euo pipefail
63-
attempts=24
66+
attempts=36
6467
delay=15
68+
normalized="${PACKAGE//-/_}"
6569
for attempt in $(seq 1 "$attempts"); do
70+
json_ok=0
71+
simple_ok=0
72+
wheel_ok=0
6673
if curl -sfL "https://pypi.org/pypi/${PACKAGE}/${VERSION}/json" \
6774
| jq -e '.urls[] | select(.packagetype=="sdist") | .digests.sha256' >/dev/null; then
68-
echo "PyPI has ${PACKAGE}==${VERSION}"
75+
json_ok=1
76+
fi
77+
if curl -sfL "https://pypi.org/simple/${PACKAGE}/" \
78+
| grep -Fq "${normalized}-${VERSION}"; then
79+
simple_ok=1
80+
fi
81+
wheel_url="$(curl -sfL "https://pypi.org/pypi/${PACKAGE}/${VERSION}/json" \
82+
| jq -r '.urls[] | select(.packagetype=="bdist_wheel") | .url' \
83+
| head -n1 || true)"
84+
if [ -n "${wheel_url}" ] && curl -sfI "$wheel_url" >/dev/null; then
85+
wheel_ok=1
86+
fi
87+
if [ "$json_ok" -eq 1 ] && [ "$simple_ok" -eq 1 ] && [ "$wheel_ok" -eq 1 ]; then
88+
echo "PyPI ready for ${PACKAGE}==${VERSION} (json+simple+wheel)"
6989
exit 0
7090
fi
71-
echo "::warning::PyPI not ready for ${PACKAGE}==${VERSION} (attempt ${attempt}/${attempts}); retrying in ${delay}s"
91+
echo "::warning::PyPI not ready for ${PACKAGE}==${VERSION}"
92+
echo "::warning::json=${json_ok} simple=${simple_ok} wheel=${wheel_ok} attempt=${attempt}/${attempts}; sleep ${delay}s"
7293
sleep "$delay"
7394
done
7495
echo "::error::Timed out waiting for ${PACKAGE}==${VERSION} on PyPI"

Dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ FROM python:3.12-slim-bookworm
66
# reproducible for its tag).
77
ARG VERSION=latest
88

9+
# Retry pip install: PyPI simple-index / CDN edges can lag the JSON API
10+
# that CI already observed as ready (see #217).
911
# hadolint ignore=DL3013
1012
RUN useradd --create-home --uid 1000 --shell /bin/bash app \
1113
&& if [ "$VERSION" = "latest" ]; then \
12-
pip install --no-cache-dir create-awesome-python-app; \
14+
pkg="create-awesome-python-app"; \
1315
else \
14-
pip install --no-cache-dir "create-awesome-python-app==${VERSION}"; \
15-
fi
16+
pkg="create-awesome-python-app==${VERSION}"; \
17+
fi \
18+
&& attempt=1 \
19+
&& until pip install --no-cache-dir "$pkg"; do \
20+
if [ "$attempt" -ge 12 ]; then exit 1; fi; \
21+
echo "pip install failed (attempt ${attempt}/12); retrying in 15s"; \
22+
attempt=$((attempt + 1)); \
23+
sleep 15; \
24+
done
1625

1726
USER app
1827
WORKDIR /home/app

0 commit comments

Comments
 (0)