Git Product home page Git Product logo

Comments (10)

leoblanc avatar leoblanc commented on August 14, 2024 1

@Smiley73 Hi, thanks for your answer! My Go skills are limited but I'll try to provide a PR, thanks again

from git2consul-go.

leoblanc avatar leoblanc commented on August 14, 2024 1

@MartijnDekkers This is great, thank you very much! We tried to work on a git2consul-go patch but didn't have success so far. I'll try your approach, thanks again!

from git2consul-go.

leoblanc avatar leoblanc commented on August 14, 2024 1

Great! This is very useful. Thank you very much!

from git2consul-go.

Smiley73 avatar Smiley73 commented on August 14, 2024

@leoblanc sorry for the slow response time on our side. Unfortunately we're currently not in a position to implement a lot of changes or help much (we're short staffed due to the pandemic).
This might be as simple as adding an optional order key that forces it to be processed in the order you want. We'd appreciate any pull requests. :)

from git2consul-go.

seanmalloy avatar seanmalloy commented on August 14, 2024

From what I can tell the code is using go routines, select, and channels therefore order is not guaranteed.

Here are some notes about the relevant code for this feature enhancement request ...

from git2consul-go.

leoblanc avatar leoblanc commented on August 14, 2024

Thanks for your info!

from git2consul-go.

MartijnDekkers avatar MartijnDekkers commented on August 14, 2024

@leoblanc We have a similar use-case, where we keep as much as possible in a "common" section (i.e. your "base"), and override for specific instances where required. We use the following structure in Consul:

services/<service-name>/common/env/[KV Pairs]
services/<service-name>/<instance-name>/common/env/[KV Pairs]
services/<service-name>/<instance-name>/[dev|test|prod]/env/[KV Pairs]

we keep this in a single repo that mirrors this structure. Come deploy time, we use consul-template, with a routine like:

{{/* Build a map of the environment variables. */}}
{{/* First we get all the instance variables, and set them in the Map */}}
{{ range tree $instancevars }}
    {{ scratch.MapSet "vars" .Key .Value }}
{{ end }}
{{/* Get all the common variables. Don't overwrite a variable if it is already in the map */}}
{{ range tree $commonvars }}
    {{ scratch.MapSetX "vars" .Key .Value }}
{{ end }}

This will first grab everything in a specific instance branch of the tree, and drop the values in an internal map. Next it will grab everything out of a common branch, but only set data in the map if the keys don't already exist.

I can then render the data (in this case it is going into a config file) like so:

{{ range $thekey, $theval := (scratch.Get "vars" | explodeMap) }}
    {{ $thekey }}: {{ $theval }}{{ end }}

Hope this helps.

from git2consul-go.

Smiley73 avatar Smiley73 commented on August 14, 2024

@leoblanc were you able to resolve this issue?

from git2consul-go.

leoblanc avatar leoblanc commented on August 14, 2024

@Smiley73 Not yet, I'm creating a PoC based on consul-template. @MartijnDekkers Can you please tell me how you load the $instancevars and $commonvars variables? Thank you very much

from git2consul-go.

MartijnDekkers avatar MartijnDekkers commented on August 14, 2024

@leoblanc This is part of the definition section of my template, it is on top of the file:

{{/* Define variables to be used in the template. Keep the template clean and readable. */}}
{{/* Get required information from the environment. It is possible to get these from elsewhere if required. */}}
{{- $service := env "SERVICE" -}}
{{- $instance := env "INSTANCE" -}}
{{- $deploy := env "DEPLOY" -}}

{{/* Some stuff that uglifies the template. Put them here for easier debugging and readability */}}
{{/* Frequently used lookups */}}
{{- $commonvars := (printf "%s/common/vars" ($service)) -}}
{{- $instancevars := (printf "%s/%s/%s/vars" ($service) ($instance) ($deploy)) -}}
{{- $commonparams := (printf "%s/params" ($service)) -}}
{{- $instanceparams := (printf "%s/%s/%s/params" ($service) ($instance) ($deploy)) -}}
{{- $dcospath := (printf "%s/%s/%s" ($service) ($deploy) ($instance)) | replaceAll "tenants" "" -}}
{{- $dcoscommonsettings := (printf "%s/DCOS" ($service)) -}}
{{- $dcosinstsettings := (printf "%s/%s/%s/DCOS" ($service) ($instance) ($deploy)) -}}
{{- $volnamesuffix := (printf "%s%s" ($deploy) ($instance)) | replaceAll "/" ""}}
{{- $port := keyOrDefault (printf "%s/%s/%s/vars/PORT" ($service) ($instance) ($deploy)) (key (printf "%s/common/vars/PORT" ($service))) -}}
{{- $pwxdefs := (printf "%s/common/DCOS/volumes" ($service)) -}}
{{- $commonsecrets := (printf "%s/common/DCOS/secrets" ($service)) -}}
{{- $instancesecrets := (printf "%s/%s/%s/DCOS/secrets" ($service) ($instance) ($deploy)) -}}

This layout (and the rest that follows) will leave a whole bunch of empty lines at the top of the rendered file, there are different ways to deal with that. This particular template renders to a YAML file, that I run through yq to end up with a JSON file that's valid for my use-case.

This approach makes that you can use {{ range tree $instancevars }} in the main body of your template, instead of {{ range tree (printf "%s/%s/%s/vars" ($service) ($instance) ($deploy)) }} which makes for a nicer experience.

from git2consul-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.