Skip to content

Commit

Permalink
Reverse proxy updates (#780)
Browse files Browse the repository at this point in the history
* update traefik to use dynamic configs instead of static traefik.toml

* remove static traefik file

* update vite config

* remove docker compose health checks

* remove references to localhost outside configs
  • Loading branch information
dpgraham4401 authored Aug 25, 2024
1 parent 2cfbf85 commit ec5a98c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 73 deletions.
3 changes: 0 additions & 3 deletions client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export default defineConfig({
server: {
host: true,
port: 3000,
hmr: {
clientPort: 8080,
},
},
test: {
environment: 'jsdom',
Expand Down
31 changes: 15 additions & 16 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- ./server:/app
environment:
DJANGO_SETTINGS_MODULE: "haztrak.settings.dev"
HT_HOST: "localhost"
HT_HOST: ${HT_HOST}
HT_SECRET_KEY: ${HT_SECRET_KEY}
HT_DEBUG: ${HT_DEBUG}
HT_LOG_LEVEL: ${HT_LOG_LEVEL}
Expand All @@ -27,19 +27,17 @@ services:
HT_DB_PASSWORD: ${HT_DB_PASSWORD}
HT_DB_HOST: db
HT_DB_PORT: ${HT_DB_PORT}
labels:
- "traefik.enable=true"
- "traefik.http.routers.trak.rule=Host(`${HT_HOST}`)"
- "traefik.http.routers.trak.rule=PathPrefix(`/api`) || PathPrefix(`/admin`) || PathPrefix(`/static`)"
- "traefik.http.routers.trak.entrypoints=web"
command: |
sh -c "
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py loaddata core_dev.yaml rcrasite_dev.yaml org_dev.yaml profile_dev.yaml &&
python manage.py runserver 0.0.0.0:8000"
healthcheck:
test:
["CMD", "curl", "-f", "http://localhost:8000/api/health/startup-probe/"]
interval: 30s
timeout: 20s
retries: 5
start_period: 10s
depends_on:
db:
condition: service_healthy
Expand Down Expand Up @@ -71,9 +69,6 @@ services:
HT_DB_HOST: db
HT_DB_PORT: ${HT_DB_PORT}
command: python manage.py celery_worker
depends_on:
trak:
condition: service_healthy

celery-beat:
restart: unless-stopped
Expand All @@ -94,9 +89,6 @@ services:
HT_DB_HOST: db
HT_DB_PORT: ${HT_DB_PORT}
command: python manage.py celery_beat
depends_on:
trak:
condition: service_healthy

db:
restart: unless-stopped
Expand Down Expand Up @@ -129,6 +121,10 @@ services:
VITE_HT_API_URL: ${VITE_HT_API_URL}
VITE_HT_ENV: ${VITE_HT_ENV}
VITE_GITHUB_URL: ${VITE_GITHUB_URL}
labels:
- "traefik.enable=true"
- "traefik.http.routers.client.rule=Host(`${HT_HOST}`)"
- "traefik.http.routers.client.entrypoints=web"
command: sh -c "cd /app; npm install; npm start"

proxy:
Expand All @@ -137,11 +133,14 @@ services:
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--log.level=DEBUG"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- "8080:8080"
- "80:80"
volumes:
- ./traefik.toml:/etc/traefik/traefik.toml
- /var/run/docker.sock:/var/run/docker.sock
- "/var/run/docker.sock:/var/run/docker.sock:ro"

mail:
container_name: mail
Expand Down
4 changes: 2 additions & 2 deletions configs/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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:8080
HT_CORS_DOMAIN=http://localhost
HT_RCRAINFO_ENV=preprod
HT_CACHE_URL=redis://redis:6379
HT_SIGNING_KEY=0dd3f4e68730bedfb07e6bc2e8f00a56c4db2d4a4b37e64ac0a83b8c97ec55dd
Expand All @@ -31,6 +31,6 @@ CELERY_RESULT_BACKEND=django-db
CELERY_BROKER_URL=redis://redis:6379

### React App configs
VITE_HT_API_URL=http://localhost:8080
VITE_HT_API_URL=http://localhost
VITE_HT_ENV=DEV
VITE_GITHUB_URL=https://github.com/USEPA/haztrak
18 changes: 13 additions & 5 deletions docs/guide/src/design/server.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## Server and Rest API

The REST API is the primary way users read and change data in the Haztrak system. It is implemented using Python, the [Django Framework](https://www.djangoproject.com/), and [Django Rest Framework](https://www.django-rest-framework.org/).
The REST API is the primary way users read and change data in the Haztrak system. It is implemented using Python,
the [Django Framework](https://www.djangoproject.com/),
and [Django Rest Framework](https://www.django-rest-framework.org/).

The choice to use Python stemmed from a desire to use a language that the team was already familiar with,
something that is easy to learn (regardless of whether Python is your primary language, it's easy to read).
The choice to use Django was made because it is a mature, well-documented, and widely used framework that provides a lot of functionality out of the box.
The choice to use Django was made because it is a mature, well-documented, and widely used framework that provides a lot
of functionality out of the box.

Many Django developer have turned to what they call the 'service layer', which
usually encapsulated the use cases business logic. It's a contentious topic whether the policy/business logic should be
Expand All @@ -25,8 +28,10 @@ The Admin site provides a quick, model-centric interface where trusted
users can manage content. It's not intended to provide a process centric interface,
admin user's should not be, for example, signing manifests through the admin site.

The admin interface is an out-of-the-box feature of the [Django framework](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/).
It can be found by appending `/admin` to the URL of the host and port of HTTP server, for example `http://localhost:8000/admin`
The admin interface is an out-of-the-box feature of
the [Django framework](https://docs.djangoproject.com/en/4.1/ref/contrib/admin/).
It can be found by appending `/admin` to the URL of the host and port of HTTP server, for example
`http://localhost/admin`

## In-memory Database

Expand All @@ -35,6 +40,9 @@ The in-memory data store serves a couple purposes,
- As a message broker for Haztrak's [task queue](./task-queue.md)
- A cache for the [http server](./http-server.md)

As a cache, the in-memory data store is utilized to increase performance by allowing Haztrak to cut down on latency for recently used resources including recent database queries, computed values, and external service calls. As a message broker, the data store provides a reliable way for the back end service to communicate which each other (e.g., launch background tasks).
As a cache, the in-memory data store is utilized to increase performance by allowing Haztrak to cut down on latency for
recently used resources including recent database queries, computed values, and external service calls. As a message
broker, the data store provides a reliable way for the back end service to communicate which each other (e.g., launch
background tasks).

The Haztrak project currently uses [Redis](https://redis.io/) as both the message broker and in-memory data store.
2 changes: 1 addition & 1 deletion docs/guide/src/development/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ that we've specified in
the [docker-compose.yaml](https://github.com/USEPA/haztrak/blob/main/docker-compose.yaml) file._

After all containers are successfully running (you can inspect with `docker ps`),
visit [localhost:8080](http://localhost:8080)
visit [localhost:8080](http://localhost)

## Fixtures (logging in)

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/src/operations/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The follow variables are required, haztrak will exit if not present.
the [e-Manifest API Client Library](https://github.com/USEPA/e-manifest/tree/master/emanifest-py)
- `HT_CORS_DOMAIN`
- Value for cross-origin resource sharing, the domain that the React app is deployed
- Example for local development: should be something like `http://localhost:3000`
- Example for local development: should be something like `http://localhost`
- `HT_CACHE_URL`
- URL that points to the cache, in this instance Redis
- Example for local development: should be something like `redis://localhost:6379`
Expand Down Expand Up @@ -137,7 +137,7 @@ will default to `HT_LOG_LEVEL`s default.

- `VITE_HT_API_URL`
- Value: host/domain name of the haztrak back end
- Default: `http://localhost:8000`
- Default: `http://localhost`
- `VITE_HT_ENV`
- Default: `PROD`
- Options: `PROD`, `DEV`, `TEST`
Expand Down
2 changes: 1 addition & 1 deletion server/haztrak/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# General
SECRET_KEY = "django-insecure-%btjqoun@6ps$e@8bw$48s+!x1e4aiz&5p2nrf6cmiw4)jsx5d"
DEBUG = True
CORS_ORIGIN_WHITELIST = [os.getenv("HT_CORS_DOMAIN", "http://localhost:3000")]
CORS_ORIGIN_WHITELIST = [os.getenv("HT_CORS_DOMAIN", "http://localhost")]

REST_FRAMEWORK["DEFAULT_RENDERER_CLASSES"] = [ # noqa: F405
"rest_framework.renderers.JSONRenderer",
Expand Down
43 changes: 0 additions & 43 deletions traefik.toml

This file was deleted.

0 comments on commit ec5a98c

Please sign in to comment.