jsonnet-bundler/README.md

125 lines
3.4 KiB
Markdown
Raw Permalink Normal View History

2018-04-24 15:19:40 +01:00
# jsonnet-bundler
> NOTE: This project is *alpha* stage. Flags, configuration, behavior and design may change significantly in following releases.
2019-03-12 19:00:08 +00:00
The jsonnet-bundler is a package manager for [Jsonnet](http://jsonnet.org/).
2018-04-24 15:19:40 +01:00
## Install
```
go install -a github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
2018-04-24 15:19:40 +01:00
```
**NOTE**: please use a recent Go version to do this, ideally Go 1.13 or greater.
2018-04-24 15:19:40 +01:00
This will put `jb` in `$(go env GOPATH)/bin`. If you encounter the error
`jb: command not found` after installation then you may need to add that directory to your `$PATH` as shown [in their docs](https://golang.org/doc/code.html#GOPATH).
2018-04-24 15:19:40 +01:00
## Package Install
* [Arch Linux AUR](https://aur.archlinux.org/packages/jsonnet-bundler-bin)
* Mac OS X via Homebrew: `brew install jsonnet-bundler`
2021-01-03 18:50:08 +01:00
* Fedora (>= 32): `sudo dnf install golang-github-jsonnet-bundler`
2019-03-12 19:00:08 +00:00
## Features
- Fetches transitive dependencies
- Can vendor subtrees, as opposed to whole repositories
## Current Limitations
2019-03-13 13:13:20 +00:00
- Always downloads entire dependent repositories, even when updating
2019-03-12 19:00:08 +00:00
- If two dependencies depend on the same package (diamond problem), they must require the same version
## Example Usage
Initialize your project:
```sh
mkdir myproject
cd myproject
jb init
```
The existence of the `jsonnetfile.json` file means your directory is now a
2019-03-13 13:13:20 +00:00
jsonnet-bundler package that can define dependencies.
2019-03-12 19:00:08 +00:00
To depend on another package (another Github repository):
2019-03-13 13:13:20 +00:00
*Note that your dependency need not be initialized with a `jsonnetfile.json`.
If it is not, it is assumed it has no transitive dependencies.*
2019-03-12 19:00:08 +00:00
```sh
jb install https://github.com/anguslees/kustomize-libsonnet
```
Now write `myconfig.jsonnet`, which can import a file from that package.
2019-03-13 11:02:13 +00:00
Remember to use `-J vendor` when running Jsonnet to include the vendor tree.
2019-03-12 19:00:08 +00:00
```jsonnet
2019-03-13 11:02:13 +00:00
local kustomize = import 'kustomize-libsonnet/kustomize.libsonnet';
2019-03-12 19:00:08 +00:00
local my_resource = {
metadata: {
name: 'my-resource',
},
};
kustomize.namePrefix('staging-')(my_resource)
```
2019-03-13 11:02:13 +00:00
To depend on a package that is in a subtree of a Github repo (this package also
2019-03-12 19:00:08 +00:00
happens to bring in a transitive dependency):
```sh
jb install https://github.com/prometheus-operator/prometheus-operator/jsonnet/prometheus-operator
2019-03-12 19:00:08 +00:00
```
2019-03-13 11:02:13 +00:00
*Note that if you are copy pasting from the Github website's address bar,
remove the `tree/master` from the path.*
2019-03-12 19:00:08 +00:00
If pushed to Github, your project can now be referenced from other packages in
2019-03-13 13:13:20 +00:00
the same way, with its dependencies fetched automatically.
2019-03-12 19:00:08 +00:00
## All command line flags
2018-04-24 15:19:40 +01:00
[embedmd]:# (_output/help.txt)
```txt
$ jb -h
2018-05-13 06:55:13 -07:00
usage: jb [<flags>] <command> [<args> ...]
A jsonnet package manager
Flags:
-h, --help Show context-sensitive help (also try --help-long and
--help-man).
--version Show application version.
2018-05-13 06:55:13 -07:00
--jsonnetpkg-home="vendor"
The directory used to cache packages in.
-q, --quiet Suppress any output from git command.
2018-05-13 06:55:13 -07:00
Commands:
help [<command>...]
Show help.
init
Initialize a new empty jsonnetfile
2020-04-21 13:45:14 +02:00
install [<flags>] [<uris>...]
2020-03-17 17:42:08 +01:00
Install new dependencies. Existing ones are silently skipped
2018-05-13 06:55:13 -07:00
2020-03-17 17:42:08 +01:00
update [<uris>...]
Update all or specific dependencies.
2018-06-29 14:29:48 +02:00
2020-01-24 08:02:34 +01:00
rewrite
Automatically rewrite legacy imports to absolute ones
2019-04-23 17:03:40 +02:00
2018-04-24 15:19:40 +01:00
```
2019-03-12 19:00:08 +00:00
2019-08-13 15:27:02 +02:00
## Design
This is an implemention of the design specified in this document: https://docs.google.com/document/d/1czRScSvvOiAJaIjwf3CogOULgQxhY9MkiBKOQI1yR14/edit#heading=h.upn4d5pcxy4c