| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- name: Test Installation Script
- permissions:
- contents: read
- on:
- push:
- branches: [ main, dev ]
- pull_request:
- branches: [ main , dev, workflow-install-test ]
- workflow_dispatch:
- jobs:
- test-install:
- runs-on: ubuntu-latest
- env:
- DEBIAN_FRONTEND: noninteractive
- TZ: Etc/UTC
- strategy:
- matrix:
- distro: [alpine, ubuntu]
- include:
- - distro: alpine
- container: alpine:latest
- squid_package: squid
- squid_service: squid
- python_packages: "python3 py3-pip py3-virtualenv"
- - distro: ubuntu
- container: ubuntu:latest
- squid_package: squid
- squid_service: squid
- python_packages: "python3 python3-pip python3-venv"
- container:
- image: ${{ matrix.container }}
- steps:
- - name: Install system dependencies
- run: |
- if [ "${{ matrix.distro }}" = "alpine" ]; then
- apk update
- apk add --no-cache \
- bash \
- git \
- ${{ matrix.python_packages }} \
- mariadb-dev \
- curl \
- build-base \
- openssl-dev \
- postgresql-dev \
- ${{ matrix.squid_package }} \
- openrc \
- sudo \
- procps \
- grep \
- tzdata
- else
- # Configurar entorno no interactivo para Ubuntu/Debian
- export DEBIAN_FRONTEND=noninteractive
- export TZ=UTC
-
- apt-get update
- apt-get install -y \
- bash \
- git \
- ${{ matrix.python_packages }} \
- libmariadb-dev \
- curl \
- build-essential \
- libssl-dev \
- postgresql-server-dev-all \
- ${{ matrix.squid_package }} \
- sudo \
- procps \
- grep \
- tzdata
- fi
- - name: Checkout code
- uses: actions/checkout@v6
- - name: Configure Squid (Alpine)
- if: matrix.distro == 'alpine'
- run: |
- mkdir -p /var/log/squid /var/cache/squid
- chmod -R 777 /var/log/squid /var/cache/squid
- {
- echo 'http_port 3128'
- echo 'access_log /var/log/squid/access.log squid'
- echo 'coredump_dir /var/cache/squid'
- echo 'acl localnet src 127.0.0.0/8'
- echo 'http_access allow localnet'
- echo 'http_access deny all'
- } > /etc/squid/squid.conf
- # Run in foreground (non-daemon) so the process stays visible in the container
- squid -N -f /etc/squid/squid.conf &
- echo "Squid started with PID $!"
- - name: Configure Squid (Ubuntu)
- if: matrix.distro == 'ubuntu'
- run: |
- mkdir -p /var/log/squid /var/cache/squid
- chown -R proxy:proxy /var/log/squid /var/cache/squid
- chmod -R 755 /var/log/squid /var/cache/squid
- {
- echo 'http_port 3128'
- echo 'access_log /var/log/squid/access.log squid'
- echo 'coredump_dir /var/cache/squid'
- echo 'acl localnet src 127.0.0.0/8'
- echo 'http_access allow localnet'
- echo 'http_access deny all'
- } > /etc/squid/squid.conf
- # Run in foreground (non-daemon) so the process stays visible in the container
- squid -N -f /etc/squid/squid.conf &
- echo "Squid started with PID $!"
- - name: Wait for Squid to become available and generate access log
- run: |
- for i in $(seq 1 30); do
- if curl -s --max-time 5 http://127.0.0.1:3128/ > /dev/null 2>&1; then
- echo "Squid responding on port 3128"
- break
- fi
- echo "Waiting for Squid to start... ($i/30)"
- sleep 1
- done
- if ! curl -s --max-time 5 http://127.0.0.1:3128/ > /dev/null 2>&1; then
- echo "⚠️ WARNING: Squid is not listening on 127.0.0.1:3128 after 30s"
- echo "The app will return HTTP 502 (Squid unavailable) which is still a valid CI result."
- echo "=== Squid process list ==="
- ps -ef | grep -i squid | grep -v grep || true
- echo "=== Squid cache log ==="
- cat /var/log/squid/cache.log 2>/dev/null || echo "(no cache log)"
- fi
- # Generar una entrada en el log accediendo a squid
- curl -s -o /dev/null http://127.0.0.1:3128/ || true
-
- # Verificar que el log existe
- ls -la /var/log/squid/access.log || echo "Log file check"
- - name: Make install script executable
- run: |
- chmod +x install.sh
- - name: Run installation script (non-interactive)
- run: |
- # Ejecutar instalación no interactiva
- # En CI, el script detecta app.py + requirements.txt y usa el directorio actual
- ./install.sh --non-interactive
- env:
- DEBIAN_FRONTEND: noninteractive
- TZ: UTC
- - name: Start application (container mode)
- run: |
- # En contenedor no hay systemd/openrc, iniciar la app manualmente
- # El script instaló el venv en el directorio actual (checkout)
- INSTALL_DIR="$(pwd)"
-
- if [ ! -f "$INSTALL_DIR/app.py" ]; then
- echo "app.py not found in $INSTALL_DIR"
- ls -la "$INSTALL_DIR"
- exit 1
- fi
-
- # Start application in background with more robust method
- "$INSTALL_DIR/venv/bin/python3" "$INSTALL_DIR/app.py" > "$INSTALL_DIR/app.log" 2>&1 &
- APP_PID=$!
- echo $APP_PID > "$INSTALL_DIR/squidstats.pid"
- echo "Application started with PID $APP_PID from $INSTALL_DIR"
-
- # Give it a moment to start
- sleep 2
- - name: Wait for application to start
- run: |
- for i in $(seq 1 30); do
- if curl -s --max-time 5 http://localhost:5000 > /dev/null 2>&1; then
- echo "Application is responding on port 5000"
- break
- fi
- if [ "$i" -eq 30 ]; then
- echo "Timeout waiting for application"
- cat "$(pwd)/app.log" 2>/dev/null || true
- exit 1
- fi
- echo "Waiting for application to start... ($i/30)"
- sleep 1
- done
- - name: Test application response
- run: |
- response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000)
- if [ "$response" = "200" ]; then
- echo "✅ SUCCESS: Application returned HTTP 200 (Squid is reachable)"
- elif [ "$response" = "502" ]; then
- echo "✅ SUCCESS: Application returned HTTP 502 (running correctly; Squid not available in CI)"
- else
- echo "❌ FAILED: Application returned unexpected HTTP $response"
- echo "=== Application logs ==="
- tail -50 "$(pwd)/app.log" 2>/dev/null || echo "No app.log found"
- echo "=== Process check ==="
- if [ -f "$(pwd)/squidstats.pid" ]; then
- pid=$(cat "$(pwd)/squidstats.pid")
- ps -p $pid 2>/dev/null || echo "Process $pid not running"
- fi
- exit 1
- fi
- - name: Show application logs
- if: always()
- run: |
- INSTALL_DIR="$(pwd)"
- echo "=== Install Directory ==="
- echo "$INSTALL_DIR"
- ls -la "$INSTALL_DIR/venv/" 2>/dev/null || echo "No venv found"
-
- echo "=== Application Logs ==="
- tail -50 "$INSTALL_DIR/app.log" 2>/dev/null || echo "No application logs found"
-
- echo "=== Process Status ==="
- if [ -f "$INSTALL_DIR/squidstats.pid" ]; then
- pid=$(cat "$INSTALL_DIR/squidstats.pid")
- ps -p $pid 2>/dev/null || echo "Process $pid not running"
- else
- echo "No PID file found"
- fi
|