Git Product home page Git Product logo

Comments (5)

greenled avatar greenled commented on June 19, 2024 1

Thanks @tortuetorche, this is a very good starting point.

Stack envvars are set in the deploy() function. When a new stack is deployed it gets no envvars, and when an existing one is updated its envvars are reused (extracted from its stack definition into the stack_envvars variable and set back again). For the first case it would be just a matter of loading the content of the envvars file and transform it into JSON using the command you provided, and set it as the stack_envvars value. For the second case, though, the script should update the current stack envvars rather than setting them from scratch, keeping any value not previously set in the .env file.

I would also make the environment variables file path customizable with a flag, like -g (could be any of the remaining bfghijkmoqwxyz), and a script configuration envvar, like ENVIRONMENT_VARIABLES_FILE.

from portainer-stack-utils.

tortuetorche avatar tortuetorche commented on June 19, 2024

Hi @greenled,

Any news on this issue?
I'll be very useful.

Have a good day,
Tortue Torche

from portainer-stack-utils.

greenled avatar greenled commented on June 19, 2024

Hi @tortuetorche,

I'm afraid I can not work on this in an immediate future. Too much work here and some health issues :(
Feel free to contribute a solution if you want to 💪 Have a good day too.

from portainer-stack-utils.

tortuetorche avatar tortuetorche commented on June 19, 2024

Hi @greenled,

Here a starting point:

Create a .env file, which contains the Docker Stack environment variables:

HOSTNAME=bfaecdeb0cd2
HOME=/root
_BASH_VERSION=5.0
_BASH_PATCH_LEVEL=0
_BASH_LATEST_PATCH=7
TERM=xterm
foo=d=cc

Then execute this jq command:

env -i $(cat .env) jq -n 'env | to_entries | map({name: .key, value: .value})'

This will output:

[
  {
    "name": "HOSTNAME",
    "value": "bfaecdeb0cd2"
  },
  {
    "name": "HOME",
    "value": "/root"
  },
  {
    "name": "_BASH_VERSION",
    "value": "5.0"
  },
  {
    "name": "_BASH_PATCH_LEVEL",
    "value": "0"
  },
  {
    "name": "_BASH_LATEST_PATCH",
    "value": "7"
  },
  {
    "name": "TERM",
    "value": "xterm"
  },
  {
    "name": "foo",
    "value": "d=cc"
  }
]

I hope you'll be better soon,
Tortue Torche

from portainer-stack-utils.

tortuetorche avatar tortuetorche commented on June 19, 2024

Hi @greenled ,

Thank you for your explanations.

Here some snippets to merge two environment variable JSON files with jq:

jq -s 'add | unique_by(.name)' env_new.json env_old.json

Or:

jq -n '[inputs] | add | unique_by(.name)' env_new.json env_old.json

Have a good day,
Tortue Torche

from portainer-stack-utils.

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.