Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adjustments to defaults, postgres docker example, minor fixes #26

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 <https://www.postgresql.org/download/> to install postgres locally.

You will then need to configure postgres for ceramic.

Expand All @@ -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.
29 changes: 20 additions & 9 deletions cli/src/install/ceramic_app_template.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::DidAndPrivateKey;
use anyhow::Context;
use std::path::Path;
use tokio::io::AsyncWriteExt;

Expand All @@ -13,14 +14,16 @@ pub async fn install_ceramic_app_template(
template_branch: &Option<String>,
daemon_config_file: impl AsRef<Path>,
) -> 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()
Expand All @@ -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?;
}
Expand All @@ -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?;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/install/ceramic_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/install/compose_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/prompt/ceramic_advanced_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion cli/src/prompt/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Project {

pub async fn configure_project(working_directory: impl AsRef<Path>) -> anyhow::Result<Project> {
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")
Expand Down
15 changes: 15 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -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