diff --git a/development.sh b/development.sh index a4e62ae1..fdf0e030 100755 --- a/development.sh +++ b/development.sh @@ -3,9 +3,8 @@ backend=false frontend=false build=false -test=false -while getopts ":bfct" opt; do +while getopts ":bfc" opt; do case ${opt} in b ) backend=true @@ -16,9 +15,6 @@ while getopts ":bfct" opt; do c ) build=true ;; - t ) - test=true - ;; \? ) echo "Usage: $0 [-b] [-f] [-c]" exit 1 @@ -59,22 +55,17 @@ fi echo "Starting services..." docker-compose -f development.yml up -d -if [ "$test" = true ]; then - echo "Running tests..." - docker-compose -f development.yml exec backend python manage.py test -else - echo "-------------------------------------" - echo "Following logs..." - echo "Press CTRL + C to stop all containers" - echo "-------------------------------------" +echo "-------------------------------------" +echo "Following logs..." +echo "Press CTRL + C to stop all containers" +echo "-------------------------------------" - if [ "$backend" = true ] && [ "$frontend" = true ]; then - docker-compose -f development.yml logs --follow --tail 50 backend frontend - elif [ "$frontend" = true ]; then - docker-compose -f development.yml logs --follow --tail 50 frontend - else - docker-compose -f development.yml logs --follow --tail 50 backend - fi +if [ "$backend" = true ] && [ "$frontend" = true ]; then + docker-compose -f development.yml logs --follow --tail 50 backend frontend +elif [ "$frontend" = true ]; then + docker-compose -f development.yml logs --follow --tail 50 frontend +else + docker-compose -f development.yml logs --follow --tail 50 backend fi echo "Cleaning up..." diff --git a/test.sh b/test.sh new file mode 100755 index 00000000..a70f382a --- /dev/null +++ b/test.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +backend=false +frontend=false +build=false + +while getopts ":bfc" opt; do + case ${opt} in + b ) + backend=true + ;; + f ) + frontend=true + ;; + c ) + build=true + ;; + \? ) + echo "Usage: $0 [-b] [-f] [-c]" + exit 1 + ;; + esac +done + +echo "Checking environment file..." + +if ! [ -f .env ]; then + cp .dev.env .env + sed -i "s/^DJANGO_SECRET_KEY=.*/DJANGO_SECRET_KEY=totally_random_key_string/" .env + echo "Created environment file" +fi + +echo "Checking for existing SSL certificates..." + +if [ ! -f "data/nginx/ssl/private.key" ] || [ ! -f "data/nginx/ssl/certificate.crt" ]; then + echo "Generating SSL certificates..." + sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ + -keyout data/nginx/ssl/private.key \ + -out data/nginx/ssl/certificate.crt \ + -subj "/C=BE/ST=/L=/O=/OU=/CN=" > /dev/null + echo "SSL certificates generated." +else + echo "SSL certificates already exist, skipping generation." +fi + +if [ "$build" = true ]; then + echo "Building Docker images..." + echo "This can take a while..." + docker-compose -f testing.yml build --no-cache +else + echo "$build" +fi + +echo "Starting services..." +docker-compose -f testing.yml up -d + +if [ "$frontend" = true ]; then + echo "Running frontend tests..." + echo "Not implemented yet" +fi + +if [ "$backend" = true ]; then + echo "Running backend tests..." + docker-compose -f testing.yml exec backend python manage.py test +fi + +echo "Cleaning up..." + +docker-compose -f testing.yml down + +echo "Done." diff --git a/testing.yml b/testing.yml new file mode 100644 index 00000000..1c6dbf00 --- /dev/null +++ b/testing.yml @@ -0,0 +1,98 @@ +version: "3.9" + +############################# NETWORKS + +networks: + selab_network: + name: selab_network + driver: bridge + ipam: + config: + - subnet: 192.168.90.0/24 + +############################# EXTENSIONS + +x-common-keys-selab: &common-keys-selab + networks: + - selab_network + security_opt: + - no-new-privileges:true + restart: unless-stopped + environment: + TZ: $TZ + PUID: $PUID + PGID: $PGID + env_file: + - .env + +############################# SERVICES + +services: + + nginx: + <<: *common-keys-selab + image: nginx:latest + container_name: nginx + expose: + - 80 + - 443 + - 8080 + volumes: + - ${DATA_DIR}/nginx/nginx.dev.conf:/etc/nginx/nginx.conf:ro + - ${SSL_DIR}:/etc/nginx/ssl:ro + depends_on: + - backend + - frontend + + backend: + <<: *common-keys-selab + container_name: backend + build: + context: $BACKEND_DIR + dockerfile: Dockerfile.dev + command: /bin/bash -c "./setup.sh && python manage.py runsslserver 192.168.90.2:8080" + expose: + - 8080 + volumes: + - $BACKEND_DIR:/code + + celery: + <<: *common-keys-selab + container_name: celery + build: + context: $BACKEND_DIR + dockerfile: Dockerfile.dev + command: celery -A ypovoli worker -l DEBUG + volumes: + - $BACKEND_DIR:/code + depends_on: + - backend + - redis + + frontend: + <<: *common-keys-selab + container_name: frontend + build: + context: $FRONTEND_DIR + dockerfile: Dockerfile.dev + command: bash -c "npm install && npm run host" + expose: + - 5173 + volumes: + - $FRONTEND_DIR:/app + depends_on: + - backend + + redis: + <<: *common-keys-selab + container_name: redis + image: redis:latest + networks: + selab_network: + ipv4_address: $REDIS_IP + expose: + - $REDIS_PORT + entrypoint: redis-server --appendonly yes --maxmemory 512mb --maxmemory-policy allkeys-lru + volumes: + - ${DATA_DIR}/redis:/data + \ No newline at end of file