This package contains a highly experimental CLI for Garden, written in Golang.
The code in this repository was originally a part of the main Garden repo. At this tag, the Go CLI is included in the main source under garden-cli
. Here's the PR for removing it, and here's the original issue.
First clone the repo into your $GOPATH
:
git clone https://github.com/garden-io/experimental-go-cli.git $GOPATH/github.com/garden-io/`
Then start the Mutagen daemon with:
mutagen daemon start
Finally, change into the cli
directory:
cd cli
and build the package with:
go build -o build/garden
Now you can use the built Go binary as you would normally use Garden.
We currently don't ship the built binary of the Go CLI. To use, please follow the Getting started instructions above to install and build the binary yourself.
Once that's done, it can be convenient to alias the Go binary:
alias garden_go=$GOPATH/github.com/garden-io/experimental-go-cli/cli/build/garden
Now, you can use garden_go
just like you would normally use Garden. For example, in some Garden project, run:
garden_go deploy
Note: It's currently not recommended to use the Go CLI inside the examples directory included with the main Garden source. This is a known limitation, see below.
The Go CLI is just a thin wrapper around the containerized version of the garden-service package, that uses Mutagen for file syncing. The garden-service
Docker image is available on Dockerhub and updated on every merge to master.
For the first run, the CLI:
- Creates a named volume for the project.
- Creates and starts a
garden-sync
container that mounts the named volume. - Starts a sync session between the host and the
garden-sync
container that syncs the contents of the local project directory into the named project volume and watches for changes. - Starts a
garden-service
container that mounts the named volume. - Runs the command inside the
garden-service
container and streams the output.
The containers, volume and sync session are persistent, and unique to a given project. So, for an existing project, where the steps above have already been performed, the CLI simply execs
into the garden-service
container and runs the command.
It can be useful to use the Mutagen CLI to check if everything is all right with the sync process:
mutagen list
To manually terminate a sync session, use:
mutagen terminate <session-id>
To find the Docker volumes created by the Go CLI, use:
docker volume ls | grep garden-volume
To find the Docker containers created by the Go CLI, use:
docker container ls | grep garden-sync
and
docker volume ls | grep garden-service
To access the Docker volume when using Docker for Mac, checkout this SO answer.
It's currently not recommend to use the Go CLI inside the examples directory of the main Garden source. This is because with the current implementation, the Go CLI assumes that the root of the project is the git root, i.e. the directory that contains the .git
directory.
So, if you've cloned the main Garden repo, the git root contains the entire codebase. The Go CLI would therefore attempt to sync and watch the entire codebase instead of just a particular example project.
You should therefore move an example project into it's own directory and do a git init
there.