Merge pull request #3442 from alphagov/celery-docker

add script to run celery from within docker
This commit is contained in:
Leo Hemsted
2022-02-03 12:51:01 +00:00
committed by GitHub
4 changed files with 57 additions and 1 deletions

View File

@@ -177,3 +177,8 @@ 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

View File

@@ -427,7 +427,7 @@ class Development(Config):
NOTIFY_LOG_PATH = 'application.log'
NOTIFY_EMAIL_DOMAIN = "notify.tools"
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'
ANTIVIRUS_ENABLED = os.getenv('ANTIVIRUS_ENABLED') == '1'

32
docker/Dockerfile Normal file
View File

@@ -0,0 +1,32 @@
FROM python:3.9-slim-bullseye as parent
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "Install base packages" && apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
git \
&& echo "Install binary app dependencies" \
&& apt-get install -y --no-install-recommends \
libcurl4-openssl-dev \
libssl-dev \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/* /tmp/*
RUN pip install --upgrade pip
WORKDIR /home/vcap/app
COPY requirements.txt ./
# RUN useradd celeryuser
RUN \
echo "Installing python dependencies" \
&& pip install -r requirements.txt
COPY app app
COPY run_celery.py .
COPY environment.sh .
COPY Makefile .

19
scripts/run_with_docker.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
set -eu
DOCKER_IMAGE_NAME=notifications-api
source environment.sh
# this script should be run from within your virtualenv so you can access the aws cli
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}"
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 \
-v $(pwd):/home/vcap/app \
${DOCKER_IMAGE_NAME} \
${@}