Skip to content

Commit

Permalink
feat(deployment): testing script
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Mar 30, 2024
1 parent 6ab8d28 commit 7a37491
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 149 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
.venv
.idea
.vscode

data/*
data/nginx/ssl/*
data/postres*
data/redis/*

backend/data/production/*
backend/staticfiles/*

frontend/cypress/screenshots/*
frontend/cypress/videos/*
/node_modules
backend/staticfiles/*


!data/nginx/ssl/.gitkeep
4 changes: 4 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# cypress
cypress/screenshots/*
cypress/videos/*
Empty file removed frontend/.gitkeep
Empty file.
8 changes: 4 additions & 4 deletions frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "https://localhost/",
specPattern: "src/test/e2e/**/*.cy.{js,jsx,ts,tsx}",
},
e2e: {
baseUrl: "https://nginx",
specPattern: "src/test/e2e/**/*.cy.{js,jsx,ts,tsx}",
},
});
Binary file not shown.
74 changes: 37 additions & 37 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"name": "vite-vue-typescript-starter",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"host": "vite --host",
"build": "vue-tsc && vite build",
"preview": "vite preview",
"test": "vitest",
"cypress:open": "cypress open",
"cypress:test": "cypress run"
},
"dependencies": {
"@vueuse/core": "^10.9.0",
"axios": "^1.6.8",
"js-cookie": "^3.0.5",
"moment": "^2.30.1",
"pinia": "^2.1.7",
"primeflex": "^3.3.1",
"primeicons": "^6.0.1",
"primevue": "^3.50.0",
"vue": "^3.4.18",
"vue-i18n": "^9.10.2",
"vue-router": "^4.3.0"
},
"devDependencies": {
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.11.30",
"@vitejs/plugin-vue": "^5.0.4",
"cypress": "^13.7.1",
"sass": "^1.72.0",
"typescript": "^5.2.2",
"vite": "^5.1.1",
"vitest": "^1.4.0",
"vue-tsc": "^1.8.27"
}
"name": "vite-vue-typescript-starter",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"host": "vite --host",
"build": "vue-tsc && vite build",
"preview": "vite preview",
"test": "vitest run",
"cypress:open": "cypress open",
"cypress:test": "cypress run"
},
"dependencies": {
"@vueuse/core": "^10.9.0",
"axios": "^1.6.8",
"js-cookie": "^3.0.5",
"moment": "^2.30.1",
"pinia": "^2.1.7",
"primeflex": "^3.3.1",
"primeicons": "^6.0.1",
"primevue": "^3.50.0",
"vue": "^3.4.18",
"vue-i18n": "^9.10.2",
"vue-router": "^4.3.0"
},
"devDependencies": {
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.11.30",
"@vitejs/plugin-vue": "^5.0.4",
"cypress": "^13.7.1",
"sass": "^1.72.0",
"typescript": "^5.2.2",
"vite": "^5.1.1",
"vitest": "^1.4.0",
"vue-tsc": "^1.8.27"
}
}
60 changes: 51 additions & 9 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ done

echo "Checking environment file..."

if [ "$build" = true ]; then
rm .env > /dev/null 2>&1
fi

if ! [ -f .env ]; then
cp .dev.env .env
sed -i "s/^DJANGO_SECRET_KEY=.*/DJANGO_SECRET_KEY=totally_random_key_string/" .env
Expand All @@ -46,26 +50,64 @@ 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"
docker-compose -f test.yml build --no-cache
fi

echo "Starting services..."
docker-compose -f testing.yml up -d
docker-compose -f test.yml up -d --scale cypress=0

cypress_exit=0
vitest_exit=0
django_exit=0

if [ "$frontend" = true ]; then
echo "Running frontend tests..."
echo "Not implemented yet"
echo "Running Cypress tests..."
docker-compose -f test.yml up --exit-code-from cypress --abort-on-container-exit cypress
cypress_exit=$?
echo "Running Vitest tests..."
docker exec frontend npm run test
vitest_exit=$?
elif [ "$backend" = true ]; then
echo "Running backend tests..."
docker exec backend python manage.py test
django_exit=$?
else
echo "Running backend tests..."
docker exec 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
cypress_exit=$?
echo "Running Vitest tests..."
docker exec frontend npm run test
vitest_exit=$?
fi

if [ "$backend" = true ]; then
echo "Running backend tests..."
docker-compose -f testing.yml exec backend python manage.py test
echo "-----------------"
if [ $cypress_exit -ne 0 ] || [ $vitest_exit -ne 0 ] || [ $django_exit -ne 0 ]; then
echo "Tests failed:"
if [ $cypress_exit -ne 0 ]; then
echo " - Cypress"
fi
if [ $vitest_exit -ne 0 ]; then
echo " - Vitest"
fi
if [ $django_exit -ne 0 ]; then
echo " - Django"
fi
echo "-----------------"
exit 1
else
echo "All tests passed!"
fi
echo "-----------------"

echo "Cleaning up..."

docker-compose -f testing.yml down
docker-compose -f test.yml down

echo "Done."

exit 0
107 changes: 107 additions & 0 deletions test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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

cypress:
<<: *common-keys-selab
container_name: 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
volumes:
- ${FRONTEND_DIR}:/e2e
extra_hosts:
- "host.docker.internal:host-gateway"
Loading

0 comments on commit 7a37491

Please sign in to comment.