diff --git a/.gitignore b/.gitignore index bc75674a4d..a6dcb02de6 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ tags /ckb-miner.toml /data /specs +/ckb-dev +/ckb-testnet +/ckb-mainnet diff --git a/docker/hub/Dockerfile b/docker/hub/Dockerfile index 412d8b2f56..f77a526b76 100644 --- a/docker/hub/Dockerfile +++ b/docker/hub/Dockerfile @@ -61,6 +61,7 @@ COPY --from=ckb-builder \ /usr/lib/x86_64-linux-gnu/libcrypto.so.* \ /usr/lib/x86_64-linux-gnu/ COPY --from=ckb-builder /ckb/target/release/ckb /bin/ckb +RUN /bin/ckb init --force USER ckb diff --git a/docs/configure.md b/docs/configure.md index 5634ec5978..e7ad88f535 100644 --- a/docs/configure.md +++ b/docs/configure.md @@ -12,7 +12,7 @@ CKB looks for configuration files in ``, which is the current workin Command line argument `-C ` sets the value of `` to ``. -If CKB could not find the config file, it will use the default bundled ones. +Command `ckb init` initializes a directory by exporting the config files. Some config file may refer to other files, for example, `chain.spec` in `ckb.toml` and `system_cells` in chain spec file. The file is referred via diff --git a/docs/quick-start.md b/docs/quick-start.md index 7616797828..ddff40c918 100644 --- a/docs/quick-start.md +++ b/docs/quick-start.md @@ -3,8 +3,16 @@ Following steps will assume that the shell can find the executable `ckb`, see how to [get CKB](get-ckb.md). -CKB uses current directory to store data. It is recommended to setup the -directory with default config files: +First creates a directory to run CKB + +```shell +mkdir ckb-dev +cd ckb-dev +``` + +All the following commands will run in this same directory. + +Then init the directory with the default config files. ```shell ckb init @@ -14,6 +22,8 @@ See how to [configure CKB](configure.md) if you like to tweak the options. ## Start Node +Start the node from the directory + ```shell ckb run ``` diff --git a/resource/src/lib.rs b/resource/src/lib.rs index 36ddd8b91d..600a1cb8cd 100644 --- a/resource/src/lib.rs +++ b/resource/src/lib.rs @@ -28,6 +28,13 @@ pub enum Resource { } impl Resource { + pub fn is_bundled(&self) -> bool { + match self { + Resource::Bundled(_) => true, + _ => false, + } + } + /// Gets resource content pub fn get(&self) -> Result> { match self { diff --git a/src/setup/app_config.rs b/src/setup/app_config.rs index 231b32ede4..3688e04f26 100644 --- a/src/setup/app_config.rs +++ b/src/setup/app_config.rs @@ -59,6 +59,10 @@ pub struct ChainConfig { } impl AppConfig { + pub fn is_bundled(&self) -> bool { + self.resource.is_bundled() + } + pub fn load_for_subcommand( locator: &ResourceLocator, subcommand_name: &str, diff --git a/src/setup/mod.rs b/src/setup/mod.rs index ea5c4a17ea..088936ea0d 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -40,6 +40,10 @@ impl Setup { let resource_locator = locator_from_matches(matches)?; let config = AppConfig::load_for_subcommand(&resource_locator, subcommand_name)?; + if config.is_bundled() { + eprintln!("Not a CKB directory, initialize one with `ckb init`."); + return Err(ExitCode::Config); + } Ok(Setup { subcommand_name: subcommand_name.to_string(),