Skip to content

Commit

Permalink
refactoring for all node types
Browse files Browse the repository at this point in the history
  • Loading branch information
iDmple committed Dec 17, 2023
2 parents 141d971 + e7d349a commit c361c75
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
context: docker
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: |
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Make release

on:
push:
tags:
- v*
branches:
- docker

jobs:
push-store-image:
runs-on: ubuntu-latest
defaults:
run:
working-directory: "."
steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@main

- name: "Run release script"
run: npm i && node scripts/gh-release.js

- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1

- name: "Release"
uses: softprops/action-gh-release@v1
with:
body_path: release-notes.md
files: ./release/*.zip
name: Unchained v${{ steps.package-version.outputs.current-version }}
tag_name: v${{ steps.package-version.outputs.current-version }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ conf.*.yaml
.env
dist
data
release
release-notes.md
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 53 additions & 10 deletions quickstart.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
# Quick Start

## Prerequisites
## Using Docker

Running Unchained with Docker is straightforward. Make sure you
[have Docker installed](https://docs.docker.com/engine/install/).
Then, head over to the
[Unchained release page](https://github.com/KenshiTech/unchained/releases)
on GitHub, find the latest Docker release file (file name ends with
`-docker.zip`), download it, and uncompress it.

Once done, head to the uncompressed directory and use one of the following
commands in your favorite terminal emulator.

### Start Node

To start the node, run this command while in the release directory:

```bash
./scripts/start_node.sh
```

### Stop Node

To stop the node, run this command while in the release directory:

```bash
./scripts/stop_node.sh
```

### View Node

To view the node, run this command while in the release directory:

```bash
./scripts/view_node.sh
```

## Installing Locally

Follow these instructions if you want to install Unchained and its dependencies
locally, on a
[RaspberryPi](https://forum.kenshi.io/t/how-to-set-up-your-unchained-node-on-raspberry-pi/132),
on a server, or on your computer/laptop.

### Prerequisites

To run a Kenshi Unchained validator, you need to install Node.js. Follow the
installation instructions for your platform on the Node.js
[official installation](https://nodejs.org/en/download/package-manager) page.

## Install the Unchained Client
### Install the Unchained Client

The easiest way to get started is to install the Unchained client globally.
On windows, Linux, MacOS, and BSD, run this command in CMD or terminal:
The easiest way to get the Unchained client is to install it globally. On
windows, Linux, MacOS, and BSD, run this command in CMD or terminal:

```bash
npm i -g @kenshi.io/unchained
Expand All @@ -22,7 +65,7 @@ Note: On UNIX-like operating systems, you might need to run this command with
sudo npm i -g @kenshi.io/unchained
```

### Updates
#### Updates

To update the Unchained client, you can re-run the installation command above.
Adding `@latest` to the end would result in installing the latest version.
Expand All @@ -31,7 +74,7 @@ Adding `@latest` to the end would result in installing the latest version.
sudo npm i -g @kenshi.io/unchained@latest
```

## MongoDB
### MongoDB

Note: Skip this step if you're planning to run a lite node.

Expand All @@ -44,12 +87,12 @@ free credits on [Digital Ocean](https://try.digitalocean.com/freetrialoffer/).

Contact us on [Telegram](https://t.me/kenshi) if you need help with this step.

### MongoDB Atlas
#### MongoDB Atlas

If you want to use MongoDB Atlas, there is a great tutorial you can watch on the
[official MongoDB YouTube channel](https://www.youtube.com/watch?v=jXgJyuBeb_o).

### Installing MongoDB Locally
#### Installing MongoDB Locally

If you want to install MongoDB locally, first follow the official MongoDB
installation
Expand All @@ -63,7 +106,7 @@ mongodb://localhost:27017/<database>
Replace `<database>` with the name of the database you want to use (for example,
`unchained`).

#### Securing Your Local MongoDB
##### Securing Your Local MongoDB

To secure your local MongoDB installation, you should first enable DB
authentication. To do so, follow the guide
Expand All @@ -87,7 +130,7 @@ Replace `user` with your username, replace `<password>` with a
`<database>` with the name of the database you want to use for Unchained. Your
user needs `readWrite` access to this database.

## Configuration
### Configuration

You need a configuration file to get started. You can start with the following
config:
Expand Down
65 changes: 65 additions & 0 deletions scripts/gh-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { writeFileSync, readFileSync, mkdirSync, copyFileSync } from "fs";
import { dirname } from "path";
import { execSync } from "child_process";

const packageJson = JSON.parse(readFileSync("./package.json"));

const about = [
"Unchained is a decentralized, peer-to-peer network for data validation.",
"Unchained nodes work to validate data together and are rewarded in KNS tokens.",
"The validated data can then be queried by consumer in exchange for KNS tokens.",
"Learn more about Unchained [here](https://kenshi.io/docs/unchained).",
].join(" ");

const questions = [
"Have any questions? Ask in the [forum](https://forum.kenshi.io/c/unchained),",
"in our [chat](https://t.me/KenshiTech/85602), or send us an",
"[email](mailto:hi@kenshi.io).",
].join(" ");

const releaseTemplate = (changes) => `\
${about}
${questions}
${changes}
`;

const makeReleaseNotes = async () => {
const url =
"https://app.whatthediff.ai/changelog/github/KenshiTech/unchained.json";
const req = await fetch(url);
const notes = await req.json();
const wtd = notes.changelog.data[0];

const changes = wtd.comment.replace(/^## PR Summary/, "## Changes");
const release = releaseTemplate(changes);

writeFileSync("./release-notes.md", release);
};

const makeReleaseFile = (name, files) => {
const dirName = `unchained-v${packageJson.version}-${name}`;
mkdirSync(`release/${dirName}`, { recursive: true });
for (const { source, target } of files) {
const dirToMake = dirname(target);
if (dirToMake !== ".") {
mkdirSync(`release/${dirName}/${dirToMake}`, { recursive: true });
}
copyFileSync(source, `release/${dirName}/${target}`);
}
execSync(`cd release && zip -r ${dirName}.zip ${dirName}`);
};

await makeReleaseNotes();
mkdirSync("./release", { recursive: true });
makeReleaseFile("docker", [
{ source: "docker/compose.yaml", target: "compose.yaml" },
{ source: "docker/Dockerfile", target: "Dockerfile" },
{ source: "docker/scripts/start_node.sh", target: "scripts/start_node.sh" },
{ source: "docker/scripts/stop_node.sh", target: "scripts/stop_node.sh" },
{ source: "docker/scripts/view_node.sh", target: "scripts/view_node.sh" },
{ source: ".env.template", target: ".env.template" },
{ source: "conf.yaml.template", target: "conf.yaml.template" },
{ source: "LICENSE", target: "LICENSE" },
]);

0 comments on commit c361c75

Please sign in to comment.