Comments (10)
@Smiley73 Hi, thanks for your answer! My Go skills are limited but I'll try to provide a PR, thanks again
from git2consul-go.
@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.
Great! This is very useful. Thank you very much!
from git2consul-go.
@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.
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 ...
- Here is the go routine that starts the runner.
- Relevant select statement
- The Watcher code using channels
from git2consul-go.
Thanks for your info!
from git2consul-go.
@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.
@leoblanc were you able to resolve this issue?
from git2consul-go.
@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.
@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)
- Add better support for yaml lists HOT 10
- Add support to load KV from a file
- Current log format is missing a useful date HOT 3
- Consul Cluster Auto Discovery Feature
- Wrong default value for polling interval HOT 3
- Add support for Consul configuration through environmental variables
- Add support for configurable "repos:expand_keys" file extension HOT 2
- git2consul destroys kv store HOT 2
- Allow expanding of json values HOT 3
- Out of memory in some cases.
- Question: Connecting to Azure Devops git repos HOT 1
- Hidden files (e.g. .gitlab-ci.yml) cause failures
- Tx api size error
- Create Dockerfile to be able to use git2consul-go docker image
- slice interface case unable to load non map[interface{}]interface{}
- Running git2consul updates kv to one before most recent commit
- My branch name is topic/kurt.ding/fix_something,sync doesn't work
- I made some opinionated changes, may I can submit a PR ?
- Similarly named keys are inadvertently removed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git2consul-go.