Can you import your own jsonnet libraries?

can I import a libsonet file from my repository?

the drone-jsonnet-config extension can import libsonet files from your repository, however, the embedded jsonnet feature cannot import.

1 Like

Hey, I’m sorry for posting it here but maybe you could help.
I’m switching from built-in jsonnet to external extension by setting
DRONE_JSONNET_ENABLED = false
and
DRONE_CONVERT_PLUGIN_ENDPOINT = xxx
DRONE_CONVERT_PLUGIN_SECRET = xxx
DRONE_CONVERT_PLUGIN_EXTENSION = “.jsonnet”

But yet I bump into ‘yaml: line 1: mapping values are not allowed in this context’ like Drone is treating my pipeline file as yaml

Drone has multiple extension types. The jsonnet extension is a Configuration Extension and needs to be configured with different environment variables (see Configuration Extension | Drone). The jsonnet extension was created before the existence of Conversion Extensions which is what one would use if they were creating a jsonnet extension today.

I am not sure if proper configuration will solve the specific error message. If this does not solve the error, you will need to find a way to gather more data since this is not enough detail to diagnose the problem (sample jsonnet file? sample of what is returned from the extension?). You will not be able to use curl to interact with the extension because the extension requires an http-signature, however, you can use the command line tools to hit the extension endpoint directly and test it out (see below). You should also expect to download the jsonnet extension code and compile from source / debug as needed.

% drone plugins config get --help
NAME:
   drone plugins config get - get the pipeline configuration

USAGE:
   drone plugins config get [command options] [repo/name]

OPTIONS:
   --ref value              git reference (default: "refs/heads/master")
   --source value           source branch (default: "master")
   --target value           target branch (default: "master")
   --before value           commit sha before the change
   --after value            commit sha after the change
   --path value             configuration file path (default: ".drone.jsonnet")
   --endpoint value         plugin endpoint [$DRONE_YAML_ENDPOINT]
   --secret value           plugin secret [$DRONE_YAML_SECRET]
   --ssl-skip-verify value  plugin ssl verification disabled [$DRONE_YAML_SKIP_VERIFY]

Thanks a lot!

I’ve tried to switch to DRONE_YAML_ENDPOINT and DRONE_YAML_SECRET.
No luck though.

Well it might be a problem with my extension setup since
drone plugins config get --path "drone.jsonnet" --target "feature/xxx" --secret "xxx" --endpoint "https://drone-jsonnet.xxx/" xxx/terraform
gives me empty output and I can’t see any new log records on extension side (there are other records created on my lb healthchecks)

Is there some option for cli tool to produce verbose logs? I haven’t found any in the help.

Some details:

  • I am running a docker version of extension (drone/drone-jsonnet) and I have PLUGIN_DEBUG set to true. I cannot get a sample of what is returned from the extension because of the above
  • My pipeline is being successfully interpreted and executed by built-in jsonnet extension (DRONE_JSONNET_ENABLED=true) so it’s a valid jsonnet file.

You probably need to clone and build from source so that you can more easily debug the code

It would be awesome if .drone.jsonnet supported import statements from external sources. That way one could re-use jsonnet code across multiple repositories and possibly even source common patterns in the community similar how Prometheus libraries provide their own mixins.

Right now I’m resorting to copy / pasting jsonnet from one project to another.

We are moving in a slightly different direction. Drone now supports shared templates, which can be used to share pipelines and logic across multiple repositories. Check out https://docs.drone.io/template/

Hi @bradrydzewski , apologies for resurrecting an old post, but do the shared templates support importing libraries?

I would like to be able to leverage imports from a lib_deploy.jsonnet file across overarching pipelines for my different languages, such as golang.jsonnet, php.jsonnet etc.

I believe I had this working by importing a file with the template name, but the functionality has broken while I am testing it out and I am unsure if this is supported.

Thanks!

I had a cheeky peep around it it seems that it might not be officially supported, at least, pathing presents something to be considered.

Might I have had this working but am failing to reproduce a working pipeline now due to some cache issues that I am seeing perhaps?
I’m not the greatest coder out there, so hopefully I’m not barking up the wrong tree

I need to import json from the repository or an external source in jsonnet aswell. I’m trying to import a json file like this:

local info = import 'info.json';

This works locally without problems with a different parser, but drone failes on that line of my configuration. The info.json file is in the repository. How can I import it?