diff --git a/Dockerfile.dev b/Dockerfile.dev index d33132e8..0c9327e8 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,29 +1,29 @@ # Use an official Python runtime as a parent image FROM python:3.11-alpine -# Instala el cliente de MySQL para poder usarlo en el script de espera +# Install the MySQL client to be able to use it in the standby script. RUN apk add --no-cache mysql-client -# Establece el directorio de trabajo en el contenedor en /app +# Set the working directory in the container to /app WORKDIR /app -# Copia el contenido del directorio local app/ al directorio /app en el contenedor +# Copy the contents of the local app/ directory to the /app directory in the container COPY app/ ./app -# Copia requirements.txt en el directorio de trabajo /app +# Copy requirements.txt at the /app working directory COPY requirements.txt . -# Copia el script wait-for-db.sh y establece los permisos de ejecuciĆ³n +# Copy the wait-for-db.sh script and set execution permissions COPY --chmod=+x scripts/wait-for-db.sh ./scripts/ -# Instala los paquetes necesarios especificados en requirements.txt +# Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt -# Actualiza pip +# Update pip RUN pip install --no-cache-dir --upgrade pip -# Expone el puerto 5000 +# Expose port 5000 EXPOSE 5000 -# Ajusta el comando CMD para ejecutar correctamente el script wait-for-db.sh +# Sets the CMD command to correctly execute the wait-for-db.sh script CMD sh ./scripts/wait-for-db.sh && flask db upgrade && flask run --host=0.0.0.0 --port=5000 --reload --debug diff --git a/Dockerfile.prod b/Dockerfile.prod index aa969245..5bd26405 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -1,6 +1,9 @@ # Use an official Python runtime as a parent image FROM python:3.11-alpine +# Install the MySQL client to be able to use it in the standby script. +RUN apk add --no-cache mysql-client + # Set the working directory in the container to /app WORKDIR /app @@ -10,6 +13,9 @@ COPY app/ ./app # Copy requirements.txt at the /app working directory COPY requirements.txt . +# Copy the wait-for-db.sh script and set execution permissions +COPY --chmod=+x scripts/wait-for-db.sh ./scripts/ + # Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt @@ -23,4 +29,4 @@ COPY migrations/ ./migrations EXPOSE 5000 # Run the database migrations and then start the application with Gunicorn -CMD flask db upgrade && gunicorn --bind 0.0.0.0:5000 app:app --log-level debug --timeout 3600 +CMD sh ./scripts/wait-for-db.sh && flask db upgrade && gunicorn --bind 0.0.0.0:5000 app:app --log-level debug --timeout 3600 diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index bfae7521..4ed88e44 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -2,6 +2,7 @@ version: '3.8' services: web: + container_name: web_app_container image: drorganvidez/uvlhub:latest volumes: - .:/app @@ -9,19 +10,31 @@ services: - "5000:5000" environment: FLASK_ENV: production + MARIADB_HOSTNAME: ${MARIADB_HOSTNAME} + MARIADB_PORT: ${MARIADB_PORT} + MARIADB_USER: ${MARIADB_USER} + MARIADB_PASSWORD: ${MARIADB_PASSWORD} depends_on: - db restart: always - flamapyapi: - image: flamapy/flamapy-fm-dist:v1.5.3 - deploy: - replicas: 3 + db: + container_name: mariadb_container + image: mariadb:latest + command: --default-authentication-plugin=mysql_native_password restart: always - expose: - - 8000 + environment: + MARIADB_DATABASE: ${MARIADB_DATABASE} + MARIADB_USER: ${MARIADB_USER} + MARIADB_PASSWORD: ${MARIADB_PASSWORD} + MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD} + ports: + - "${MARIADB_PORT}:3306" + volumes: + - db_data:/var/lib/mysql nginx: + container_name: nginx_web_server image: nginx:latest volumes: - ./nginx/nginx.prod.conf:/etc/nginx/nginx.conf @@ -31,24 +44,11 @@ services: - "80:80" - "443:443" depends_on: - - flamapyapi - restart: always - - db: - image: mysql:latest - command: --default-authentication-plugin=mysql_native_password + - web restart: always - environment: - MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} - MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} - ports: - - "3306:3306" - volumes: - - db_data:/var/lib/mysql watchtower: + container_name: watchtower_container image: containrrr/watchtower volumes: - /var/run/docker.sock:/var/run/docker.sock @@ -57,7 +57,7 @@ services: certbot: image: certbot/certbot - container_name: certbot + container_name: certbot_container volumes: - ./public:/var/www:rw - ./letsencrypt:/etc/letsencrypt diff --git a/nginx/nginx.prod.conf b/nginx/nginx.prod.conf index 83e7c571..bfeb3d01 100644 --- a/nginx/nginx.prod.conf +++ b/nginx/nginx.prod.conf @@ -5,10 +5,6 @@ http { server web:5000; } - upstream flamapyapi { - server flamapyapi:8000; - } - server { listen 80; server_name uvlhub.io; @@ -49,11 +45,4 @@ http { } } - server { - listen 8000; - - location / { - proxy_pass http://flamapyapi; - } - } }