├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── app.py ├── celery_config.py ├── docker-compose.yml └── nginx.conf /.gitignore: -------------------------------------------------------------------------------- 1 | htpasswd 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10 2 | 3 | WORKDIR /usr/src/app 4 | 5 | RUN pip install celery[redis]==5.2.7 6 | 7 | COPY app.py . 8 | COPY celery_config.py . 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Michael Herman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Running Flower in Production 2 | 3 | https://testdriven.io/blog/flower-nginx/ 4 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from celery import Celery 4 | 5 | 6 | os.environ.setdefault('CELERY_CONFIG_MODULE', 'celery_config') 7 | 8 | app = Celery('app') 9 | app.config_from_envvar('CELERY_CONFIG_MODULE') 10 | 11 | 12 | @app.task 13 | def add(x, y): 14 | return x + y 15 | -------------------------------------------------------------------------------- /celery_config.py: -------------------------------------------------------------------------------- 1 | from os import environ 2 | 3 | broker_url = environ['BROKER_URL'] 4 | result_backend = environ['RESULT_BACKEND'] 5 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.7' 2 | 3 | services: 4 | 5 | redis: 6 | image: redis 7 | expose: 8 | - 6379 9 | 10 | worker: 11 | build: 12 | context: . 13 | dockerfile: Dockerfile 14 | command: ['celery', '-A', 'app.app', 'worker', '-l', 'info'] 15 | environment: 16 | - BROKER_URL=redis://redis:6379 17 | - RESULT_BACKEND=redis://redis:6379 18 | depends_on: 19 | - redis 20 | 21 | flower: 22 | image: mher/flower:0.9.7 23 | command: ['flower', '--broker=redis://redis:6379', '--port=5555'] 24 | expose: 25 | - 5555 26 | depends_on: 27 | - redis 28 | 29 | nginx: 30 | image: nginx:latest 31 | volumes: 32 | - ./nginx.conf:/etc/nginx/nginx.conf 33 | - ./htpasswd:/etc/nginx/.htpasswd 34 | ports: 35 | - 80:80 36 | depends_on: 37 | - flower 38 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | events {} 2 | 3 | http { 4 | server { 5 | listen 80; 6 | # server_name your.server.url; 7 | 8 | location / { 9 | proxy_pass http://flower:5555; 10 | proxy_set_header Host $host; 11 | proxy_redirect off; 12 | proxy_http_version 1.1; 13 | proxy_set_header Upgrade $http_upgrade; 14 | proxy_set_header Connection "upgrade"; 15 | 16 | auth_basic "Restricted"; 17 | auth_basic_user_file /etc/nginx/.htpasswd; 18 | } 19 | } 20 | } 21 | --------------------------------------------------------------------------------