Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Traefik Configuration To Environment Variables #813

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SamJUK
Copy link
Contributor

@SamJUK SamJUK commented Oct 20, 2024

Currently overriding / extending the traefik.yml configuration is difficult. This PR proposes migrating the Traefik configuration from the .yml file to environment variables. This should improve both the extendability and maintainability of attempting to extend the Traefik config. Such as, but not limited to configuring plugins or certificate resolvers.

I've found there are 2 main pain points to the current approach.

  1. You have to overwrite and maintain the whole configuration file, even for a single value change.
  2. You have to edit the source file, since the svc up command replaces any modifications under $HOME/.warden/etc/traefik/traefik.yml See Here

Note: May be considered a breaking change. Since any custom changes to the traefik.yml by users would have to be reimplemented via the ENV approach. Due to Traefik static config approaches being mutually exclusive.


Example Use Case

Say you want to enable debug logging for Traefik. With the environment variable approach you can create a docker compose file in the warden home directory with the following contents.

# ~/.warden/docker-compose.yml
services:
  traefik:
    environment:
      TRAEFIK_LOG_LEVEL: DEBUG

Or if you want to define a certificate resolver such as LetsEncrypt to sign your certs. It can again be defined in the users home directory with the following docker compose file. See this issue of someone attempting a similar thing and having to override the source file

# ~/.warden/docker-compose.yml
services:
  traefik:
    volumes:
      - acmedata:/acme
    environment:
      CF_DNS_API_TOKEN: xxx
      CF_ZONE_API_TOKEN: xxx
      TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT: true
      TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL: [email protected]
      TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_STORAGE: /acme/acme.json
      TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_CASERVER: https://acme-staging-v02.api.letsencrypt.org/directory
      TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_DNSCHALLENGE: true
      TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_DNSCHALLENGE_PROVIDER: cloudflare
volumes:
  acmedata:

@bap14
Copy link
Member

bap14 commented Oct 21, 2024

Thank you for the work on this @SamJUK !! I see no issues with this PR.

If we didn't want to wait until Warden 1.0 (or 0.15) to push this change we could add a Warden flag that is WARDEN_USE_TRAEFIK_ENV_CONFIG that if set to 1 then the config file is this new style, but if not set is the old way. Then also send a message to stderr which states that the Traefik static file config has been deprecated and will be removed in a future version and people should start switching to WARDEN_USE_TRAEFIK_ENV_CONFIG now.

Thoughts @navarr ?

Copy link
Member

@bap14 bap14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only improvement we could make is in the deprecation instead of immediate cessation of static config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants