diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec220df --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Usar uma imagem base do Python +FROM python:3.10 + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + net-tools \ + inetutils-ping \ + inetutils-traceroute \ + nano \ + vim-nox \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt /app/ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . /app/ + +RUN chmod +x /app/init.sh +RUN chmod +x /app/entrypoint.sh +ARG SERVER_ADDRESS +ARG DEBUG_MODE +ENTRYPOINT ["/app/entrypoint.sh"] + +CMD ["/app/init.sh"] \ No newline at end of file diff --git a/containers/cron/Dockerfile-cron b/containers/cron/Dockerfile-cron new file mode 100644 index 0000000..01e9dc9 --- /dev/null +++ b/containers/cron/Dockerfile-cron @@ -0,0 +1,16 @@ +FROM ubuntu:latest + +# Instalar cron +RUN apt-get update && apt-get install -y cron curl + +# Adicionar seus scripts de cron +COPY cron_tasks /etc/cron.d/cron_tasks + +# Dar permissões apropriadas +RUN chmod 0644 /etc/cron.d/cron_tasks + +# Criar um arquivo de log para armazenar os resultados do cron +RUN touch /var/log/cron.log + +# Executar o cron em primeiro plano +CMD cron -f \ No newline at end of file diff --git a/containers/cron/cron_tasks b/containers/cron/cron_tasks new file mode 100644 index 0000000..18e8c62 --- /dev/null +++ b/containers/cron/cron_tasks @@ -0,0 +1,5 @@ +* * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/check_updates/ >> /var/log/cron.log 2>&1 +*/5 * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/generate_backup_schedule/ >> /var/log/cron.log 2>&1 +* * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/create_backup_tasks/ >> /var/log/cron.log 2>&1 +* * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/perform_backup_tasks/ >> /var/log/cron.log 2>&1 +*/10 * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/housekeeping/ >> /var/log/cron.log 2>&1 \ No newline at end of file diff --git a/containers/monitoring/Dockerfile-monitoring b/containers/monitoring/Dockerfile-monitoring new file mode 100644 index 0000000..63a404c --- /dev/null +++ b/containers/monitoring/Dockerfile-monitoring @@ -0,0 +1,17 @@ +FROM python:3.10 +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + net-tools \ + inetutils-ping \ + inetutils-traceroute \ + nano \ + vim-nox \ + fping \ + && rm -rf /var/lib/apt/lists/* \ + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY monitoring.py . + +CMD ["python", "-u", "monitoring.py"] diff --git a/containers/monitoring/monitoring.py b/containers/monitoring/monitoring.py index 77500c7..74f2e90 100644 --- a/containers/monitoring/monitoring.py +++ b/containers/monitoring/monitoring.py @@ -7,8 +7,8 @@ from subprocess import Popen, PIPE UPDATE_HOST_LIST_INTERVAL = 600 # How often to update the router list in seconds MONITOR_INTERVAL = 60 # How often to monitor each router in seconds MAX_NOTIFICATIONS_PER_MONITOR_INTERVAL = 50 # Throttle the number of notifications sent to the remote API -HOST_LIST_URL = "http://127.0.0.1:8000/monitoring/export_router_list/" -UPDATE_STATUS_URL = "http://127.0.0.1:8000/monitoring/update_router_status/" +HOST_LIST_URL = "http://routerfleet:8001/monitoring/export_router_list/" +UPDATE_STATUS_URL = "http://routerfleet:8001/monitoring/update_router_status/" DEBUG = False # Global variables diff --git a/containers/nginx/Dockerfile-nginx b/containers/nginx/Dockerfile-nginx new file mode 100644 index 0000000..c056122 --- /dev/null +++ b/containers/nginx/Dockerfile-nginx @@ -0,0 +1,6 @@ +FROM nginx:alpine +RUN apk --no-cache add openssl +COPY nginx_entrypoint.sh /nginx_entrypoint.sh +RUN chmod +x /nginx_entrypoint.sh +ENTRYPOINT ["/nginx_entrypoint.sh"] +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/containers/nginx/nginx_entrypoint.sh b/containers/nginx/nginx_entrypoint.sh new file mode 100644 index 0000000..b42a32e --- /dev/null +++ b/containers/nginx/nginx_entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +CERT_DIR="/certificate" + +if [ ! -f "$CERT_DIR/nginx.key" ] || [ ! -f "$CERT_DIR/nginx.pem" ]; then + echo "Creating self signed certificate..." + openssl req -x509 -newkey rsa:4096 -nodes -keyout "$CERT_DIR/nginx.key" -out "$CERT_DIR/nginx.pem" -days 3650 -subj "/CN=localhost" +else + echo "Skipping self signed certificate creation, files already exist." +fi + +exec "$@" \ No newline at end of file diff --git a/containers/nginx/virtualhost.conf b/containers/nginx/virtualhost.conf new file mode 100644 index 0000000..e90232c --- /dev/null +++ b/containers/nginx/virtualhost.conf @@ -0,0 +1,25 @@ +server { + listen 80; + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl; + ssl_certificate /certificate/nginx.pem; + ssl_certificate_key /certificate/nginx.key; + + # if you are using cloudflare, you can use this enable authenticated origin pull. Dont forget to activate it in cloudflare + #ssl_client_certificate /certificate/cloudflare_authenticated_origin_pull_ca.pem; + #ssl_verify_client on; + + location /static/ { + alias /static/; + } + + location / { + proxy_pass http://routerfleet:8001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b3790e7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: '3' +services: + routerfleet: + container_name: routerfleet + restart: unless-stopped + build: + context: . + environment: + - SERVER_ADDRESS=${SERVER_ADDRESS} + - DEBUG_MODE=${DEBUG_MODE} + volumes: + - media_root:/var/lib/routerfleet/ + - static_volume:/app_static_files/ + command: /bin/bash /app/init.sh + + routerfleet-cron: + container_name: routerfleet-cron + restart: unless-stopped + build: + context: ./containers/cron + dockerfile: Dockerfile-cron + depends_on: + - routerfleet + + nginx: + container_name: routerfleet-nginx + restart: unless-stopped + image: nginx:alpine + build: + context: . + dockerfile: Dockerfile_nginx + volumes: + - ./containers/nginx/virtualhost.conf:/etc/nginx/conf.d/routerfleet.conf + - static_volume:/static + - https_cert:/certificate + ports: + - "80:80" + - "443:443" + +volumes: + static_volume: + https_cert: + media_root: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..450237b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +if [ -z "$SERVER_ADDRESS" ]; then + echo "SERVER_ADDRESS environment variable is not set. Exiting." + exit 1 +fi + +DEBUG_VALUE="False" +if [[ "${DEBUG_MODE,,}" == "true" ]]; then + DEBUG_VALUE="True" +fi + +cat > /app/routerfleet/production_settings.py <