mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-16 18:22:17 -05:00
Iterate local development with Docker
This makes a few changes to: - Make local development consistent with our other apps. It's now faster to start Celery locally since we don't try to build the image each time - this is usually quick, but unnecessary. - Add support for connecting to a local Redis instance. Note that the previous suggestion of "REDIS = True" was incorrect as this would be turned into the literal string "True". I've also co-located and extended the recipes in the Makefile to make them a bit more visible.
This commit is contained in:
17
Makefile
17
Makefile
@@ -27,6 +27,10 @@ bootstrap: generate-version-file ## Set up everything to run the app
|
|||||||
createdb notification_api || true
|
createdb notification_api || true
|
||||||
(. environment.sh && flask db upgrade) || true
|
(. environment.sh && flask db upgrade) || true
|
||||||
|
|
||||||
|
.PHONY: bootstrap-with-docker
|
||||||
|
bootstrap-with-docker: ## Build the image to run the app in Docker
|
||||||
|
docker build -f docker/Dockerfile -t notifications-api .
|
||||||
|
|
||||||
.PHONY: run-flask
|
.PHONY: run-flask
|
||||||
run-flask: ## Run flask
|
run-flask: ## Run flask
|
||||||
. environment.sh && flask run -p 6011
|
. environment.sh && flask run -p 6011
|
||||||
@@ -39,12 +43,20 @@ run-celery: ## Run celery
|
|||||||
--loglevel=INFO \
|
--loglevel=INFO \
|
||||||
--concurrency=4
|
--concurrency=4
|
||||||
|
|
||||||
|
.PHONY: run-celery-with-docker
|
||||||
|
run-celery-with-docker: ## Run celery in Docker container (useful if you can't install pycurl locally)
|
||||||
|
./scripts/run_with_docker.sh make run-celery
|
||||||
|
|
||||||
.PHONY: run-celery-beat
|
.PHONY: run-celery-beat
|
||||||
run-celery-beat: ## Run celery beat
|
run-celery-beat: ## Run celery beat
|
||||||
. environment.sh && celery \
|
. environment.sh && celery \
|
||||||
-A run_celery.notify_celery beat \
|
-A run_celery.notify_celery beat \
|
||||||
--loglevel=INFO
|
--loglevel=INFO
|
||||||
|
|
||||||
|
.PHONY: run-celery-beat-with-docker
|
||||||
|
run-celery-beat-with-docker: ## Run celery beat in Docker container (useful if you can't install pycurl locally)
|
||||||
|
./scripts/run_with_docker.sh make run-celery-beat
|
||||||
|
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help:
|
help:
|
||||||
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
@cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
||||||
@@ -177,8 +189,3 @@ disable-failwhale: ## Disable the failwhale app and enable api
|
|||||||
cf unmap-route notify-api-failwhale ${DNS_NAME} --hostname api
|
cf unmap-route notify-api-failwhale ${DNS_NAME} --hostname api
|
||||||
cf stop notify-api-failwhale
|
cf stop notify-api-failwhale
|
||||||
@echo "Failwhale is disabled"
|
@echo "Failwhale is disabled"
|
||||||
|
|
||||||
.PHONY: run-celery-with-docker
|
|
||||||
run-celery-with-docker: ## Run celery in Docker container (useful if you can't install pycurl locally)
|
|
||||||
docker build -f docker/Dockerfile -t notifications-api .
|
|
||||||
./scripts/run_with_docker.sh make run-celery
|
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -63,8 +63,11 @@ export PATH=${PATH}:/Applications/Postgres.app/Contents/Versions/11/bin/
|
|||||||
|
|
||||||
To switch redis on you'll need to install it locally. On a OSX we've used brew for this. To use redis caching you need to switch it on by changing the config for development:
|
To switch redis on you'll need to install it locally. On a OSX we've used brew for this. To use redis caching you need to switch it on by changing the config for development:
|
||||||
|
|
||||||
REDIS_ENABLED = True
|
```
|
||||||
|
REDIS_ENABLED = 1
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that if you're running Celery with Docker locally, then you'll also need to set `REDIS_URL=redis://host.docker.internal:6379`.
|
||||||
|
|
||||||
## To run the application
|
## To run the application
|
||||||
|
|
||||||
@@ -82,6 +85,18 @@ make run-celery
|
|||||||
make run-celery-beat
|
make run-celery-beat
|
||||||
```
|
```
|
||||||
|
|
||||||
|
We've had problems running Celery locally due to one of its dependencies: pycurl. Due to the complexity of the issue, we also support running Celery via Docker:
|
||||||
|
|
||||||
|
```
|
||||||
|
# install dependencies, etc.
|
||||||
|
make bootstrap-with-docker
|
||||||
|
|
||||||
|
# run the background tasks
|
||||||
|
make run-celery-with-docker
|
||||||
|
|
||||||
|
# run scheduled tasks
|
||||||
|
make run-celery-beat-with-docker
|
||||||
|
|
||||||
## To test the application
|
## To test the application
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ class Development(Config):
|
|||||||
NOTIFY_EMAIL_DOMAIN = "notify.tools"
|
NOTIFY_EMAIL_DOMAIN = "notify.tools"
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI', 'postgresql://localhost/notification_api')
|
SQLALCHEMY_DATABASE_URI = os.getenv('SQLALCHEMY_DATABASE_URI', 'postgresql://localhost/notification_api')
|
||||||
REDIS_URL = 'redis://localhost:6379/0'
|
REDIS_URL = os.getenv('REDIS_URL', 'redis://localhost:6379/0')
|
||||||
|
|
||||||
ANTIVIRUS_ENABLED = os.getenv('ANTIVIRUS_ENABLED') == '1'
|
ANTIVIRUS_ENABLED = os.getenv('ANTIVIRUS_ENABLED') == '1'
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ docker run -it --rm \
|
|||||||
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
|
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
|
||||||
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
|
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
|
||||||
-e SQLALCHEMY_DATABASE_URI=$SQLALCHEMY_DATABASE_URI \
|
-e SQLALCHEMY_DATABASE_URI=$SQLALCHEMY_DATABASE_URI \
|
||||||
|
-e REDIS_ENABLED=${REDIS_ENABLED:-0} \
|
||||||
|
-e REDIS_URL=${REDIS_URL:-''} \
|
||||||
-v $(pwd):/home/vcap/app \
|
-v $(pwd):/home/vcap/app \
|
||||||
${DOCKER_IMAGE_NAME} \
|
${DOCKER_IMAGE_NAME} \
|
||||||
${@}
|
${@}
|
||||||
|
|||||||
Reference in New Issue
Block a user