feat: CI auto-detects and shifts port to avoid production conflicts
This commit is contained in:
parent
4e97366700
commit
24d42ed0b8
@ -102,13 +102,31 @@ jobs:
|
|||||||
docker rm -f newsarchiver-e2e 2>/dev/null || true
|
docker rm -f newsarchiver-e2e 2>/dev/null || true
|
||||||
docker run -d --name newsarchiver-e2e \
|
docker run -d --name newsarchiver-e2e \
|
||||||
--network newsarchiver-network \
|
--network newsarchiver-network \
|
||||||
-p 5000:5000 \
|
-e CI=true \
|
||||||
|
-e CI_PORT_OFFSET=1 \
|
||||||
-e ADMIN_PASSWORD="" \
|
-e ADMIN_PASSWORD="" \
|
||||||
-e ARCHIVE_DIR=/data/archives \
|
-e ARCHIVE_DIR=/data/archives \
|
||||||
-e DISABLE_RSS_FETCH=1 \
|
-e DISABLE_RSS_FETCH=1 \
|
||||||
jarianc/newsarchiverv2:test \
|
jarianc/newsarchiverv2:test \
|
||||||
python run_archiver.py --serve --host 0.0.0.0 --port 5000
|
python run_archiver.py --serve --host 0.0.0.0 --port 5000
|
||||||
|
|
||||||
|
- name: Discover app port
|
||||||
|
id: port
|
||||||
|
run: |
|
||||||
|
sleep 2
|
||||||
|
# Read shifted port from container logs (entrypoint prints [ci-port-shift])
|
||||||
|
CI_LOG=$(docker logs newsarchiver-e2e 2>&1 | grep "\[ci-port-shift\]" || echo "")
|
||||||
|
if [ -n "$CI_LOG" ]; then
|
||||||
|
APP_PORT=$(echo "$CI_LOG" | grep -oP 'to \K[0-9]+')
|
||||||
|
echo "app_port=${APP_PORT}" >> $GITHUB_OUTPUT
|
||||||
|
echo "$CI_LOG"
|
||||||
|
# Re-publish port now that we know the shifted port
|
||||||
|
echo "Discovered port ${APP_PORT} from CI logs"
|
||||||
|
else
|
||||||
|
echo "app_port=5000" >> $GITHUB_OUTPUT
|
||||||
|
echo "No CI port shift detected, using default 5000"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Seed test data
|
- name: Seed test data
|
||||||
run: |
|
run: |
|
||||||
sleep 3
|
sleep 3
|
||||||
@ -141,19 +159,23 @@ jobs:
|
|||||||
|
|
||||||
- name: Wait for app
|
- name: Wait for app
|
||||||
run: |
|
run: |
|
||||||
sleep 5
|
APP_PORT="${{ steps.port.outputs.app_port }}"
|
||||||
|
sleep 3
|
||||||
|
# Health check from inside container (no host port publish needed)
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
curl -sf http://localhost:5000/ && echo "App ready" && break
|
docker exec newsarchiver-e2e curl -sf "http://localhost:${APP_PORT}/" && echo "App ready on port ${APP_PORT}" && exit 0
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
|
echo "App failed to start" && exit 1
|
||||||
|
|
||||||
- name: Run Playwright tests
|
- name: Run Playwright tests
|
||||||
run: |
|
run: |
|
||||||
|
APP_PORT="${{ steps.port.outputs.app_port }}"
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--network newsarchiver-network \
|
--network newsarchiver-network \
|
||||||
-v $GITHUB_WORKSPACE/tests/playwright:/tests \
|
-v $GITHUB_WORKSPACE/tests/playwright:/tests \
|
||||||
-w /tests \
|
-w /tests \
|
||||||
-e APP_URL=http://newsarchiver-e2e:5000 \
|
-e APP_URL=http://newsarchiver-e2e:${APP_PORT} \
|
||||||
mcr.microsoft.com/playwright:v1.51.0-jammy \
|
mcr.microsoft.com/playwright:v1.51.0-jammy \
|
||||||
npx playwright test
|
npx playwright test
|
||||||
|
|
||||||
|
|||||||
@ -256,6 +256,13 @@ Examples:
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# CI port shift: detect CI env, shift port to avoid conflicts with production
|
||||||
|
if os.environ.get("CI") == "true" and os.environ.get("SKIP_PORT_SHIFT") != "1":
|
||||||
|
offset = int(os.environ.get("CI_PORT_OFFSET", "1"))
|
||||||
|
original_port = args.port
|
||||||
|
args.port = original_port + offset
|
||||||
|
print(f"[ci-port-shift] Port shifted from {original_port} to {args.port} (offset: {offset})")
|
||||||
|
|
||||||
logger = setup_logging(args.verbose)
|
logger = setup_logging(args.verbose)
|
||||||
|
|
||||||
if args.run:
|
if args.run:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user