Skip to content

Commit ccbb951

Browse files
Merge pull request #946 from basedosdados/feat/chatbot
feat: chatbot to staging
2 parents f85f47f + 342059f commit ccbb951

File tree

74 files changed

+7707
-663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+7707
-663
lines changed

.env.docker

Lines changed: 0 additions & 22 deletions
This file was deleted.

.env.example

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
1-
# Mail notifications
2-
ADMINS="Gabriel Milan,[email protected]"
3-
EMAIL_HOST_USER="[email protected]"
4-
EMAIL_HOST_PASSWORD="password"
5-
# Django configurations
6-
DJANGO_SECRET_KEY="some-secret"
7-
DJANGO_SETTINGS_MODULE="backend.settings.local"
1+
# =============================================================================
2+
# ESSENTIAL SETTINGS FOR DEVELOPMENT
3+
# =============================================================================
4+
5+
# Django
6+
DJANGO_SECRET_KEY=dev-secret-key-change-in-production
7+
DJANGO_SETTINGS_MODULE=backend.settings.local
8+
9+
# Database (configured for Docker - do not change if using docker compose)
10+
DB_HOST=database
11+
DB_PORT=5432
12+
DB_NAME=postgres
13+
DB_USER=postgres
14+
DB_PASSWORD=postgres
15+
16+
# Queue (configured for Docker - do not change if using docker compose)
17+
REDIS_HOST=queue
18+
REDIS_PORT=6379
19+
20+
# Search Index (configured for Docker - do not change if using docker compose)
21+
ELASTICSEARCH_URL=http://index:9200
22+
823
# Logger
9-
LOGGER_LEVEL="DEBUG"
10-
LOGGER_IGNORE="faker,haystack"
11-
LOGGER_SERIALIZE=""
12-
# Database
13-
DB_HOST="localhost"
14-
DB_PORT="5432"
15-
DB_NAME="postgres"
16-
DB_USER="postgres"
17-
DB_PASSWORD="postgres"
18-
# Queue
19-
REDIS_HOST="localhost"
20-
REDIS_PORT="6379"
21-
# Index
22-
ELASTICSEARCH_URL=http://localhost:9200
23-
# Google
24-
GOOGLE_OAUTH_CLIENT_ID="google_key"
25-
GOOGLE_OAUTH_CLIENT_SECRET="google_secret"
24+
LOGGER_LEVEL=DEBUG
25+
LOGGER_IGNORE=faker,haystack
26+
LOGGER_SERIALIZE=
27+
28+
# =============================================================================
29+
# OPTIONAL SETTINGS FOR DEVELOPMENT
30+
# =============================================================================
31+
32+
# Mail notifications (only required if testing email sending)
33+
# ADMINS=Your Name,[email protected]
34+
35+
# EMAIL_HOST_PASSWORD=your-app-password
36+
37+
# Google authentication
38+
# GOOGLE_OAUTH_CLIENT_ID="google_key"
39+
# GOOGLE_OAUTH_CLIENT_SECRET="google_secret"
40+
41+
# Chatbot (only required if working with chatbot functionality)
42+
# Requires Google Cloud Platform credentials with BigQuery access
43+
# CHATBOT_CREDENTIALS=/app/credentials/service_account.json
44+
# BIGQUERY_PROJECT_ID=your-gcp-project
45+
# BASE_URL_BACKEND=http://localhost:8000
46+
# LANGSMITH_TRACING=true
47+
# LANGSMITH_API_KEY=your-langsmith-api-key
48+
# LANGSMITH_PROJECT=your-langsmith-project-name
49+
# For load testing only
50+
# MOCK_AGENT=false
51+
52+
# CHATBOT_USER_PASSWORD=examplepassword
53+
54+
# Local DB populating (only required to populate local database with production data)
55+
# METABASE_USER=your-metabase-user
56+
# METABASE_PASSWORD=your-metabase-password

.github/workflows/ci-python.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ jobs:
1111
- name: Checkout
1212
uses: actions/checkout@v4
1313
- name: Lint source code
14-
uses: chartboost/ruff-action@v1
14+
uses: astral-sh/ruff-action@v3
15+
with:
16+
version: "0.14.9"
1517
test:
1618
name: Test python
1719
runs-on: ubuntu-latest

.github/workflows/deploy-dev.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88
jobs:
99
deploy-dev:
1010
runs-on: ubuntu-latest
11-
if: |
12-
${{ github.event_name == 'workflow_dispatch' }}
13-
|| ${{ github.event.workflow_run.conclusion == 'success' }}
11+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
1412
environment:
1513
name: development
1614
url: https://api.development.basedosdados.org
@@ -56,10 +54,10 @@ jobs:
5654
resources:
5755
limits:
5856
cpu: 500m
59-
memory: 4096Mi
57+
memory: 2Gi
6058
requests:
6159
cpu: 250m
62-
memory: 1536Mi
60+
memory: 1.5Gi
6361
envFrom:
6462
- secretRef:
6563
name: api-development-secrets
@@ -87,8 +85,8 @@ jobs:
8785
run: |-
8886
helm upgrade \
8987
--wait \
90-
--timeout 15m \
9188
--install \
89+
--timeout 10m \
9290
--namespace website \
9391
--values values.yaml \
9492
api-dev charts/basedosdados-api/.

.github/workflows/deploy-prod.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88
jobs:
99
deploy-prod:
1010
runs-on: ubuntu-latest
11-
if: |
12-
${{ github.event_name == 'workflow_dispatch' }}
13-
|| ${{ github.event.workflow_run.conclusion == 'success' }}
11+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
1412
environment:
1513
name: production
1614
url: https://backend.basedosdados.org
@@ -56,10 +54,10 @@ jobs:
5654
resources:
5755
limits:
5856
cpu: 1000m
59-
memory: 1536Mi
57+
memory: 4Gi
6058
requests:
6159
cpu: 500m
62-
memory: 1024Mi
60+
memory: 2Gi
6361
envFrom:
6462
- secretRef:
6563
name: api-prod-secrets
@@ -88,6 +86,7 @@ jobs:
8886
helm upgrade \
8987
--wait \
9088
--install \
89+
--timeout 10m \
9190
--namespace website \
9291
--values values.yaml \
9392
api-prod charts/basedosdados-api/.

.github/workflows/deploy-staging.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88
jobs:
99
deploy-staging:
1010
runs-on: ubuntu-latest
11-
if: |
12-
${{ github.event_name == 'workflow_dispatch' }}
13-
|| ${{ github.event.workflow_run.conclusion == 'success' }}
11+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
1412
environment:
1513
name: staging
1614
url: https://staging.backend.basedosdados.org
@@ -56,10 +54,10 @@ jobs:
5654
resources:
5755
limits:
5856
cpu: 500m
59-
memory: 1Gi
57+
memory: 2Gi
6058
requests:
6159
cpu: 250m
62-
memory: 500Mi
60+
memory: 1.5Gi
6361
envFrom:
6462
- secretRef:
6563
name: api-staging-secrets
@@ -88,6 +86,7 @@ jobs:
8886
helm upgrade \
8987
--wait \
9088
--install \
89+
--timeout 10m \
9190
--namespace website \
9291
--values values.yaml \
9392
api-staging charts/basedosdados-api/.

.github/workflows/release-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
registry: ghcr.io
1919
username: ${{ github.repository_owner }}
2020
password: ${{ secrets.GITHUB_TOKEN }}
21-
- name: Build and push PR image
21+
- name: Build and push development tagged image
2222
uses: docker/build-push-action@v2
2323
with:
2424
context: .

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,6 @@ fixtures*
256256

257257
# Version manager
258258
.tool-versions
259+
260+
# fetch_metabase script
261+
metabase_data

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ repos:
1919
hooks:
2020
- id: poetry-check
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.2.0
22+
rev: v0.14.9
2323
hooks:
24-
- id: ruff
24+
- id: ruff-check
2525
args: [--fix]
2626
- id: ruff-format
2727
- repo: https://github.com/tconbeer/sqlfmt
28-
rev: v0.20.0
28+
rev: v0.28.2
2929
hooks:
3030
- id: sqlfmt
3131
language_version: python
@@ -36,4 +36,5 @@ repos:
3636
name: yamlfix
3737
types: [yaml]
3838
language: system
39-
entry: yamlfix --exclude "charts/**/*" .
39+
entry: yamlfix
40+
exclude: ^charts/

Dockerfile

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
ARG PYTHON_VERSION=3.11-slim
22

3-
FROM python:${PYTHON_VERSION}
3+
FROM python:$PYTHON_VERSION
44

5-
# Install virtualenv and create a virtual environment
6-
RUN pip install --no-cache-dir -U virtualenv>=20.13.1 && virtualenv /env --python=python3.11
7-
ENV PATH /env/bin:$PATH
5+
# Set shell with pipefail for safer pipe operations
6+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
87

9-
# Install pip requirements
10-
WORKDIR /app
11-
COPY . .
12-
RUN /env/bin/pip install --no-cache-dir . && rm nginx.conf
8+
# Define where Poetry virtual environments will be stored
9+
ARG POETRY_VIRTUALENVS_PATH=/opt/pypoetry/virtualenvs
10+
11+
# Ensure that the python output is sent straight to terminal (e.g. your container log)
12+
# without being first buffered and that you can see the output of your application (e.g. django logs)
13+
# in real time. Equivalent to python -u: https://docs.python.org/3/using/cmdline.html#cmdoption-u
14+
ENV PYTHONUNBUFFERED=1
15+
16+
# Prevent Python from writing .pyc files to disc
17+
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE
18+
ENV PYTHONDONTWRITEBYTECODE=1
1319

1420
# Install make, nginx and copy configuration
1521
RUN apt-get update \
@@ -20,20 +26,26 @@ RUN apt-get update \
2026
RUN apt-get update && apt-get install -y postgresql postgresql-contrib
2127
COPY nginx.conf /etc/nginx/nginx.conf
2228

23-
# Prevents Python from writing .pyc files to disc
24-
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE
25-
ENV PYTHONDONTWRITEBYTECODE 1
29+
# Install Poetry and add it to PATH so its commands can be executed
30+
# from anywhere, without specifying the full path to its executable.
31+
RUN curl -sSL https://install.python-poetry.org | python3 - --version 2.1.3
32+
ENV PATH="/root/.local/bin:$PATH"
2633

27-
# Ensures that the python output is sent straight to terminal (e.g. your container log)
28-
# without being first buffered and that you can see the output of your application (e.g. django logs)
29-
# in real time. Equivalent to python -u: https://docs.python.org/3/using/cmdline.html#cmdoption-u
30-
ENV PYTHONUNBUFFERED 1
34+
# Create the folder where Poetry virtual environments will be stored and make it
35+
# accessible to all users. This is needed by the 'www-data' user during server startup
36+
RUN mkdir -p $POETRY_VIRTUALENVS_PATH && chmod 755 $POETRY_VIRTUALENVS_PATH
37+
ENV POETRY_VIRTUALENVS_PATH=$POETRY_VIRTUALENVS_PATH
38+
39+
# Copy and install project
40+
WORKDIR /app
41+
COPY . .
42+
RUN poetry install --only main && rm nginx.conf
3143

32-
# Copy app, generate static and set permissions
33-
RUN /env/bin/python manage.py collectstatic --no-input --settings=backend.settings.base && \
44+
# Generate static and set permissions
45+
RUN poetry run python manage.py collectstatic --no-input --settings=backend.settings.base && \
3446
chown -R www-data:www-data /app
3547

3648
# Expose and run app
3749
EXPOSE 80
3850
STOPSIGNAL SIGKILL
39-
CMD ["/app/start-server.sh"]
51+
CMD ["poetry", "run", "/app/start-server.sh"]

0 commit comments

Comments
 (0)