jsonnetmod

module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: MIT

README

Jsonnet Mod

GoDoc Widget codecov Go Report Card

JSONNET dependency management based on go modules

Requirements

  • git or other vcs tool supported by go for vcs downloading.

Install

go install github.com/jsonnetmod/jsonnetmod/cmd/jmod@latest

Usage

# build, will automately install deps if not exists. 
jmod build ./path/to/jsonnetfile

# auto dep
jmod get ./...

# upgrade dep
jmod get -u ./...

# install dep with special version
jmod get github.com/grafana/jsonnet-libs@latest

Features

  • Dependency management based on go modules
    • all dependency codes will download under $(go env GOMODCACHE)
    • GOPROXY supported to speed up downloading
    • JSONNET_PATH compatibility
  • Compatible with jsonnetfile.json
    • not support local source, use replace to fix
  • Includes all native functions of tanka
  • Object YAML import supported
    • with hidden fields __dirname and __filename

Spec mod.jsonnet

{
  // module name
  // for sub mod import, <module>/path/to/local/file.jsonnet
  module: 'github.com/x/b',
  
  // `JSONNET_PATH` compatibility, 
  // when this field defined, all dependencies will created symlinks under ./<jpath>
  jpath: 'vendor',
  
  // dependency version lock or replace
  // only support dir
  replace: {
    // version lock
    // if path equals, could short as '@v0.0.18'
    'github.com/rancher/local-path-provisioner': 'github.com/rancher/local-path-provisioner@v0.0.18',
    // local mod replace
    'github.com/x/a': '../a',
    // import stubs
    'k.libsonnet': 'github.com/jsonnet-libs/k8s-alpha/1.19/main.libsonnet',
    // mod short alias
    'ksonnet-util': 'github.com/grafana/jsonnet-libs/ksonnet-util',
  },
  
  // automately resolve by the jsonnet code `import` or `importstr`
  // rules follow go modules
  // :: hidden fields means indirect require
  require: {
    'github.com/rancher/local-path-provisioner':: 'v0.0.19',
    // ,<tag_version>, when upgrade, should use tag version for upgrade. 
    'github.com/grafana/jsonnet-libs':: 'v0.0.0-20210209092858-49e80898b183,master',
    'github.com/x/a': 'v0.0.0',
  },
}
Known issues
dep incompatible go mod repo

For some go project like

$ go mod download -json github.com/grafana/loki@v2.1.0
{
        "Path": "github.com/grafana/loki",
        "Version": "v2.1.0",
        "Error": "github.com/grafana/loki@v2.1.0: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2"
}

Could config mod.jsonnet replace with commit hash of the tag to hack

{
    replace: {
        'github.com/grafana/loki': '@1b79df3',
    }
}

Plugin kube

Like Tanka but without struct limit. Only one requirement, make sure the file return tanka.dev/Environment object

cd ./examples
jmod k show ./clusters/demo/hello-world.jsonnet
jmod k apply ./clusters/demo/hello-world.jsonnet
jmod k delete ./clusters/demo/hello-world.jsonnet
jmod k prune ./clusters/demo/hello-world.jsonnet
Work with Tanka
jmod build -o ./environments/demo/main.jsonnet ./path/to/tanka-environment.jsonnet
tk show ./environments/demo

export not support pipe now, so need to create inline env object main.jsonnet first.

Directories

Path Synopsis
cmd
internal
forked/cmd/go/internalpkg/auth
Package auth provides access to user-provided authentication credentials.
Package auth provides access to user-provided authentication credentials.
forked/cmd/go/internalpkg/base
Package base defines shared basic pieces of the go command, in particular logging and the Command structure.
Package base defines shared basic pieces of the go command, in particular logging and the Command structure.
forked/cmd/go/internalpkg/cfg
Package cfg holds configuration shared by multiple parts of the go command.
Package cfg holds configuration shared by multiple parts of the go command.
forked/cmd/go/internalpkg/fsys
Package fsys is an abstraction for reading files that allows for virtual overlays on top of the files on disk.
Package fsys is an abstraction for reading files that allows for virtual overlays on top of the files on disk.
forked/cmd/go/internalpkg/lockedfile
Package lockedfile creates and manipulates files whose contents should only change atomically.
Package lockedfile creates and manipulates files whose contents should only change atomically.
forked/cmd/go/internalpkg/lockedfile/internalpkg/filelock
Package filelock provides a platform-independent API for advisory file locking.
Package filelock provides a platform-independent API for advisory file locking.
forked/cmd/go/internalpkg/modfetch/codehost
Package codehost defines the interface implemented by a code hosting source, along with support code for use by implementations.
Package codehost defines the interface implemented by a code hosting source, along with support code for use by implementations.
forked/cmd/go/internalpkg/mvs
Package mvs implements Minimal Version Selection.
Package mvs implements Minimal Version Selection.
forked/cmd/go/internalpkg/par
Package par implements parallel execution helpers.
Package par implements parallel execution helpers.
forked/cmd/go/internalpkg/renameio
Package renameio writes files atomically by renaming temporary files.
Package renameio writes files atomically by renaming temporary files.
forked/cmd/go/internalpkg/robustio
Package robustio wraps I/O functions that are prone to failure on Windows, transparently retrying errors up to an arbitrary timeout.
Package robustio wraps I/O functions that are prone to failure on Windows, transparently retrying errors up to an arbitrary timeout.
forked/cmd/go/internalpkg/str
Package str provides string manipulation utilities.
Package str provides string manipulation utilities.
forked/cmd/go/internalpkg/web
Package web defines minimal helper routines for accessing HTTP/HTTPS resources without requiring external dependencies on the net package.
Package web defines minimal helper routines for accessing HTTP/HTTPS resources without requiring external dependencies on the net package.
forked/cmd/internalpkg/browser
Package browser provides utilities for interacting with users' browsers.
Package browser provides utilities for interacting with users' browsers.
forked/cmd/internalpkg/traceviewer
Package traceviewer provides definitions of the JSON data structures used by the Chrome trace viewer.
Package traceviewer provides definitions of the JSON data structures used by the Chrome trace viewer.
forked/internalpkg/cfg
Package cfg holds configuration shared by the Go command and internal/testenv.
Package cfg holds configuration shared by the Go command and internal/testenv.
forked/internalpkg/execabs
Package execabs is a drop-in replacement for os/exec that requires PATH lookups to find absolute paths.
Package execabs is a drop-in replacement for os/exec that requires PATH lookups to find absolute paths.
forked/internalpkg/lazyregexp
Package lazyregexp is a thin wrapper over regexp, allowing the use of global regexp variables without forcing them to be compiled at init.
Package lazyregexp is a thin wrapper over regexp, allowing the use of global regexp variables without forcing them to be compiled at init.
forked/internalpkg/singleflight
Package singleflight provides a duplicate function call suppression mechanism.
Package singleflight provides a duplicate function call suppression mechanism.
forked/internalpkg/syscall/windows/sysdll
Package sysdll is an internal leaf package that records and reports which Windows DLL names are used by Go itself.
Package sysdll is an internal leaf package that records and reports which Windows DLL names are used by Go itself.
forked/internalpkg/unsafeheader
Package unsafeheader contains header declarations for the Go runtime's slice and string implementations.
Package unsafeheader contains header declarations for the Go runtime's slice and string implementations.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL