test-install.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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@v6
  74. - name: Configure Squid (Alpine)
  75. if: matrix.distro == 'alpine'
  76. run: |
  77. mkdir -p /var/log/squid /var/cache/squid
  78. chmod -R 777 /var/log/squid /var/cache/squid
  79. {
  80. echo 'http_port 3128'
  81. echo 'access_log /var/log/squid/access.log squid'
  82. echo 'coredump_dir /var/cache/squid'
  83. echo 'acl localnet src 127.0.0.0/8'
  84. echo 'http_access allow localnet'
  85. echo 'http_access deny all'
  86. } > /etc/squid/squid.conf
  87. # Run in foreground (non-daemon) so the process stays visible in the container
  88. squid -N -f /etc/squid/squid.conf &
  89. echo "Squid started with PID $!"
  90. - name: Configure Squid (Ubuntu)
  91. if: matrix.distro == 'ubuntu'
  92. run: |
  93. mkdir -p /var/log/squid /var/cache/squid
  94. chown -R proxy:proxy /var/log/squid /var/cache/squid
  95. chmod -R 755 /var/log/squid /var/cache/squid
  96. {
  97. echo 'http_port 3128'
  98. echo 'access_log /var/log/squid/access.log squid'
  99. echo 'coredump_dir /var/cache/squid'
  100. echo 'acl localnet src 127.0.0.0/8'
  101. echo 'http_access allow localnet'
  102. echo 'http_access deny all'
  103. } > /etc/squid/squid.conf
  104. # Run in foreground (non-daemon) so the process stays visible in the container
  105. squid -N -f /etc/squid/squid.conf &
  106. echo "Squid started with PID $!"
  107. - name: Wait for Squid to become available and generate access log
  108. run: |
  109. for i in $(seq 1 30); do
  110. if curl -s --max-time 5 http://127.0.0.1:3128/ > /dev/null 2>&1; then
  111. echo "Squid responding on port 3128"
  112. break
  113. fi
  114. echo "Waiting for Squid to start... ($i/30)"
  115. sleep 1
  116. done
  117. if ! curl -s --max-time 5 http://127.0.0.1:3128/ > /dev/null 2>&1; then
  118. echo "⚠️ WARNING: Squid is not listening on 127.0.0.1:3128 after 30s"
  119. echo "The app will return HTTP 502 (Squid unavailable) which is still a valid CI result."
  120. echo "=== Squid process list ==="
  121. ps -ef | grep -i squid | grep -v grep || true
  122. echo "=== Squid cache log ==="
  123. cat /var/log/squid/cache.log 2>/dev/null || echo "(no cache log)"
  124. fi
  125. # Generar una entrada en el log accediendo a squid
  126. curl -s -o /dev/null http://127.0.0.1:3128/ || true
  127. # Verificar que el log existe
  128. ls -la /var/log/squid/access.log || echo "Log file check"
  129. - name: Make install script executable
  130. run: |
  131. chmod +x install.sh
  132. - name: Run installation script (non-interactive)
  133. run: |
  134. # Ejecutar instalación no interactiva
  135. # En CI, el script detecta app.py + requirements.txt y usa el directorio actual
  136. ./install.sh --non-interactive
  137. env:
  138. DEBIAN_FRONTEND: noninteractive
  139. TZ: UTC
  140. - name: Start application (container mode)
  141. run: |
  142. # En contenedor no hay systemd/openrc, iniciar la app manualmente
  143. # El script instaló el venv en el directorio actual (checkout)
  144. INSTALL_DIR="$(pwd)"
  145. if [ ! -f "$INSTALL_DIR/app.py" ]; then
  146. echo "app.py not found in $INSTALL_DIR"
  147. ls -la "$INSTALL_DIR"
  148. exit 1
  149. fi
  150. # Start application in background with more robust method
  151. "$INSTALL_DIR/venv/bin/python3" "$INSTALL_DIR/app.py" > "$INSTALL_DIR/app.log" 2>&1 &
  152. APP_PID=$!
  153. echo $APP_PID > "$INSTALL_DIR/squidstats.pid"
  154. echo "Application started with PID $APP_PID from $INSTALL_DIR"
  155. # Give it a moment to start
  156. sleep 2
  157. - name: Wait for application to start
  158. run: |
  159. for i in $(seq 1 30); do
  160. if curl -s --max-time 5 http://localhost:5000 > /dev/null 2>&1; then
  161. echo "Application is responding on port 5000"
  162. break
  163. fi
  164. if [ "$i" -eq 30 ]; then
  165. echo "Timeout waiting for application"
  166. cat "$(pwd)/app.log" 2>/dev/null || true
  167. exit 1
  168. fi
  169. echo "Waiting for application to start... ($i/30)"
  170. sleep 1
  171. done
  172. - name: Test application response
  173. run: |
  174. response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000)
  175. if [ "$response" = "200" ]; then
  176. echo "✅ SUCCESS: Application returned HTTP 200 (Squid is reachable)"
  177. elif [ "$response" = "502" ]; then
  178. echo "✅ SUCCESS: Application returned HTTP 502 (running correctly; Squid not available in CI)"
  179. else
  180. echo "❌ FAILED: Application returned unexpected HTTP $response"
  181. echo "=== Application logs ==="
  182. tail -50 "$(pwd)/app.log" 2>/dev/null || echo "No app.log found"
  183. echo "=== Process check ==="
  184. if [ -f "$(pwd)/squidstats.pid" ]; then
  185. pid=$(cat "$(pwd)/squidstats.pid")
  186. ps -p $pid 2>/dev/null || echo "Process $pid not running"
  187. fi
  188. exit 1
  189. fi
  190. - name: Show application logs
  191. if: always()
  192. run: |
  193. INSTALL_DIR="$(pwd)"
  194. echo "=== Install Directory ==="
  195. echo "$INSTALL_DIR"
  196. ls -la "$INSTALL_DIR/venv/" 2>/dev/null || echo "No venv found"
  197. echo "=== Application Logs ==="
  198. tail -50 "$INSTALL_DIR/app.log" 2>/dev/null || echo "No application logs found"
  199. echo "=== Process Status ==="
  200. if [ -f "$INSTALL_DIR/squidstats.pid" ]; then
  201. pid=$(cat "$INSTALL_DIR/squidstats.pid")
  202. ps -p $pid 2>/dev/null || echo "Process $pid not running"
  203. else
  204. echo "No PID file found"
  205. fi