Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Make the stack name available in Docker Swarm configuration as an environment variable #6911

Closed
antran22 opened this issue May 10, 2022 · 3 comments
Labels

Comments

@antran22
Copy link

Is your feature request related to a problem? Please describe.
This request is not related to a problem, but is a minor enhancement for the application templating workflow.
For Docker Swarm cluster using a label based load balancer/reverse proxy (such as Traefik) for exposing applications, I need to specify several labels in the Docker Swarm configuration, which looks something like this:

labels:
  - traefik.enable=true
  - traefik.docker.network=traefik-public
  - traefik.constraint-label=traefik-public
  - traefik.http.routers.${STACK_NAME}-http.rule=Host(`${DOMAIN}`)
  - traefik.http.routers.${STACK_NAME}-http.entrypoints=http
  - traefik.http.routers.${STACK_NAME}-http.middlewares=https-redirect
  - traefik.http.routers.${STACK_NAME}-https.rule=Host(`${DOMAIN}`)
  - traefik.http.routers.${STACK_NAME}-https.entrypoints=https
  - traefik.http.routers.${STACK_NAME}-https.tls=true
  - traefik.http.routers.${STACK_NAME}-https.tls.certresolver=le
  - traefik.http.services.${STACK_NAME}.loadbalancer.server.port=80

The $STACK_NAME variable is used because labels for each stack must be different in order for Traefik to differentiate between stacks.

Describe the solution you'd like
We can provide the STACK_NAME variable somewhere around here.
The code would look something like this:

env := make([]string, 0)
for _, envvar := range stack.Env {
    env = append(env, envvar.Name+"="+envvar.Value)
}
env = append(env, "STACK_NAME="+stack.Name)

The variable name can be discussed so that it may not clash with existing users. PORTAINER_STACK_NAME is also a viable alternative.

Describe alternatives you've considered
For now, I have to specify STACK_NAME in the env of the App Template file in order for the configuration to interpolate correctly.

@jamescarppe jamescarppe added kind/enhancement Applied to Feature Requests area/templates labels May 10, 2022
@jamescarppe
Copy link
Member

Thanks for the feedback - I've written this up as an internal ticket for the team to assess for the future.

@robjuz
Copy link

robjuz commented Nov 7, 2022

Any update on this? I'm deploying the same stack multiple times and this is the one remaining part to make it full automated.

@sergioisidoro
Copy link

It might make sense to focus efforts on Docker itself exposing COMPOSE_PROJECT_NAME which I assume is the same in a deployed swarm stack.

docker/compose#2294

@portainer portainer locked and limited conversation to collaborators Jul 27, 2023
@jamescarppe jamescarppe converted this issue into discussion #9823 Jul 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants