From 6e33a18629794e9a09298e7bafecd73d5f548193 Mon Sep 17 00:00:00 2001 From: Rafael Germano <149633206+RafaelGermano05@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:24:19 -0300 Subject: [PATCH 1/4] Update Dockerfile for psycopg2 and gunicorn --- Dockerfile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 937a75d..485a4a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,22 @@ -# Use uma imagem oficial do Python FROM python:3.10-slim -# Defina o diretório de trabalho dentro do container +# Instalar dependências do sistema para psycopg2 +RUN apt-get update && apt-get install -y \ + gcc \ + postgresql-client \ + libpq-dev \ + && rm -rf /var/lib/apt/lists/* + WORKDIR /app -# Copie os arquivos de requirements e instale as dependências COPY requirements.txt . RUN pip install --upgrade pip -RUN pip install -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt -# Copie todo o projeto para dentro do container COPY . . -# Exponha a porta que o Django vai rodar -EXPOSE 8000 +# Coletar static files ANTES de rodar +RUN python manage.py collectstatic --noinput -# Comando para rodar o servidor Django -CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] +# Não exponha porta fixa - Railway usa $PORT +CMD ["gunicorn", "argus_ia.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120"] From 1ffd95438fec3c760202fc3479ebfaaed555067d Mon Sep 17 00:00:00 2001 From: Rafael Germano <149633206+RafaelGermano05@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:27:41 -0300 Subject: [PATCH 2/4] Update database settings for Railway deployment --- argus_ia/settings.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/argus_ia/settings.py b/argus_ia/settings.py index 176411f..8b1577f 100644 --- a/argus_ia/settings.py +++ b/argus_ia/settings.py @@ -56,19 +56,17 @@ # Database Configuration # DATABASES -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} +import dj_database_url -if 'DATABASE_URL' in os.environ: - import dj_database_url - DATABASES['default'] = dj_database_url.config( +# Database +DATABASES = { + 'default': dj_database_url.config( + default='sqlite:///db.sqlite3', # Fallback para desenvolvimento conn_max_age=600, - ssl_require=False + conn_health_checks=True, + ssl_require=True ) +} # Password validation AUTH_PASSWORD_VALIDATORS = [ @@ -116,9 +114,20 @@ 'https://*.railway.app' ] +# Porta dinâmica para Railway +if 'RAILWAY_ENVIRONMENT' in os.environ or 'DATABASE_URL' in os.environ: + # Configurações específicas para produção no Railway + import django_heroku + django_heroku.settings(locals(), databases=False) + + # Ajuste ALLOWED_HOSTS dinamicamente + railway_app_name = os.environ.get('RAILWAY_STATIC_URL', '').replace('https://', '').replace('http://', '') + if railway_app_name: + ALLOWED_HOSTS.append(railway_app_name) + # if not DEBUG: # SECURE_SSL_REDIRECT = True # SESSION_COOKIE_SECURE = True # CSRF_COOKIE_SECURE = True # SECURE_BROWSER_XSS_FILTER = True -# SECURE_CONTENT_TYPE_NOSNIFF = True \ No newline at end of file +# SECURE_CONTENT_TYPE_NOSNIFF = True From d12237441fe758f70694fecc769c2e88d3d06b5f Mon Sep 17 00:00:00 2001 From: Rafael Germano <149633206+RafaelGermano05@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:34:13 -0300 Subject: [PATCH 3/4] Refactor database settings and remove Railway config --- argus_ia/settings.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/argus_ia/settings.py b/argus_ia/settings.py index 8b1577f..564604a 100644 --- a/argus_ia/settings.py +++ b/argus_ia/settings.py @@ -56,17 +56,19 @@ # Database Configuration # DATABASES -import dj_database_url - -# Database DATABASES = { - 'default': dj_database_url.config( - default='sqlite:///db.sqlite3', # Fallback para desenvolvimento + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + +if 'DATABASE_URL' in os.environ: + import dj_database_url + DATABASES['default'] = dj_database_url.config( conn_max_age=600, - conn_health_checks=True, - ssl_require=True + ssl_require=False ) -} # Password validation AUTH_PASSWORD_VALIDATORS = [ @@ -114,17 +116,6 @@ 'https://*.railway.app' ] -# Porta dinâmica para Railway -if 'RAILWAY_ENVIRONMENT' in os.environ or 'DATABASE_URL' in os.environ: - # Configurações específicas para produção no Railway - import django_heroku - django_heroku.settings(locals(), databases=False) - - # Ajuste ALLOWED_HOSTS dinamicamente - railway_app_name = os.environ.get('RAILWAY_STATIC_URL', '').replace('https://', '').replace('http://', '') - if railway_app_name: - ALLOWED_HOSTS.append(railway_app_name) - # if not DEBUG: # SECURE_SSL_REDIRECT = True # SESSION_COOKIE_SECURE = True From 95eb379e9cec29d0babdcbeaf069eadd0a56fcb3 Mon Sep 17 00:00:00 2001 From: Amanda Date: Tue, 9 Dec 2025 14:35:02 -0300 Subject: [PATCH 4/4] feat/add-pipeline --- .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1ffb50d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI - Argus IA + +on: + push: + branches: [ "main", "develop" ] + pull_request: + branches: [ "main", "develop" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout do código + uses: actions/checkout@v3 + + - name: Configurar Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Instalar dependências + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt || true + + - name: Rodar testes (opcional – se adicionar testes) + run: | + echo "Nenhum teste configurado por enquanto" + continue-on-error: true + + - name: Build Docker + uses: docker/setup-buildx-action@v2 + + - name: Construir imagem Docker + run: | + docker build -t argusia . + + - name: Verificar sucesso do build + run: | + echo "Build do Docker finalizado com sucesso!"