From 7f558157c1b0205ebeab245ef2101bd71795ab54 Mon Sep 17 00:00:00 2001 From: Samuel Date: Sat, 1 Jun 2024 15:22:05 -0300 Subject: [PATCH] =?UTF-8?q?Adi=C3=A7=C3=A3o=20do=20Docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 17 +++++++++++++++++ comandos | 26 ++++++++++++++++++++++++++ docker-compose.yaml | 26 ++++++++++++++++++++++++++ driverplan/manage.py | 22 ++++++++++++++++++++++ driverplan/requirements.txt | 13 +++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 Dockerfile create mode 100644 comandos create mode 100644 docker-compose.yaml create mode 100755 driverplan/manage.py create mode 100644 driverplan/requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bd3cfb4 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/comandos b/comandos new file mode 100644 index 0000000..9d9cde9 --- /dev/null +++ b/comandos @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..dc910e8 --- /dev/null +++ b/docker-compose.yaml @@ -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 diff --git a/driverplan/manage.py b/driverplan/manage.py new file mode 100755 index 0000000..be8487e --- /dev/null +++ b/driverplan/manage.py @@ -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() diff --git a/driverplan/requirements.txt b/driverplan/requirements.txt new file mode 100644 index 0000000..2c182d1 --- /dev/null +++ b/driverplan/requirements.txt @@ -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