From ed248bbb795096c0635eb58c05542b7b4c78e7c3 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 8 Apr 2024 16:13:20 +0200 Subject: [PATCH 1/2] fix: production down when tests being run --- frontend/cypress.config.ts | 6 ++--- test.sh | 17 +++++++----- test.yml | 54 +++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/frontend/cypress.config.ts b/frontend/cypress.config.ts index 8bd806de..686e5ac2 100644 --- a/frontend/cypress.config.ts +++ b/frontend/cypress.config.ts @@ -1,8 +1,8 @@ -import { defineConfig } from "cypress"; +import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - baseUrl: "https://nginx", - specPattern: "src/test/e2e/**/*.cy.{js,jsx,ts,tsx}", + baseUrl: 'http://test_nginx', + specPattern: 'src/test/e2e/**/*.cy.{js,jsx,ts,tsx}', }, }); diff --git a/test.sh b/test.sh index 0a42e1b6..f4cba183 100755 --- a/test.sh +++ b/test.sh @@ -54,7 +54,7 @@ if [ "$build" = true ]; then fi echo "Starting services..." -docker-compose -f test.yml up -d --scale cypress=0 +docker-compose -f test.yml up -d --scale test_cypress=0 cypress_exit=0 vitest_exit=0 @@ -63,25 +63,25 @@ django_exit=0 if [ "$frontend" = true ]; then echo "Running frontend tests..." echo "Running Cypress tests..." - docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress + docker-compose -f test.yml up --exit-code-from test_cypress --abort-on-container-exit test_cypress cypress_exit=$? echo "Running Vitest tests..." - docker exec frontend npm run test + docker exec test_frontend npm run test vitest_exit=$? elif [ "$backend" = true ]; then echo "Running backend tests..." - docker exec backend python manage.py test + docker exec test_backend python manage.py test django_exit=$? else echo "Running backend tests..." - docker exec backend python manage.py test + docker exec test_backend python manage.py test django_exit=$? echo "Running frontend tests..." echo "Running Cypress tests..." - docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress + docker-compose -f test.yml up --exit-code-from test_cypress --abort-on-container-exit test_cypress cypress_exit=$? echo "Running Vitest tests..." - docker exec frontend npm run test + docker exec test_frontend npm run test vitest_exit=$? fi @@ -98,6 +98,9 @@ if [ $cypress_exit -ne 0 ] || [ $vitest_exit -ne 0 ] || [ $django_exit -ne 0 ]; echo " - Django" fi echo "-----------------" + echo "Cleaning up..." + docker-compose -f test.yml down + echo "Done." exit 1 else echo "All tests passed!" diff --git a/test.yml b/test.yml index ac716c0f..cd50a19e 100644 --- a/test.yml +++ b/test.yml @@ -3,18 +3,18 @@ version: "3.9" ############################# NETWORKS networks: - selab_network: - name: selab_network + test_selab_network: + name: test_selab_network driver: bridge ipam: config: - - subnet: 192.168.90.0/24 + - subnet: 192.168.91.0/24 ############################# EXTENSIONS x-common-keys-selab: &common-keys-selab networks: - - selab_network + - test_selab_network security_opt: - no-new-privileges:true restart: unless-stopped @@ -28,49 +28,49 @@ x-common-keys-selab: &common-keys-selab ############################# SERVICES services: - nginx: + test_nginx: <<: *common-keys-selab image: nginx:latest - container_name: nginx + container_name: test_nginx expose: - 80 - 443 - 8080 volumes: - - ${DATA_DIR}/nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro + - ${DATA_DIR}/nginx/nginx.test.conf:/etc/nginx/nginx.conf:ro - ${SSL_DIR}:/etc/nginx/ssl:ro depends_on: - - backend - - frontend + - test_backend + - test_frontend - backend: + test_backend: <<: *common-keys-selab - container_name: backend + container_name: test_backend build: context: $BACKEND_DIR dockerfile: Dockerfile - command: /bin/bash -c "./setup.sh && python manage.py runsslserver 192.168.90.2:8080" + command: /bin/bash -c "./setup.sh && python manage.py runsslserver 192.168.91.2:8080" expose: - 8080 volumes: - $BACKEND_DIR:/code - celery: + test_celery: <<: *common-keys-selab - container_name: celery + container_name: test_celery build: context: $BACKEND_DIR - dockerfile: Dockerfile.dev + dockerfile: Dockerfile command: celery -A ypovoli worker -l DEBUG volumes: - $BACKEND_DIR:/code depends_on: - - backend - - redis + - test_backend + - test_redis - frontend: + test_frontend: <<: *common-keys-selab - container_name: frontend + container_name: test_frontend build: context: $FRONTEND_DIR dockerfile: Dockerfile.dev @@ -80,24 +80,24 @@ services: volumes: - $FRONTEND_DIR:/app depends_on: - - backend + - test_backend - redis: + test_redis: <<: *common-keys-selab - container_name: redis + container_name: test_redis image: redis:latest networks: - selab_network: - ipv4_address: $REDIS_IP + test_selab_network: + ipv4_address: 192.168.91.10 expose: - - $REDIS_PORT + - 6379 entrypoint: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru volumes: - ${DATA_DIR}/redis:/data - cypress: + test_cypress: <<: *common-keys-selab - container_name: cypress + container_name: test_cypress image: cypress/included:cypress-12.17.3-node-18.16.0-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1 restart: "no" working_dir: /e2e From 6c54026bdaee116b57200968efc02fdc0e4f1b12 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Mon, 8 Apr 2024 16:30:39 +0200 Subject: [PATCH 2/2] chore: added ignored nginx conf --- .gitignore | 3 ++ data/nginx/nginx.test.conf | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 data/nginx/nginx.test.conf diff --git a/.gitignore b/.gitignore index d2d1af67..4feb86b2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ frontend/cypress/videos/* !data/nginx/ssl/.gitkeep +!data/nginx/nginx.dev.conf +!data/nginx/nginx.test.conf +!data/nginx/nginx.prod.conf diff --git a/data/nginx/nginx.test.conf b/data/nginx/nginx.test.conf new file mode 100644 index 00000000..e8fcaae2 --- /dev/null +++ b/data/nginx/nginx.test.conf @@ -0,0 +1,69 @@ +events { + worker_connections 1024; +} + +http { + upstream backend { + server test_backend:8080; + } + + upstream frontend { + server test_frontend:5173; + } + + upstream hmr { + server test_frontend:443; + } + + server { + listen 80; + listen [::]:80; + + location / { + return 301 https://$host$request_uri; + } + } + + server { + listen 8080 ssl; + listen [::]:8080 ssl; + + ssl_certificate ssl/certificate.crt; + ssl_certificate_key ssl/private.key; + + location / { + return 301 https://$host$request_uri; + } + } + + server { + listen 443 ssl; + listen [::]:443 ssl; + + ssl_certificate ssl/certificate.crt; + ssl_certificate_key ssl/private.key; + + location /api/ { + proxy_pass https://backend$request_uri; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + + location /hmr { + proxy_pass http://hmr; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } + + + location / { + proxy_pass http://frontend; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + } + } +}