Giter Club home page Giter Club logo

Comments (7)

Globegitter avatar Globegitter commented on June 12, 2024

@mariusgrigoriu Just started out with using jsonnet for kubernetes manifests and we would have similar requirements in regard to ingress host names. I am a fan of having everything checked into the repository so my idea was making use of --code-file/file (not implemented here yet but see google/jsonnet#110 for usage) and then define it as something like:

jsonnet_to_json(
    name = "k8s",
    src = "k8s.jsonnet",
    outs = ["k8s.json"],
    file = select({
    "//common/config:namespace_dev": {"fqdn": ":fqdn_dev.txt"},
    "//common/config:namespace_something": {"fqdn": ":fqdn_something.txt"},
    }),
)

So one would run e.g. bazel build :k8s --define namespace=dev and that would then make it select the right checked in file which contains the fqdn.

Your approach is of course total valid as well and my thought of approach has it's own drawbacks but since I just thought of that yesterday/today and wanted to look into it in the near future I thought I'd mention it here.

from rules_jsonnet.

mariusgrigoriu avatar mariusgrigoriu commented on June 12, 2024

I think that approach is better if you have a limited number of environments. In our case, the name is dynamically generated from earlier in the build process. Each pipeline run spins up a whole cluster with a unique name. Normally I'd use stamp variables for something like that, but I'm integrating with a complicated make system while incrementally converting to Bazel. (I'm also new to Bazel so I'm sure there are better ways of accomplishing this that I don't know about.)

from rules_jsonnet.

sparkprime avatar sparkprime commented on June 12, 2024

Is this backwards incompatible for people who were previously using $ in that string and expecting it to be passed through to Jsonnet?

from rules_jsonnet.

mariusgrigoriu avatar mariusgrigoriu commented on June 12, 2024

A $ alone should be fine, however $( ) would be interpreted as a make variable. People who have those would need to use $$( )

from rules_jsonnet.

sparkprime avatar sparkprime commented on June 12, 2024

Are strings usually interpolated like that in Bazel? If not is it usually documented which ones have it / don't have it, and is there any kind of standard about that?

from rules_jsonnet.

mariusgrigoriu avatar mariusgrigoriu commented on June 12, 2024

Only certain arguments are substituted like that. The convention is to document when it happens. The most common example is the genrule: https://docs.bazel.build/versions/master/be/general.html#genrule.cmd

It seems to me that if jsonnet takes variables on the command line, then it would be handy to extend that type of capability all the way out by allowing variables to be passed in from the bazel command line.

That said, for my uses, I'm starting to generate a .libsonnet with variables that will be imported into various templates, but this feature might still be handy.

from rules_jsonnet.

mariusgrigoriu avatar mariusgrigoriu commented on June 12, 2024

Merged in #40
Thank you.

from rules_jsonnet.

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.