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

error calling index: index out of range: 1, but "last works #279

Open
maxmeyer opened this issue Mar 8, 2018 · 1 comment
Open

error calling index: index out of range: 1, but "last works #279

maxmeyer opened this issue Mar 8, 2018 · 1 comment

Comments

@maxmeyer
Copy link

maxmeyer commented Mar 8, 2018

I get this error when I use the index-method with docker-gen on something else than 0, but the last and first-methods work as expected. I can't really see what I do wrong.

2018/03/08 23:22:34 Template error: template: vhost-nginx-new.tmpl:10:3: executing "vhost-nginx-neu.tmpl" at <index $v 1>: error calling index: index out of range: 1

This is an "annotated" template showing the results for the example given below:

{{ range $value := whereExist . "Env.VIRTUAL_HOST" }}
{{ range $index, $vhost := split $value.Env.VIRTUAL_HOST "," }}
{{ $v := split $vhost ":::" }}
# this is the content of $v after splitting up the string
# [nextcloud-1.cloud.in.example.org nextcloud-1:80]
{{ $v }}

{{ $frontend := first $v }}
# this succeeds with:
# nextcloud-1.cloud.in.example.org
{{ $frontend }}

{{ $backend := last $v }}
# this succeeds with
# nextcloud-1:80
{{ $backend }}


{{ index $v 0 }}
# this succeeds with
# nextcloud-1.cloud.in.example.org

{{ index $v 1 }}
# this fails with
# error calling index: index out of range: 1
{{ end }}
{{ end }}

The docker container is started this way:


/usr/bin/docker run \
  --rm \
  --name nextcloud-1 \
  --network internal \
  -v /srv/machines/nextcloud/storage:/var/www/html \
  -e VIRTUAL_HOST=nextcloud-1.cloud.in.example.org:::nextcloud-1:80 \
  nextcloud:13

That's the template for docker-gen:

{{ range $value := whereExist . "Env.VIRTUAL_HOST" }}
{{ range $index, $vhost := split $value.Env.VIRTUAL_HOST "," }}
{{ $v := split $vhost ":::" }}
{{ $v }}
{{ $frontend := first $v }}
{{ $frontend }}
{{ $backend := last $v }}
{{ $backend }}
{{ index $v 0 }}
{{ index $v 1 }}
{{ end }}
{{ end }}

That's the docker-gen-configuration-file

[[config]]
template = "/etc/docker-gen/templates/vhost-nginx-new.tmpl"
dest = "/var/docker-gen/exports/nginx/vhosts-new.conf"
watch = true
keep-blank-lines = true
notify-output = true
@maxmeyer
Copy link
Author

maxmeyer commented May 22, 2018

@jwilder Any ideas?

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

No branches or pull requests

1 participant