Skip to content

Commit

Permalink
improves CLI README & brings down instances before spinning them up f…
Browse files Browse the repository at this point in the history
…or local tembo apply (#495)
  • Loading branch information
shahadarsh authored Jan 22, 2024
1 parent 3875a1a commit 4451e2d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We just got started, but here's what we're working on:
* A managed service Postgres, which you can get early access to by visiting
[our website](https://tembo.io)
* [Tembo-Stacks](https://github.com/tembo-io/tembo-stacks) - pre-configured Postgres Stacks deployable to Kubernetes
* [Tembo CLI](https://github.com/tembo-io/tembo-cli) built with Rust
* [Tembo CLI](https://github.com/tembo-io/tembo/tree/main/tembo-cli) built with Rust
* [Trunk CLI](https://github.com/tembo-io/trunk/tree/main/cli) that users can use to publish and install Postgres extensions
* [Trunk Website](https://github.com/tembo-io/trunk/tree/main/registry) that serves as a backend for [pgt.dev](https://pgt.dev), and also provides discovery and metrics

Expand Down
2 changes: 1 addition & 1 deletion tembo-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace = { members = ["temboclient", "tembodataclient"] }
[package]
name = "tembo-cli"
version = "0.15.0"
version = "0.15.1"
edition = "2021"
authors = ["Tembo.io"]
description = "The CLI for Tembo"
Expand Down
23 changes: 14 additions & 9 deletions tembo-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Tembo CLI allows users to experience [Tembo](https://tembo.io) locally, as well as,
manage and deploy to Tembo Cloud. It abstracts away complexities of configuring,
managing, and running Postgres in a local environment.
managing, and running Postgres.

## Getting Started

Expand Down Expand Up @@ -34,11 +34,11 @@ The `tembo init` command initializes your environment with following files. Run

For more information: `tembo init --help`

### Add Tembo Cloud info
#### Add Tembo Cloud info

To provision instances on Tembo Cloud using CLI you will need to configure `org_id` & `tembo_access_token`

* fetch the `org_id` Tembo Cloud and add it as `org_id` in context file generated above
* fetch the `org_id` from Tembo Cloud and add it as `org_id` in context file generated above
* generate a JWT token using steps [here](https://tembo.io/docs/tembo-cloud/security-and-authentication/api-authentication/) & add it as `tembo_access_token` to the credentials file generated above.

#### `tembo context list/set`
Expand All @@ -54,13 +54,18 @@ Validates `tembo.toml` and other configurations files.
Validates tembo.toml (same as `tembo validate`) and applies the changes to the context selected.

* applies changes and runs migration for all dbs
* **local docker:** stops existing container if it exists & run docker build/run + sqlx migration
* **tembo-cloud:** calls the api in appropriate environment to create/update instance
* **local docker:**
* runs `docker-compose down` to bring down all existing containers
* generates `Dockerfile` for each instance & builds a docker image
* generates `docker-compose` to provision all instances
* runs `docker-compose up -d` to spin up all instances
* runs `sqlx migration` against the instances
* **tembo-cloud:** Creates/updates instance on tembo-cloud by calling the api against the appropriate environment

#### `tembo delete`

- **local docker:** runs `docker stop & rm` command
- **tembo-cloud:** calls delete tembo api endpoint
- **local docker:** runs `docker-compose down` command to bring down all containers
- **tembo-cloud:** deletes the instance on tembo-cloud by calling the api

## Developing Tembo CLI

Expand Down Expand Up @@ -94,7 +99,7 @@ Delete the contents of the directory first and then run following command to re-
openapi-generator generate -i https://api.data-1.use1.tembo.io/api-docs/openapi.json -g rust -o . --additional-properties=packageName=tembodataclient
```

* Go to `tembodataclient/src/lib.rs` & add followng line at the top to disable clippy for the generated code
* Go to `tembodataclient/src/lib.rs` & add following line at the top to disable clippy for the generated code

```
#![allow(clippy::all)]
Expand All @@ -110,7 +115,7 @@ Delete the contents of the directory first and then run following command to re-
openapi-generator generate -i https://api.tembo.io/api-docs/openapi.json -g rust -o . --additional-properties=packageName=temboclient
```

* Go to `temboclient/src/lib.rs` & add followng line at the top to disable clippy for the generated code
* Go to `temboclient/src/lib.rs` & add following line at the top to disable clippy for the generated code

```
#![allow(clippy::all)]
Expand Down
19 changes: 17 additions & 2 deletions tembo-cli/src/cli/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use colorful::{Color, Colorful};
use simplelog::*;
use spinoff::{spinners, Spinner};
use std::io::{BufRead, BufReader};
use std::path::Path;
use std::process::Output;
use std::process::{Command as ShellCommand, Stdio};
use std::thread;
Expand Down Expand Up @@ -125,7 +126,21 @@ impl Docker {
Ok(())
}

pub fn docker_compose_down() -> Result<(), anyhow::Error> {
pub fn docker_compose_down(verbose: bool) -> Result<(), anyhow::Error> {
let path = Path::new("docker-compose.yml");
if !path.exists() {
if verbose {
println!(
"{} {}",
"✓".color(colors::indicator_good()).bold(),
"No docker-compose.yml found in the directory"
.color(Color::White)
.bold()
)
}
return Ok(());
}

let mut sp = Spinner::new(
spinners::Dots,
"Running Docker Compose Down",
Expand All @@ -152,7 +167,7 @@ impl Docker {

let stderr = String::from_utf8(output.stderr).unwrap();

if !stderr.is_empty() {
if !output.status.success() {
bail!("There was an issue stopping the instances: {}", stderr)
}

Expand Down
2 changes: 2 additions & 0 deletions tembo-cli/src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ fn docker_apply(
) -> Result<(), anyhow::Error> {
Docker::installed_and_running()?;

Docker::docker_compose_down(false)?;

for (_key, instance_setting) in instance_settings.clone().iter() {
let result = docker_apply_instance(verbose, instance_setting);

Expand Down
2 changes: 1 addition & 1 deletion tembo-cli/src/cmd/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn execute() -> Result<(), anyhow::Error> {
let env = get_current_context()?;

if env.target == Target::Docker.to_string() {
Docker::docker_compose_down()?;
Docker::docker_compose_down(true)?;
} else if env.target == Target::TemboCloud.to_string() {
return execute_tembo_cloud(env);
}
Expand Down

0 comments on commit 4451e2d

Please sign in to comment.