-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from SELab-2/docker
Docker
- Loading branch information
Showing
3 changed files
with
180 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|