StanGirard/seo-audits-toolkit

ADD path prefix variable in config for traefik intergration

Opened this issue · 2 comments

Hi guys,

Hope you are all well !

Is it possible to add a prefix path variable to flask in order to ease the integration in traefik ?

In fact, I d like to access seo-audits-toolkit from /devops/seo-toolkit path

here is the traefik label config:

    - "traefik.http.routers.seo-toolkit.rule=Host(`xxxx-xxxx.xxx-xxxxx.com`) && PathPrefix(`/devops/seo-toolkit`)"

here is an excerpt of my docker-compose:

  seo-toolkit:
    image: lucmichalski/seo-audits-toolkit:latest
    container_name: seo-audits-toolkit
    build: 
      context: .docker/seo-audits-toolkit
      dockerfile: Dockerfile
    expose:
    - 5000
    depends_on:
    - redis
    - postgres
    - seo-celery
    networks:
    - internal
    - web
    environment:
    - SECRET_KEY=changeme
    - URL_APP=http://localhost:5000/
    - FLASK_APP=SEOToolkit
    - FLASK_ENV=development
    - GOOGLE_API_KEY=None
    - CELERY_BROKER_URL=redis://redis:6379/0
    - CELERY_RESULT_BACKEND=redis://redis:6379/0
    - SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://unicorn_user:magical_password@postgres:5432/rainbow_database
    labels:
    - "org.label-schema.group=seo-toolkits"
    - "traefik.enable=true"
    - "traefik.docker.network=web"
    - "traefik.http.routers.seo-toolkit.rule=Host(`para-test.gsi-network.com`) && PathPrefix(`/devops/seo-toolkit`)"
    - 'traefik.http.routers.seo-toolkit.tls=true'
    - 'traefik.http.routers.seo-toolkit.tls.certresolver=letsencrypt'
    - "traefik.http.routers.seo-toolkit.entrypoints=https"
    - "traefik.http.services.seo-toolkit.loadbalancer.server.port=5000"  
    - "traefik.http.middlewares.seo-toolkit.compress=true"
    - "traefik.http.routers.seo-toolkit.middlewares=seo-toolkit-replacepathregex,seo-toolkit-basicauth" 
    - "traefik.http.middlewares.seo-toolkit-replacepathregex.replacepathregex.regex=^/devops/seo-toolkit(.*)"
    - "traefik.http.middlewares.seo-toolkit-replacepathregex.replacepathregex.replacement=/devops/seo-toolkit$$1"
    - 'traefik.http.middlewares.seo-toolkit-basicauth.basicauth.removeheader=true'
    - "traefik.http.middlewares.seo-toolkit-basicauth.basicauth.realm=EG-Seo Audit Toolkits"
    - "traefik.http.middlewares.seo-toolkit-basicauth.basicauth.users=${USER_PASSWORD}"
    restart: unless-stopped

  seo-celery:
    build: 
      context: .docker/seo-audits-toolkit
      dockerfile: Dockerfile
    networks:
    - internal
    - web
    depends_on:
    - redis
    environment:
    - SECRET_KEY=changeme
    - URL_APP=http://localhost:5000/
    - FLASK_APP=SEOToolkit
    - FLASK_ENV=development
    - GOOGLE_API_KEY=None
    - CELERY_BROKER_URL=redis://redis:6379/0
    - CELERY_RESULT_BACKEND=redis://redis:6379/0
    - SQLALCHEMY_DATABASE_URI=postgresql+psycopg2://unicorn_user:magical_password@postgres:5432/rainbow_database
    labels:
    - "traefik.enable=false"
    - "org.label-schema.group=seo-audits"
    command: "celery worker -A celery_worker.celery --loglevel=info"
    restart: unless-stopped

  postgres:
    image: "postgres" # use latest official postgres version
    container_name: postgres
    networks:
    - internal
    environment:
    - POSTGRES_USER=unicorn_user
    - POSTGRES_PASSWORD=magical_password
    - POSTGRES_DB=rainbow_database
    volumes:
    - postgres-data:/var/lib/postgresql/data/

  redis:
    image: redis:6-alpine
    container_name: redis
    networks:
    - internal
    volumes:
    - redis-data:/data
    labels:
    - "org.label-schema.group=storage"
    - "traefik.enable=false"
    command:
    - "redis-server"
    - "--maxmemory 3G"
    - "--maxmemory-policy allkeys-lru"
    restart: unless-stopped

Would be awesome to add something like app.config["APPLICATION_ROOT"] = "/devops/seo-toolkit/" but I am not sure for the rest of the integration ^^

Thanks for any insights or inputs on that.

Cheers,
Luc Michalski

Hello @lucmichalski,

That's a great idea to integrate traefik in this app. I'll need to look into it a little bit more to see the implications and how to integrate it with the code. I like the fact that you added authentication.

Maybe we could clean the docker compose by using an env file for all the values required.

I'll look into it next week ;)

Awesome, let me know if I can help !