feat: CI auto-detects and shifts port to avoid production conflicts
This commit is contained in:
parent
e47dd2315e
commit
c27bd399ec
@ -102,13 +102,31 @@ jobs:
|
||||
docker rm -f newsarchiver-e2e 2>/dev/null || true
|
||||
docker run -d --name newsarchiver-e2e \
|
||||
--network newsarchiver-network \
|
||||
-p 5000:5000 \
|
||||
-e CI=true \
|
||||
-e CI_PORT_OFFSET=1 \
|
||||
-e ADMIN_PASSWORD="" \
|
||||
-e ARCHIVE_DIR=/data/archives \
|
||||
-e DISABLE_RSS_FETCH=1 \
|
||||
jarianc/newsarchiverv2:test \
|
||||
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
|
||||
run: |
|
||||
sleep 3
|
||||
@ -141,19 +159,23 @@ jobs:
|
||||
|
||||
- name: Wait for app
|
||||
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
|
||||
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
|
||||
done
|
||||
echo "App failed to start" && exit 1
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: |
|
||||
APP_PORT="${{ steps.port.outputs.app_port }}"
|
||||
docker run --rm \
|
||||
--network newsarchiver-network \
|
||||
-v $GITHUB_WORKSPACE/tests/playwright:/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 \
|
||||
npx playwright test
|
||||
|
||||
|
||||
@ -255,7 +255,14 @@ Examples:
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
if args.run:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user