test-install.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. fail-fast: false
  18. matrix:
  19. distro: [alpine, ubuntu, debian-12, debian-13]
  20. include:
  21. - distro: alpine
  22. container: alpine:latest
  23. squid_package: squid
  24. squid_service: squid
  25. python_packages: "python3 py3-pip py3-virtualenv"
  26. - distro: ubuntu
  27. container: ubuntu:latest
  28. squid_package: squid
  29. squid_service: squid
  30. python_packages: "python3 python3-pip python3-venv"
  31. - distro: debian-12
  32. container: debian:12
  33. squid_package: squid
  34. squid_service: squid
  35. python_packages: "python3 python3-pip python3-venv"
  36. - distro: debian-13
  37. container: debian:13
  38. squid_package: squid
  39. squid_service: squid
  40. python_packages: "python3 python3-pip python3-venv"
  41. container:
  42. image: ${{ matrix.container }}
  43. steps:
  44. - name: Install system dependencies
  45. run: |
  46. if [ "${{ matrix.distro }}" = "alpine" ]; then
  47. apk update
  48. apk add --no-cache \
  49. bash \
  50. git \
  51. ${{ matrix.python_packages }} \
  52. mariadb-dev \
  53. curl \
  54. build-base \
  55. openssl-dev \
  56. postgresql-dev \
  57. ${{ matrix.squid_package }} \
  58. openrc \
  59. sudo \
  60. procps \
  61. grep \
  62. tzdata
  63. else
  64. # Configurar entorno no interactivo para Ubuntu/Debian
  65. export DEBIAN_FRONTEND=noninteractive
  66. export TZ=UTC
  67. apt-get update
  68. apt-get install -y \
  69. bash \
  70. git \
  71. ${{ matrix.python_packages }} \
  72. libmariadb-dev \
  73. curl \
  74. build-essential \
  75. libssl-dev \
  76. postgresql-server-dev-all \
  77. ${{ matrix.squid_package }} \
  78. sudo \
  79. procps \
  80. grep \
  81. tzdata
  82. fi
  83. - name: Checkout code
  84. uses: actions/checkout@v7
  85. - name: Configure Squid (Alpine)
  86. if: matrix.distro == 'alpine'
  87. run: |
  88. mkdir -p /var/log/squid /var/cache/squid
  89. chmod -R 777 /var/log/squid /var/cache/squid
  90. {
  91. echo 'http_port 3128'
  92. echo 'access_log /var/log/squid/access.log squid'
  93. echo 'coredump_dir /var/cache/squid'
  94. echo 'acl localnet src 127.0.0.0/8'
  95. echo 'http_access allow localnet'
  96. echo 'http_access deny all'
  97. } > /etc/squid/squid.conf
  98. # Run in foreground (non-daemon) so the process stays visible in the container
  99. squid -N -f /etc/squid/squid.conf &
  100. echo "Squid started with PID $!"
  101. - name: Configure Squid (Ubuntu/Debian)
  102. if: matrix.distro != 'alpine'
  103. run: |
  104. mkdir -p /var/log/squid /var/cache/squid
  105. chown -R proxy:proxy /var/log/squid /var/cache/squid
  106. chmod -R 755 /var/log/squid /var/cache/squid
  107. {
  108. echo 'http_port 3128'
  109. echo 'access_log /var/log/squid/access.log squid'
  110. echo 'coredump_dir /var/cache/squid'
  111. echo 'acl localnet src 127.0.0.0/8'
  112. echo 'http_access allow localnet'
  113. echo 'http_access deny all'
  114. } > /etc/squid/squid.conf
  115. # Run in foreground (non-daemon) so the process stays visible in the container
  116. squid -N -f /etc/squid/squid.conf &
  117. echo "Squid started with PID $!"
  118. - name: Wait for Squid to become available and generate access log
  119. run: |
  120. for i in $(seq 1 30); do
  121. if curl -s --max-time 5 http://127.0.0.1:3128/ > /dev/null 2>&1; then
  122. echo "Squid responding on port 3128"
  123. break
  124. fi
  125. echo "Waiting for Squid to start... ($i/30)"
  126. sleep 1
  127. done
  128. if ! curl -s --max-time 5 http://127.0.0.1:3128/ > /dev/null 2>&1; then
  129. echo "⚠️ WARNING: Squid is not listening on 127.0.0.1:3128 after 30s"
  130. echo "The app will return HTTP 502 (Squid unavailable) which is still a valid CI result."
  131. echo "=== Squid process list ==="
  132. ps -ef | grep -i squid | grep -v grep || true
  133. echo "=== Squid cache log ==="
  134. cat /var/log/squid/cache.log 2>/dev/null || echo "(no cache log)"
  135. fi
  136. # Generar una entrada en el log accediendo a squid
  137. curl -s -o /dev/null http://127.0.0.1:3128/ || true
  138. # Verificar que el log existe
  139. ls -la /var/log/squid/access.log || echo "Log file check"
  140. - name: Make install script executable
  141. run: |
  142. chmod +x install.sh
  143. - name: Run installation script (non-interactive)
  144. run: |
  145. # Ejecutar instalación no interactiva
  146. # En CI, el script detecta app.py + requirements.txt y usa el directorio actual
  147. ./install.sh --non-interactive
  148. env:
  149. DEBIAN_FRONTEND: noninteractive
  150. TZ: UTC
  151. - name: Start application (container mode)
  152. run: |
  153. # En contenedor no hay systemd/openrc, iniciar la app manualmente
  154. # El script instaló el venv en el directorio actual (checkout)
  155. INSTALL_DIR="$(pwd)"
  156. if [ ! -f "$INSTALL_DIR/app.py" ]; then
  157. echo "app.py not found in $INSTALL_DIR"
  158. ls -la "$INSTALL_DIR"
  159. exit 1
  160. fi
  161. # Start application in background with more robust method
  162. "$INSTALL_DIR/venv/bin/python3" "$INSTALL_DIR/app.py" > "$INSTALL_DIR/app.log" 2>&1 &
  163. APP_PID=$!
  164. echo $APP_PID > "$INSTALL_DIR/squidstats.pid"
  165. echo "Application started with PID $APP_PID from $INSTALL_DIR"
  166. # Give it a moment to start
  167. sleep 2
  168. - name: Wait for application to start
  169. run: |
  170. for i in $(seq 1 30); do
  171. if curl -s --max-time 5 http://localhost:5000 > /dev/null 2>&1; then
  172. echo "Application is responding on port 5000"
  173. break
  174. fi
  175. if [ "$i" -eq 30 ]; then
  176. echo "Timeout waiting for application"
  177. cat "$(pwd)/app.log" 2>/dev/null || true
  178. exit 1
  179. fi
  180. echo "Waiting for application to start... ($i/30)"
  181. sleep 1
  182. done
  183. - name: Test application response
  184. run: |
  185. response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000)
  186. if [ "$response" = "200" ]; then
  187. echo "✅ SUCCESS: Application returned HTTP 200 (Squid is reachable)"
  188. elif [ "$response" = "502" ]; then
  189. echo "✅ SUCCESS: Application returned HTTP 502 (running correctly; Squid not available in CI)"
  190. else
  191. echo "❌ FAILED: Application returned unexpected HTTP $response"
  192. echo "=== Application logs ==="
  193. tail -50 "$(pwd)/app.log" 2>/dev/null || echo "No app.log found"
  194. echo "=== Process check ==="
  195. if [ -f "$(pwd)/squidstats.pid" ]; then
  196. pid=$(cat "$(pwd)/squidstats.pid")
  197. ps -p $pid 2>/dev/null || echo "Process $pid not running"
  198. fi
  199. exit 1
  200. fi
  201. - name: Show application logs
  202. if: always()
  203. run: |
  204. INSTALL_DIR="$(pwd)"
  205. echo "=== Install Directory ==="
  206. echo "$INSTALL_DIR"
  207. ls -la "$INSTALL_DIR/venv/" 2>/dev/null || echo "No venv found"
  208. echo "=== Application Logs ==="
  209. tail -50 "$INSTALL_DIR/app.log" 2>/dev/null || echo "No application logs found"
  210. echo "=== Process Status ==="
  211. if [ -f "$INSTALL_DIR/squidstats.pid" ]; then
  212. pid=$(cat "$INSTALL_DIR/squidstats.pid")
  213. ps -p $pid 2>/dev/null || echo "Process $pid not running"
  214. else
  215. echo "No PID file found"
  216. fi