mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-27 09:28:03 -04:00
Merge pull request #3467 from alphagov/optimise-docker-dev
Iterate local development with Docker
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
|
||||
(. 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
|
||||
run-flask: ## Run flask
|
||||
. environment.sh && flask run -p 6011
|
||||
@@ -39,12 +43,20 @@ run-celery: ## Run celery
|
||||
--loglevel=INFO \
|
||||
--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
|
||||
run-celery-beat: ## Run celery beat
|
||||
. environment.sh && celery \
|
||||
-A run_celery.notify_celery beat \
|
||||
--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
|
||||
help:
|
||||
@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 stop notify-api-failwhale
|
||||
@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
|
||||
|
||||
25
README.md
25
README.md
@@ -61,10 +61,19 @@ export PATH=${PATH}:/Applications/Postgres.app/Contents/Versions/11/bin/
|
||||
|
||||
### Redis
|
||||
|
||||
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 Mac you can do:
|
||||
|
||||
REDIS_ENABLED = True
|
||||
```
|
||||
# assuming you use Homebrew
|
||||
brew install redis
|
||||
brew services start redis
|
||||
```
|
||||
|
||||
To use redis caching you need to switch it on with an environment variable:
|
||||
|
||||
```
|
||||
export REDIS_ENABLED=1
|
||||
```
|
||||
|
||||
## To run the application
|
||||
|
||||
@@ -82,6 +91,18 @@ make run-celery
|
||||
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
|
||||
|
||||
```
|
||||
|
||||
@@ -428,7 +428,7 @@ class Development(Config):
|
||||
NOTIFY_EMAIL_DOMAIN = "notify.tools"
|
||||
|
||||
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'
|
||||
|
||||
|
||||
@@ -9,11 +9,14 @@ source environment.sh
|
||||
AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-"$(aws configure get aws_access_key_id)"}
|
||||
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-"$(aws configure get aws_secret_access_key)"}
|
||||
: "${SQLALCHEMY_DATABASE_URI:=postgresql://postgres@host.docker.internal/notification_api}"
|
||||
REDIS_URL="redis://host.docker.internal:6379"
|
||||
|
||||
docker run -it --rm \
|
||||
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
|
||||
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
|
||||
-e SQLALCHEMY_DATABASE_URI=$SQLALCHEMY_DATABASE_URI \
|
||||
-e REDIS_ENABLED=${REDIS_ENABLED:-0} \
|
||||
-e REDIS_URL=$REDIS_URL \
|
||||
-v $(pwd):/home/vcap/app \
|
||||
${DOCKER_IMAGE_NAME} \
|
||||
${@}
|
||||
|
||||
Reference in New Issue
Block a user