Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MatielloAL committed Jun 11, 2024
2 parents 36c1fd0 + f01e553 commit ade1a01
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 68 deletions.
50 changes: 50 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
*.pyc
*.pyo
*.pyd
__pycache__
*.swp
*.bak
*.tmp
*.db
*.sqlite3
*.sqlite

# Diretórios do Django
driverplan/media
driverplan/static
driverplan/__pycache__
driverplan/*.log
driverplan/*.pot

# Arquivos e diretórios comuns a serem ignorados
.DS_Store
Thumbs.db
.env
.venv
venv
ENV
env
build
dist
eggs
parts
sdist
var
*.egg-info
.installed.cfg
*.egg

# Arquivos e diretórios de configuração do editor/IDE
.idea
.vscode
*.sublime-workspace

# Diretório de testes
htmlcov
.coverage
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/djangoapp/static/
/djangoapp/media/
/djangoapp/project/local_settings.py
gunicorn-error-log
__localcode
/data/

# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
# db.sqlite3 ---> modificar (pois será mudado para postegreSQL)

# Backup files #
*.bak

# If you are using PyCharm #
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# File-based project format
*.iws

# IntelliJ
out/

# JIRA plugin
atlassian-ide-plugin.xml

# Python #
*.py[cod]
*$py.class

# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery
celerybeat-schedule.*

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Sublime Text #
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files Package
Control.last-run
Control.ca-list
Control.ca-bundle
Control.system-ca-bundle
GitHub.sublime-settings

# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
76 changes: 62 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
FROM python:3.9
SHELL ["/bin/bash", "-c"]
# Set environment variables
FROM python:3.12.3-alpine3.20
LABEL mantainer="[email protected]"

# SHELL ["/bin/bash", "-c"]

# Essa variável de ambiente é usada para controlar se o Python deve
# gravar arquivos de bytecode (.pyc) no disco. 1 = Não, 0 = Sim
ENV PYTHONDONTWRITEBYTECODE 1

# Define que a saída do Python será exibida imediatamente no console ou em
# outros dispositivos de saída, sem ser armazenada em buffer.
# Em resumo, você verá os outputs do Python em tempo real.
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

# RUN mkdir -p /app

# Copia a pasta "driverplan" e "scripts" para dentro do container
COPY driverplan /driverplan
COPY scripts /scripts
# COPY driverplan/manage.py /app
# COPY driverplan/requirements.txt /app
# COPY driverplan/driverplan /app/driverplan

# Entra na pasta driverplan no container
WORKDIR /driverplan

# A porta 800 estará disponível para conexões externas ao container
# É a porta que será usada para o django
EXPOSE 8000

# RUN executa comandos em um shell dentro do container para construir a imagem.
# O resultado da execução do comando é armazenado no sistema de arquivos da
# imagem como uma nova camada.
# Agrupar os comandos em um único RUN pode reduzir a quantidade de camadas da
# imagem e torná-la mais eficiente.
RUN python -m venv /venv && \
/venv/bin/pip install --upgrade pip && \
/venv/bin/pip install -r /driverplan/requirements.txt && \
adduser --disabled-password --no-create-home duser && \
mkdir -p /data/web/static && \
mkdir -p /data/web/media && \
chown -R duser:duser /venv && \
chown -R duser:duser /data/web/static && \
chown -R duser:duser /data/web/media && \
chmod -R 755 /data/web/static && \
chmod -R 755 /data/web/media && \
chmod -R +x /scripts

#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

# Adiciona a pasta scripts e venv/bin
# no $PATH do container.
ENV PATH="/scripts:/venv/bin:$PATH"

# Mudar o usuário para duser
USER duser

# 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

CMD ["commands.sh"]
Binary file modified DrivePlanSite/DrivePlanSite/__pycache__/urls.cpython-312.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions DrivePlanSite/DrivePlanSite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('maps.urls')),
]

if settings.DEBUG:
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT
)
26 changes: 0 additions & 26 deletions comandos

This file was deleted.

26 changes: 0 additions & 26 deletions docker-compose.yaml

This file was deleted.

26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.9'

services:
driverplan:
container_name: driverplan
build:
context: .
# infomrar caminho do docker file (caso necessario): <./Dockerfile>
ports:
- 8000:8000
volumes:
- ./driverplan:/driverplan
- ./data/web/static:/data/web/static/
- ./data/web/media:/data/web/media/
env_file:
- ./dotenv_files/.env
depends_on:
- psql
psql:
container_name: psql
image: postgres:13-alpine
volumes:
- ./data/postgres/data:/var/lib/postgresql/data/
env_file:
- ./dotenv_files/.env

16 changes: 16 additions & 0 deletions dotenv_files/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SECRET_KEY="CHANGE-ME"
# gerador de senha de 50 digitos pela função interna do Django
# python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"

# 0 False, 1 True
DEBUG="1"

# Comma Separated values
ALLOWED_HOSTS="127.0.0.1, localhost"

DB_ENGINE="django.db.backends.postgresql"
POSTGRES_DB="CHANGE-ME"
POSTGRES_USER="CHANGE-ME"
POSTGRES_PASSWORD="CHANGE-ME"
POSTGRES_HOST="localhost" # localhost -> no servidor; "psql" -> hostname
POSTGRES_PORT="5432"
Loading

0 comments on commit ade1a01

Please sign in to comment.