-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Add documentation about templating support on… #28486
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to call it "Templating" or maybe something like "Create services using templates"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use templates for some flags of service create, using the syntax provided by the text/template package provided by the Go language.
Or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe title this section:
Template example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to wrap the double-backeted content with {% raw %} and {% endraw %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the output below, I can't see what the template is doing. Can you come up with an example that is more meaningful / obviously useful? Or explain to me what I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: teh
|
ping @vdemeester 😇 |
760dc84 to
e74d241
Compare
|
Updated 👼 |
thaJeztah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits/questions; wondering if we should also refer to https://docs.docker.com/engine/admin/formatting/, also that is for --format (some things may apply?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs quotes around the format "{{.Config.Hostname}}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need ./ here @mstanleyjones ?
… services creation/update. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
e74d241 to
4571ad0
Compare
thaJeztah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
but ping @mstanleyjones to check if the {%raw%} are in the correct place 😄
| `.Node.ID` | Node ID | ||
| `.Task.ID` | Task ID | ||
| `.Task.Name` | Task name | ||
| `.Task.Slot` | Task slot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should note that .Task.Slot falls back to node ID for global services
https://github.com/docker/swarmkit/blob/master/template/context.go#L52
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, probably it would be better to note that multiple tasks can share the single slot number in certain cases
moby/swarmkit#1741
PTAL @aaronlehmann @stevvooe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, probably it would be better to note that multiple tasks can share the single slot number in certain cases
I think you're over-valuing the importance of this particular functionality. It is not important for most users and calling it out every makes it look less useful than it is. In this case, the behavior of Task.Slot isn't important, at all.
In addition, the contents of .Task.Slot should largely be treated as opaque. This avoids consumers making assumptions about the contents of a field that may be broken in future versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
| service's name and the node's ID where it sits. | ||
|
|
||
| ```bash | ||
| $ docker service create --name hosttempl --hostname={% raw %}"{{.Node.ID}}-{{.Service.Name}}"{% endraw %} busybox top |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the first example of this feature include {% raw %}? Is that a feature of the local shell?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevvooe nah, that's required for the docs.github.io repo so Jekyll does not mess up the " it seams 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jekyll sees anything in {{}} as template, so tries to parse it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right it's about {{ 😅
|
LGTM |
|
|
|
Already merged #27857 and documented here, but I'm wondering why in https://github.com/docker/docker/blob/master/docs/reference/commandline/service_create.md#create-services-using-templates example:
becomes:
where those "." came from? IMHO, example it's not clear enough... |
|
@mostolog the |
|
@mostolog oh, wait; |
|
@thaJeztah thanks. I was totally confused and ended expecting "node.id" magically transformed to "task.slot" |
|
Is there any way to make service hostname inherit it's node hostname? |
|
The template variables are defined in https://github.com/docker/swarmkit/blob/master/template/context.go#L13. I'd recommend submitting a request over in https://github.com/docker/swarmkit, detailing the use case and how it would be expected to behave. |
|
+1 for this |
… services creation/update. It's a rough first attemp 👼
/cc @thaJeztah @mstanleyjones
🐸
Signed-off-by: Vincent Demeester vincent@sbr.pm