Skip to content

Commit

Permalink
Adição do Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel authored and Samuel committed Jun 1, 2024
1 parent 572f7b3 commit 7f55815
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.9
SHELL ["/bin/bash", "-c"]
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /app
COPY driverplan/manage.py /app
COPY driverplan/requirements.txt /app
COPY driverplan/driverplan /app/driverplan
RUN apt update
RUN apt full-upgrade -y
RUN apt install -y python3 pip pkg-config
RUN apt install -y python3-dev default-libmysqlclient-dev build-essential
WORKDIR /app
RUN pip install Django mysqlclient pyTelegramBotAPI python-decouple
CMD python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8000
EXPOSE 8000
26 changes: 26 additions & 0 deletions comandos
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# antes de tudo, deve-se criar um arquivo .env como no exemplo a seguir:
#### EXEMPLO ####
# Django settings
SECRET_KEY=django-insecure-p************* # senha que está no settings.py
DEBUG=True
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]

# MySQL settings
MARIADB_ROOT_PASSWORD=your-mysql-root-password
MARIADB_DATABASE=your-mysql-database
MARIADB_USER=your-mysql-username
MARIADB_PASSWORD=your-mysql-password
#### EXEMPLO ####
# dar build na imagem do dockerfile
docker build --tag driveplan .
# rodar o docker a partir da imagem gerada pelo dockerfile
docker run -p 127.0.0.1:8000:8000 -it --entrypoint bash driveplan
# vá para a pasta DrivePlan com "cd DrivePlan" e execute:
python3 manage.py runserver 0.0.0.0:8000
# iniciar mysql
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=mydatabase -e MYSQL_USER=myuser -d mysql:latest
# e depois
docker exec -it some-mysql bash
mysql -u root -p -A
# copiar os arq
docker cp DriverPlanSite 9c100cf8fb2a:ap
26 changes: 26 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'
services:
db:
image: mariadb:11.4.2
container_name: project_name_mariadb
restart: always
env_file: .env
ports:
- "3306:3306"
healthcheck:
test: ["CMD", "mysql", "-h", "localhost", "-u", "root", "-p", "${MARIADB_PASSWORD}", "-e", "SELECT 1"]
timeout: 20s
retries: 10

backend:
build:
context: .
dockerfile: Dockerfile
container_name: project_name_backend
restart: always
ports:
- "8000:8000"
env_file:
- .env
depends_on:
- db
22 changes: 22 additions & 0 deletions driverplan/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DrivePlanSite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions driverplan/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
anyio==4.4.0
asgiref==3.8.1
certifi==2024.2.2
charset-normalizer==3.3.2
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
idna==3.7
pyTelegramBotAPI==4.18.1
requests==2.32.3
sniffio==1.3.1
sqlparse==0.5.0
urllib3==2.2.1

0 comments on commit 7f55815

Please sign in to comment.