From def31f03ced28e05de6debe6d72d877f3734579d Mon Sep 17 00:00:00 2001
From: David Estes <5317198+dav1do@users.noreply.github.com>
Date: Tue, 19 Dec 2023 18:28:24 -0700
Subject: [PATCH] feat: Adjustments to defaults, postgres docker example, minor
fixes (#26)
* feat: Adjust interactive default prompts
They are similar when keeping everything, and when choosing to modify
and selecting all the default prompts (mainly changing gateway default)
* feat: Support custom app branch names with slash
Previously, the the app would fail to install due to file path issues,
now it works.
* Add docker postgres support via compose and update readme
Only for local testing if you don't want to install postgres binaries.
* Remove global npm install
- Installing globally doesn't work with how the daemon start is currently implemented. Rather than fix that, prefer a local install.
We don't need a global install. The test app brings its own node_modules folders and scripts to run ceramic/composedb, and this makes it easier to compare multiple versions.
---
.gitignore | 4 ++++
README.md | 27 +++++++++++++++++----
cli/src/install/ceramic_app_template.rs | 29 ++++++++++++++++-------
cli/src/install/ceramic_daemon.rs | 2 +-
cli/src/install/compose_db.rs | 2 +-
cli/src/lib.rs | 1 +
cli/src/prompt/ceramic_advanced_config.rs | 2 +-
cli/src/prompt/project.rs | 2 +-
compose.yaml | 15 ++++++++++++
9 files changed, 66 insertions(+), 18 deletions(-)
create mode 100644 compose.yaml
diff --git a/.gitignore b/.gitignore
index 628d3fb..39a8e63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,8 @@
Cargo.lock
tmp
.DS_Store
+# default wheel app names (historic and current)
ceramic-test-app
+ceramic-app
+# postgres compose volume
+ceramic-pg-data
diff --git a/README.md b/README.md
index ba95cd8..4c66ef4 100644
--- a/README.md
+++ b/README.md
@@ -14,8 +14,7 @@ Please follow the instructions that follow.
Setup Ceramic and ComposeDB in a quick and easy fashion
-Wheel can handle "default" behavior for Ceramic and ComposeDB based on your network, or you can customize your
-configuration by stepping through some or all the available configuration options.
+Wheel can handle "default" behavior for Ceramic and ComposeDB based on your network, or you can customize your configuration by stepping through some or all the available configuration options.
![](./gifs/running.gif)
@@ -35,11 +34,17 @@ If you don't want to step through prompts at all, you can use wheel in "quiet" m
This requires you to have already setup a DID and [CAS Auth](#cas-auth). Please run `wheel --help` for more options.
### CAS Auth
+
All networks other than InMemory require CAS authorization. Wheel will walk you through setting up CAS authorization, but
-for more information see https://composedb.js.org/docs/0.4.x/guides/composedb-server/access-mainnet#step-1-start-your-node-and-copy-your-key-did.
+for more information read about [starting your node and copying your DID](https://composedb.js.org/docs/0.4.x/guides/composedb-server/access-mainnet#step-1-start-your-node-and-copy-your-key-did).
## Setting up Postgres
-If using Postgres, it will need to be setup. Visit https://www.postgresql.org/download/ to install postgres.
+
+If using Postgres, it will need to be setup. *Note*: For production ceramic nodes, only postgres is supported.
+
+### Option 1: Local Install
+
+Visit to install postgres locally.
You will then need to configure postgres for ceramic.
@@ -53,4 +58,16 @@ You will then need to configure postgres for ceramic.
The connection string you provide to wheel will then be `postgres://ceramic:password@127.0.0.1:5432/ceramic`
-*Note*: For production ceramic nodes, only postgres is supported.
+### Option 2: Using Docker
+
+For local development and testing, you can run a postgres in docker rather than installing a postgres server locally. The wheel defaults are to use sqlite, however, this is an option if you want to verify postgres indexing. It is not recommended to run a production node this way! This requires having [Docker](https://docs.docker.com/engine/install/) and [Docker compose](https://docs.docker.com/compose/install/) installed. You can read more about the [official Postgres image](https://www.docker.com/blog/how-to-use-the-postgres-docker-official-image/).
+
+Copy the [compose.yaml](https://github.com/ceramicstudio/wheel/blob/main/compose.yaml) file to your computer. You are welcome to change the values, but by default the connection string for wheel will be `postgres://ceramic:password@127.0.0.1:5432/ceramic`. Start the container:
+
+ docker compose up -d
+
+To stop it
+
+ docker compose down # include -v to delete the data
+
+Postgres data will be stored in the `./ceramic-data` folder using a docker volume.
diff --git a/cli/src/install/ceramic_app_template.rs b/cli/src/install/ceramic_app_template.rs
index fd848a7..ea7d89f 100644
--- a/cli/src/install/ceramic_app_template.rs
+++ b/cli/src/install/ceramic_app_template.rs
@@ -1,4 +1,5 @@
use crate::DidAndPrivateKey;
+use anyhow::Context;
use std::path::Path;
use tokio::io::AsyncWriteExt;
@@ -13,14 +14,16 @@ pub async fn install_ceramic_app_template(
template_branch: &Option,
daemon_config_file: impl AsRef,
) -> anyhow::Result<()> {
- log::info!("Setting up application template from {}", REPO);
- let zip_path = format!(
- "/archive/refs/heads/{}.zip",
- template_branch
- .as_ref()
- .map(|s| s.as_str())
- .unwrap_or("main")
+ let branch_name = template_branch
+ .as_ref()
+ .map(|s| s.as_str())
+ .unwrap_or("main");
+ log::info!(
+ "Setting up application template from {} using branch {}",
+ REPO,
+ branch_name
);
+ let zip_path = format!("/archive/refs/heads/{}.zip", branch_name);
let data = reqwest::get(format!("{}{}", REPO, zip_path))
.await?
.bytes()
@@ -29,7 +32,10 @@ pub async fn install_ceramic_app_template(
let output_dir = working_directory.join(format!("{}-app", project_name));
let b_output_dir = working_directory.to_path_buf();
- let unzip_dir = working_directory.join("ComposeDbExampleApp-main");
+ let unzip_dir = working_directory.join(&format!(
+ "ComposeDbExampleApp-{}",
+ branch_name.replace("/", "-")
+ ));
if tokio::fs::try_exists(&unzip_dir).await? {
tokio::fs::remove_dir_all(&unzip_dir).await?;
}
@@ -42,7 +48,12 @@ pub async fn install_ceramic_app_template(
})
.await??;
- tokio::fs::rename(&unzip_dir, &output_dir).await?;
+ tokio::fs::rename(&unzip_dir, &output_dir)
+ .await
+ .context(format!(
+ "failed to rename {:?} to {:?}",
+ unzip_dir, output_dir
+ ))?;
npm_install(&output_dir, &None, false).await?;
diff --git a/cli/src/install/ceramic_daemon.rs b/cli/src/install/ceramic_daemon.rs
index 4899020..6268902 100644
--- a/cli/src/install/ceramic_daemon.rs
+++ b/cli/src/install/ceramic_daemon.rs
@@ -39,7 +39,7 @@ pub async fn install_ceramic_daemon(
if let Some(v) = version.as_ref() {
program.push_str(&format!("@{}", v.to_string()));
}
- npm_install_package(&working_directory, &program, true).await?;
+ npm_install_package(&working_directory, &program, false).await?;
let ans = match start_ceramic {
Some(true) => true,
diff --git a/cli/src/install/compose_db.rs b/cli/src/install/compose_db.rs
index 038cddc..37059fb 100644
--- a/cli/src/install/compose_db.rs
+++ b/cli/src/install/compose_db.rs
@@ -30,7 +30,7 @@ pub async fn install_compose_db(
if let Some(v) = version.as_ref() {
program.push_str(&format!("@{}", v.to_string()));
}
- npm_install_package(working_directory, &program, true).await?;
+ npm_install_package(working_directory, &program, false).await?;
let env_file = working_directory.join("composedb.env");
let mut f = tokio::fs::OpenOptions::new()
diff --git a/cli/src/lib.rs b/cli/src/lib.rs
index 6204ec7..4aa36fe 100644
--- a/cli/src/lib.rs
+++ b/cli/src/lib.rs
@@ -156,6 +156,7 @@ Selection is used to setup project defaults"#)
let with_app_template = if with_composedb {
Confirm::new("Include ComposeDB Sample Application?")
.with_help_message("Installs a sample application using ComposeDB")
+ // different than non-interactive defaults, but this user is more likely to have an app
.with_default(false)
.prompt()?
} else {
diff --git a/cli/src/prompt/ceramic_advanced_config.rs b/cli/src/prompt/ceramic_advanced_config.rs
index c2cb82b..294eb74 100644
--- a/cli/src/prompt/ceramic_advanced_config.rs
+++ b/cli/src/prompt/ceramic_advanced_config.rs
@@ -149,7 +149,7 @@ fn configure_network(cfg: &mut Config) -> anyhow::Result<()> {
pub fn configure_node(cfg: &mut Config) -> anyhow::Result<()> {
let gateway = Confirm::new("Run as gateway?")
.with_help_message("Gateway nodes cannot perform mutations")
- .with_default(true)
+ .with_default(false)
.prompt()?;
cfg.node.gateway = gateway;
Ok(())
diff --git a/cli/src/prompt/project.rs b/cli/src/prompt/project.rs
index f65e812..01489f5 100644
--- a/cli/src/prompt/project.rs
+++ b/cli/src/prompt/project.rs
@@ -8,7 +8,7 @@ pub struct Project {
pub async fn configure_project(working_directory: impl AsRef) -> anyhow::Result {
let project_name = Text::new("Project Name")
- .with_default("ceramic-test-app")
+ .with_default("ceramic-app")
.prompt()?;
let project_path = working_directory.as_ref().join(&project_name);
let project_path = Text::new("Project Path")
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 0000000..9d1fe0b
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,15 @@
+version: '3.1'
+
+services:
+ db:
+ image: postgres:16
+ container_name: ceramic-db
+ restart: always
+ environment:
+ POSTGRES_USER: ceramic
+ POSTGRES_PASSWORD: password
+ DATABASE: ceramic
+ volumes:
+ - ./ceramic-pg-data:/var/lib/postgresql/data
+ ports:
+ - 5432:5432