Skip to content

Conversation

@vdemeester
Copy link
Member

… services creation/update. It's a rough first attemp 👼

/cc @thaJeztah @mstanleyjones

🐸

Signed-off-by: Vincent Demeester vincent@sbr.pm

Copy link
Contributor

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"?

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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 %}

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: teh

@thaJeztah
Copy link
Member

ping @vdemeester 😇

@vdemeester vdemeester force-pushed the docs-service-templating branch from 760dc84 to e74d241 Compare November 18, 2016 14:03
@vdemeester
Copy link
Member Author

Updated 👼

Copy link
Member

@thaJeztah thaJeztah left a 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?)

Copy link
Member

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}}"

Copy link
Member

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>
@vdemeester vdemeester force-pushed the docs-service-templating branch from e74d241 to 4571ad0 Compare November 18, 2016 14:28
Copy link
Member

@thaJeztah thaJeztah left a 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
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

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
Copy link
Contributor

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?

Copy link
Member Author

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 😓

Copy link
Member

@thaJeztah thaJeztah Nov 21, 2016

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

Copy link
Member Author

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 {{ 😅

@stevvooe
Copy link
Contributor

LGTM

@thaJeztah
Copy link
Member

{% raw %} looks consistent with some other parts, let's merge

@mostolog
Copy link

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:

--name hosttempl --hostname={% raw %}"{{.Node.ID}}-{{.Service.Name}}"{% endraw %}

becomes:

hosttempl.1.wo41w8hg8qanxwjwsg4kxpprj

where those "." came from?

IMHO, example it's not clear enough...

@thaJeztah
Copy link
Member

@mostolog the {% raw %} and {% endraw %} are not part of the actual example, but unfortunately needed for the tooling that's used to generate the online documentation 😞. The Markdown files in the docs directory are used as source for the online documentation, and may not always be properly formatted for reading on GitHub directly.

@thaJeztah
Copy link
Member

@mostolog oh, wait; hosttempl.1.wo41w8hg8qanxwjwsg4kxpprj is the name of the task, not its hostname.

@mostolog
Copy link

@thaJeztah thanks. I was totally confused and ended expecting "node.id" magically transformed to "task.slot"

@approxit
Copy link

Is there any way to make service hostname inherit it's node hostname?
Would ❤️ to use {{ .Node.Hostname }}.

@stevvooe
Copy link
Contributor

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.

@gr4per
Copy link

gr4per commented Mar 20, 2017

+1 for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants