Skip to content

Commit

Permalink
Merge pull request #113 from SELab-2/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
EwoutV authored Mar 14, 2024
2 parents 6594064 + 2c5c9aa commit cb03f4b
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 20 deletions.
31 changes: 11 additions & 20 deletions development.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,9 +15,6 @@ while getopts ":bfct" opt; do
c )
build=true
;;
t )
test=true
;;
\? )
echo "Usage: $0 [-b] [-f] [-c]"
exit 1
Expand Down Expand Up @@ -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..."
Expand Down
71 changes: 71 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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."
98 changes: 98 additions & 0 deletions testing.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cb03f4b

Please sign in to comment.