-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (80 loc) · 3.39 KB
/
Copy pathdocker.yml
File metadata and controls
91 lines (80 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Docker Image CI
on:
push:
release:
types: [published]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract metadata
id: meta
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
else
TAG=${GITHUB_REF#refs/heads/}
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
# Mirror what publish_to_pypi.yaml does so the docker image and the
# PyPI wheel never disagree about their own version. The version lives in a
# single source file (src/vfbquery/_version.py); setup.py reads it at build
# time and __init__.py imports it, so only _version.py is bumped here.
- name: Sync version to tag
id: version
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
echo "Tag build detected: syncing __version__ to $VERSION"
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$VERSION\"/" src/vfbquery/_version.py
else
VERSION=$(grep '^__version__' src/vfbquery/_version.py | sed 's/.*"\(.*\)".*/\1/')
echo "Branch / dev build: using committed version $VERSION"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo " _version.py: $(grep ^__version__ src/vfbquery/_version.py)"
- name: Build test Docker image
run: docker build --no-cache . --file Dockerfile --tag test-image
- name: Test container startup
run: |
docker run -d --name test-container -p 8080:8080 test-image
sleep 10
if docker ps | grep -q test-container; then
echo "Container is running successfully"
curl -sf http://localhost:8080/health || { echo "Health check failed"; docker logs test-container; exit 1; }
echo "Health check passed"
else
echo "Container failed to start"
docker logs test-container
exit 1
fi
docker stop test-container || true
docker rm test-container
# Belt-and-braces: catch any future drift between the workflow
# sync step and what actually ends up inside the image. If the
# built image reports a version different from what we asked for,
# refuse to push it.
- name: Verify image reports expected version
run: |
EXPECTED="${{ steps.version.outputs.version }}"
ACTUAL=$(docker run --rm --entrypoint python test-image -c "from importlib.metadata import version; print(version('vfbquery'))" 2>/dev/null | tr -d '[:space:]')
echo "Expected vfbquery version: $EXPECTED"
echo "Image reports vfbquery : $ACTUAL"
if [[ "$EXPECTED" != "$ACTUAL" ]]; then
echo "ERROR: image version $ACTUAL does not match expected $EXPECTED"
echo " (see solr_result_cache.py:251-258 — mismatches the wheel and"
echo " cached package_version so cache invalidation silently breaks)"
exit 1
fi
- name: Build Docker image
run: docker build . --file Dockerfile --tag virtualflybrain/vfbquery:${{ steps.meta.outputs.tag }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Push Docker image
run: docker push virtualflybrain/vfbquery:${{ steps.meta.outputs.tag }}