Skip to content

Commit

Permalink
feat: Improve deployment configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
drorganvidez committed Mar 21, 2024
1 parent f1a0dfc commit d9839a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 43 deletions.
18 changes: 9 additions & 9 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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
44 changes: 22 additions & 22 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,39 @@ version: '3.8'

services:
web:
container_name: web_app_container
image: drorganvidez/uvlhub:latest
volumes:
- .:/app
ports:
- "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
Expand All @@ -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
Expand All @@ -57,7 +57,7 @@ services:

certbot:
image: certbot/certbot
container_name: certbot
container_name: certbot_container
volumes:
- ./public:/var/www:rw
- ./letsencrypt:/etc/letsencrypt
Expand Down
11 changes: 0 additions & 11 deletions nginx/nginx.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ http {
server web:5000;
}

upstream flamapyapi {
server flamapyapi:8000;
}

server {
listen 80;
server_name uvlhub.io;
Expand Down Expand Up @@ -49,11 +45,4 @@ http {
}
}

server {
listen 8000;

location / {
proxy_pass http://flamapyapi;
}
}
}

0 comments on commit d9839a5

Please sign in to comment.