Skip to content

Commit

Permalink
Initial .devcontainers configuration. This feature is still incomplet…
Browse files Browse the repository at this point in the history
…e and has is not documented yet
  • Loading branch information
dpgraham4401 committed Feb 14, 2024
1 parent 4b7ce6c commit 9a9722e
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 37 deletions.
41 changes: 41 additions & 0 deletions .devcontainer/.env.devcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#######################################
# Dev configuration for haztrak

### Django Configs
HT_SECRET_KEY='django-insecure-%btjqoun@6ps$e@8bw$48s+!x1e4aiz&5p2nrf6cmiw4)jsx5d'
HT_HOST=localhost
HT_TIMEZONE=America/New_York
HT_CORS_DOMAIN=http://localhost:3000
HT_RCRAINFO_ENV=preprod
HT_CACHE_URL=redis://redis:6379

### Logging
HT_LOG_LEVEL=INFO
HT_TRAK_LOG_LEVEL=INFO
HT_CORE_LOG_LEVEL=INFO
HT_LOG_FORMAT=verbose
CELERY_LOG_LEVEL=INFO

### Django Database/ORM configs
# see Django docs https://docs.djangoproject.com/en/4.0/ref/databases/ on database drivers
HT_DB_ENGINE=django.db.backends.postgresql
HT_DB_NAME=haztrak_db
HT_DB_USER=admin
HT_DB_PASSWORD='password1'
HT_DB_PORT=5432
HT_DB_HOST=db
DJANGO_SETTINGS_MODULE='haztrak.settings.dev'

### Celery task queue configs
CELERY_RESULT_BACKEND=django-db
CELERY_BROKER_URL=redis://redis:6379

### React App configs
VITE_HT_API_URL=http://localhost:8000
VITE_HT_ENV=DEV
VITE_GITHUB_URL=https://github.com/USEPA/haztrak

### Postgres
POSTGRES_USER=admin
POSTGRES_PASSWORD=password1
POSTGRES_DB=haztrak_db
11 changes: 11 additions & 0 deletions .devcontainer/Trak/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.12.2-bookworm
LABEL maintainer="[email protected]"
ENV APP_DIRECTORY=/app/server
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt install libffi-dev gcc libc-dev
WORKDIR $APP_DIRECTORY
COPY ./server $APP_DIRECTORY
RUN python -m pip install --no-cache-dir --quiet -r requirements.txt
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
22 changes: 22 additions & 0 deletions .devcontainer/Trak/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Python Dev Container",
"dockerComposeFile": ["../docker-compose.yml"],
"service": "trak",
"workspaceFolder": "/app/server",
"customizations": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"vscode": {
"extensions": [
"ms-python.python",
"batisteo.vscode-django",
"streetsidesoftware.code-spell-checker",
"charliermarsh.ruff"
]
}
},
"features": {
"ghcr.io/devcontainers/features/git:1": {}
}
}
94 changes: 94 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: '3.9'
services:
trak:
container_name: trak
build:
context: ..
dockerfile: .devcontainer/Trak/Dockerfile
ports:
- '8000:8000'
env_file:
- .env.devcontainer
volumes:
- ..:/app:cached
command: |
sh -c "
cd ./server &&
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py loaddata dev_data.yaml &&
python manage.py runserver 0.0.0.0:8000"
depends_on:
- db

db:
restart: unless-stopped
container_name: db
image: 'postgres:16'
env_file:
- .env.devcontainer
ports:
- '5432:5432'
volumes:
- rdb:/var/lib/postgresql/data

redis:
container_name: redis
image: 'redis:alpine'
ports:
- '6379:6379'
volumes:
- imdb:/data

celery-worker:
build:
context: ..
dockerfile: .devcontainer/Trak/Dockerfile
restart: unless-stopped
container_name: celery-worker
volumes:
- ..:/app:cached
env_file:
- .env.devcontainer
command: |
sh -c "cd ./server &&
python manage.py celery_worker"
depends_on:
- redis
- trak
- db

celery-beat:
build:
context: ..
dockerfile: .devcontainer/Trak/Dockerfile
restart: unless-stopped
container_name: celery-beat
env_file:
- .env.devcontainer
volumes:
- ..:/app:cached
command: |
sh -c "cd ./server &&
python manage.py celery_beat"
depends_on:
- redis
- trak
- db

client:
container_name: client
build:
context: ../client
target: dev
ports:
- '3000:3000'
volumes:
- ..:/app:cached
env_file:
- .env.devcontainer
command: sh -c "cd /app/client; npm install; npm start"

volumes:
rdb:
imdb:
9 changes: 8 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# see the GitHub - Dependabot version updates documentation for all configuration options:
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: 'devcontainers'
directory: '/'
schedule:
interval: weekly
- package-ecosystem: 'npm'
directory: '/client'
schedule:
Expand Down
25 changes: 1 addition & 24 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.9'
services:
server:
container_name: ht-server
trak:
container_name: trak
restart: unless-stopped
image: haztrak-server
build:
Expand All @@ -26,7 +26,7 @@ services:
HT_DB_NAME: ${HT_DB_NAME}
HT_DB_USER: ${HT_DB_USER}
HT_DB_PASSWORD: ${HT_DB_PASSWORD}
HT_DB_HOST: postgres
HT_DB_HOST: db
HT_DB_PORT: ${HT_DB_PORT}
command: |
sh -c "
Expand All @@ -35,11 +35,11 @@ services:
python manage.py loaddata dev_data.yaml &&
python manage.py runserver 0.0.0.0:8000"
depends_on:
postgres:
db:
condition: service_healthy

redis:
container_name: ht-redis
container_name: redis
image: 'redis:alpine'
ports:
- '6379:6379'
Expand All @@ -48,7 +48,7 @@ services:

celery-worker:
restart: unless-stopped
container_name: ht-celery-worker
container_name: celery-worker
image: haztrak-server
volumes:
- ./server:/app
Expand All @@ -61,13 +61,13 @@ services:
HT_DB_NAME: ${HT_DB_NAME}
HT_DB_USER: ${HT_DB_USER}
HT_DB_PASSWORD: ${HT_DB_PASSWORD}
HT_DB_HOST: postgres
HT_DB_HOST: db
HT_DB_PORT: ${HT_DB_PORT}
command: python manage.py celery_worker
depends_on:
- redis
- server
- postgres
- db

celery-beat:
restart: unless-stopped
Expand All @@ -84,17 +84,17 @@ services:
HT_DB_NAME: ${HT_DB_NAME}
HT_DB_USER: ${HT_DB_USER}
HT_DB_PASSWORD: ${HT_DB_PASSWORD}
HT_DB_HOST: postgres
HT_DB_HOST: db
HT_DB_PORT: ${HT_DB_PORT}
command: python manage.py celery_beat
depends_on:
- redis
- server
- postgres
- db

postgres:
db:
restart: unless-stopped
container_name: postgres
container_name: db
image: 'postgres:16'
environment:
POSTGRES_DB: ${HT_DB_NAME}
Expand Down

0 comments on commit 9a9722e

Please sign in to comment.