Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: production down when tests being run #246

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 69 additions & 0 deletions data/nginx/nginx.test.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
6 changes: 3 additions & 3 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -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}',
},
});
17 changes: 10 additions & 7 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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!"
Expand Down
54 changes: 27 additions & 27 deletions test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading