test-install.yml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. name: Test Installation Script
  2. permissions:
  3. contents: read
  4. on:
  5. push:
  6. branches: [ main, dev ]
  7. pull_request:
  8. branches: [ main , dev, workflow-install-test ]
  9. workflow_dispatch:
  10. jobs:
  11. test-install:
  12. runs-on: ubuntu-latest
  13. env:
  14. DEBIAN_FRONTEND: noninteractive
  15. TZ: Etc/UTC
  16. strategy:
  17. matrix:
  18. distro: [alpine, ubuntu]
  19. include:
  20. - distro: alpine
  21. container: alpine:latest
  22. squid_package: squid
  23. squid_service: squid
  24. python_packages: "python3 py3-pip py3-virtualenv"
  25. - distro: ubuntu
  26. container: ubuntu:latest
  27. squid_package: squid
  28. squid_service: squid
  29. python_packages: "python3 python3-pip python3-venv"
  30. container:
  31. image: ${{ matrix.container }}
  32. steps:
  33. - name: Install system dependencies
  34. run: |
  35. if [ "${{ matrix.distro }}" = "alpine" ]; then
  36. apk update
  37. apk add --no-cache \
  38. bash \
  39. git \
  40. ${{ matrix.python_packages }} \
  41. mariadb-dev \
  42. curl \
  43. build-base \
  44. openssl-dev \
  45. postgresql-dev \
  46. ${{ matrix.squid_package }} \
  47. openrc \
  48. sudo \
  49. procps \
  50. grep \
  51. tzdata
  52. else
  53. # Configurar entorno no interactivo para Ubuntu/Debian
  54. export DEBIAN_FRONTEND=noninteractive
  55. export TZ=UTC
  56. apt-get update
  57. apt-get install -y \
  58. bash \
  59. git \
  60. ${{ matrix.python_packages }} \
  61. libmariadb-dev \
  62. curl \
  63. build-essential \
  64. libssl-dev \
  65. postgresql-server-dev-all \
  66. ${{ matrix.squid_package }} \
  67. sudo \
  68. procps \
  69. grep \
  70. tzdata
  71. fi
  72. - name: Checkout code
  73. uses: actions/checkout@v4
  74. - name: Configure Squid (Alpine)
  75. if: matrix.distro == 'alpine'
  76. run: |
  77. # Crear directorios necesarios
  78. mkdir -p /var/log/squid /var/cache/squid /var/run/squid
  79. # Configurar squid básico
  80. cat > /etc/squid/squid.conf << 'EOF'
  81. # Basic Squid configuration for testing
  82. http_port 3128
  83. cache_dir ufs /var/cache/squid 100 16 256
  84. access_log /var/log/squid/access.log squid
  85. cache_log /var/log/squid/cache.log
  86. pid_filename /var/run/squid/squid.pid
  87. # Allow local access
  88. acl localnet src 127.0.0.0/8
  89. http_access allow localnet
  90. http_access deny all
  91. EOF
  92. # Inicializar cache
  93. squid -z || true
  94. # Iniciar squid en background
  95. squid || echo "Squid started"
  96. - name: Configure Squid (Ubuntu)
  97. if: matrix.distro == 'ubuntu'
  98. run: |
  99. # Crear directorios necesarios
  100. mkdir -p /var/log/squid /var/cache/squid /var/run/squid
  101. # Configurar squid básico
  102. cat > /etc/squid/squid.conf << 'EOF'
  103. # Basic Squid configuration for testing
  104. http_port 3128
  105. cache_dir ufs /var/cache/squid 100 16 256
  106. access_log /var/log/squid/access.log squid
  107. cache_log /var/log/squid/cache.log
  108. pid_filename /var/run/squid/squid.pid
  109. # Allow local access
  110. acl localnet src 127.0.0.0/8
  111. http_access allow localnet
  112. http_access deny all
  113. EOF
  114. chown -R proxy:proxy /var/log/squid /var/cache/squid /var/run/squid
  115. chmod -R 755 /var/log/squid /var/cache/squid /var/run/squid
  116. # Inicializar cache
  117. squid -z || true
  118. # Iniciar squid
  119. service squid start || squid
  120. - name: Generate Squid access log
  121. run: |
  122. # Esperar a que squid esté listo
  123. sleep 2
  124. # Generar una entrada en el log accediendo a squid
  125. curl -s -o /dev/null http://127.0.0.1:3128/ || echo "Squid access logged"
  126. # Verificar que el log existe
  127. ls -la /var/log/squid/access.log || echo "Log file check"
  128. - name: Make install script executable
  129. run: |
  130. chmod +x install.sh
  131. - name: Run installation script (non-interactive)
  132. run: |
  133. # Ejecutar instalación no interactiva
  134. # En CI, el script detecta app.py + requirements.txt y usa el directorio actual
  135. ./install.sh --non-interactive
  136. env:
  137. DEBIAN_FRONTEND: noninteractive
  138. TZ: UTC
  139. - name: Start application (container mode)
  140. run: |
  141. # En contenedor no hay systemd/openrc, iniciar la app manualmente
  142. # El script instaló el venv en el directorio actual (checkout)
  143. INSTALL_DIR="$(pwd)"
  144. if [ ! -f "$INSTALL_DIR/app.py" ]; then
  145. echo "app.py not found in $INSTALL_DIR"
  146. ls -la "$INSTALL_DIR"
  147. exit 1
  148. fi
  149. # Start application in background with more robust method
  150. "$INSTALL_DIR/venv/bin/python3" "$INSTALL_DIR/app.py" > "$INSTALL_DIR/app.log" 2>&1 &
  151. APP_PID=$!
  152. echo $APP_PID > "$INSTALL_DIR/squidstats.pid"
  153. echo "Application started with PID $APP_PID from $INSTALL_DIR"
  154. # Give it a moment to start
  155. sleep 2
  156. - name: Wait for application to start
  157. run: |
  158. for i in $(seq 1 30); do
  159. if curl -s --max-time 5 http://localhost:5000 > /dev/null 2>&1; then
  160. echo "Application is responding on port 5000"
  161. break
  162. fi
  163. if [ "$i" -eq 30 ]; then
  164. echo "Timeout waiting for application"
  165. cat "$(pwd)/app.log" 2>/dev/null || true
  166. exit 1
  167. fi
  168. echo "Waiting for application to start... ($i/30)"
  169. sleep 1
  170. done
  171. - name: Test application response
  172. run: |
  173. response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000)
  174. if [ "$response" = "200" ]; then
  175. echo "✅ SUCCESS: Application returned HTTP 200"
  176. else
  177. echo "❌ FAILED: Application returned HTTP $response"
  178. echo "=== Application logs ==="
  179. tail -50 "$(pwd)/app.log" 2>/dev/null || echo "No app.log found"
  180. echo "=== Process check ==="
  181. if [ -f "$(pwd)/squidstats.pid" ]; then
  182. pid=$(cat "$(pwd)/squidstats.pid")
  183. ps -p $pid 2>/dev/null || echo "Process $pid not running"
  184. fi
  185. exit 1
  186. fi
  187. - name: Show application logs
  188. if: always()
  189. run: |
  190. INSTALL_DIR="$(pwd)"
  191. echo "=== Install Directory ==="
  192. echo "$INSTALL_DIR"
  193. ls -la "$INSTALL_DIR/venv/" 2>/dev/null || echo "No venv found"
  194. echo "=== Application Logs ==="
  195. tail -50 "$INSTALL_DIR/app.log" 2>/dev/null || echo "No application logs found"
  196. echo "=== Process Status ==="
  197. if [ -f "$INSTALL_DIR/squidstats.pid" ]; then
  198. pid=$(cat "$INSTALL_DIR/squidstats.pid")
  199. ps -p $pid 2>/dev/null || echo "Process $pid not running"
  200. else
  201. echo "No PID file found"
  202. fi