Skip to content

Commit

Permalink
Added npm wrapper (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
samyfodil authored Jan 16, 2024
1 parent db993ff commit 2f9f3b3
Show file tree
Hide file tree
Showing 8 changed files with 549 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/testGIT
**/testGIT
npm/bin
npm/node_modules
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@

## Installation

## Binary
## npm
Run:

```bash
$ curl https://get.tau.link/dream | sh
$ npm i dreamland
```

## Script
Run:

```bash
$ curl https://get.tau.link/dream | sh
```

## Source
First, use Go to install `dreamland`:
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.19
require (
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/pterm/pterm v0.12.65
github.com/taubyte/go-interfaces v0.2.14-0.20230921175616-0dd966927da2
github.com/taubyte/go-interfaces v0.2.14-0.20230928164739-cb43412ebf90
github.com/taubyte/go-specs v0.10.8-0.20230912140105-e8d804edc77c
github.com/taubyte/http v0.10.5
github.com/taubyte/tau v1.0.11-0.20230921211832-eff68721994c
github.com/taubyte/tau v1.1.0
github.com/taubyte/utils v0.1.7
github.com/urfave/cli/v2 v2.25.7
)
Expand Down Expand Up @@ -213,8 +213,8 @@ require (
github.com/taubyte/go-seer v1.0.6 // indirect
github.com/taubyte/go-simple-container v0.4.4 // indirect
github.com/taubyte/go-simple-git v0.2.5 // indirect
github.com/taubyte/p2p v0.10.1-0.20230919152907-f26fd82a39d3 // indirect
github.com/taubyte/vm v1.0.3 // indirect
github.com/taubyte/p2p v0.11.0 // indirect
github.com/taubyte/vm v1.0.4 // indirect
github.com/taubyte/vm-core-plugins v0.3.4 // indirect
github.com/taubyte/vm-orbit v1.0.0 // indirect
github.com/tetratelabs/wazero v1.0.3 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ github.com/taubyte/config-compiler v0.4.6 h1:9s3xn955imE7gAyVFpcsBEkowhCir78b1HP
github.com/taubyte/config-compiler v0.4.6/go.mod h1:gaohk1BSknIudo16QSgeQqVWVGLyusPPdLn+wQ+xAmY=
github.com/taubyte/domain-validation v1.0.1 h1:T1iRls4p5+uJLR8R/wf+dBt9Rlahg9BcCtBVbkoD0Ik=
github.com/taubyte/domain-validation v1.0.1/go.mod h1:/X3yd7sBjnE323rA8I9PiUt5+NlKU4I02nQik25Vqe8=
github.com/taubyte/go-interfaces v0.2.14-0.20230921175616-0dd966927da2 h1:hy6J8zeFXlJGMiEX9wYuGg2dU8E5zb7ujV+0F8FFVaE=
github.com/taubyte/go-interfaces v0.2.14-0.20230921175616-0dd966927da2/go.mod h1:OWQlR4DriWCjkgmfFFrlynXd4yjigUxKGIeUBWv1Mmw=
github.com/taubyte/go-interfaces v0.2.14-0.20230928164739-cb43412ebf90 h1:vs5vfSUD6enNlvMB0XjRtTm0b9ze+PYaQ7MJEA6k6W4=
github.com/taubyte/go-interfaces v0.2.14-0.20230928164739-cb43412ebf90/go.mod h1:OWQlR4DriWCjkgmfFFrlynXd4yjigUxKGIeUBWv1Mmw=
github.com/taubyte/go-project-schema v0.9.3 h1:2H0ClUZq7f97OgtL0FUe9tv2v12wOmnTAIiJGLei/gU=
github.com/taubyte/go-project-schema v0.9.3/go.mod h1:8Rt5zsVfj8qbYCT+7++oax/nFVKvVfAepzVkqXrNTs8=
github.com/taubyte/go-sdk v0.3.9 h1:mwwjiub/Jc987kfWvVfAcx63fMRAYB9cj4yhJq+CSyo=
Expand All @@ -903,14 +903,14 @@ github.com/taubyte/go-specs v0.10.8-0.20230912140105-e8d804edc77c/go.mod h1:lhCi
github.com/taubyte/http v0.10.5 h1:0dpSYi1XvryxO7U1Df5cgh+6LWKtaMypILQjgfJdExw=
github.com/taubyte/http v0.10.5/go.mod h1:hSJYC7/yqRkrsZYe1Q0c194GKkVD0KGWDzw0sC+SAiU=
github.com/taubyte/odo v0.0.0-20230726203810-bdae9f37e8f8 h1:+r57pU7UW1DZkBgOUsBh0zmRSg77sz+bJ3DaybLR3z0=
github.com/taubyte/p2p v0.10.1-0.20230919152907-f26fd82a39d3 h1:NbgrtVT1D0IOnIidXWIA8JN7SykD5QRT20Ak+YTFflc=
github.com/taubyte/p2p v0.10.1-0.20230919152907-f26fd82a39d3/go.mod h1:Uo464wZDiMeuP7GDHvjUjwGbnm72ByuGofk2O2m58yI=
github.com/taubyte/tau v1.0.11-0.20230921211832-eff68721994c h1:bs8hxE2jZcQMrAtp0WVe9Fi24KStCpVjsq+O2RLks1Y=
github.com/taubyte/tau v1.0.11-0.20230921211832-eff68721994c/go.mod h1:jxkCqLFZ0JCYCWmA1jeA99hNnoicGAUaYDpO3kXKVYw=
github.com/taubyte/p2p v0.11.0 h1:gtrCZk6/AqIB62UuRO3iz1mcqmqUc0/AoOmISGHyrB8=
github.com/taubyte/p2p v0.11.0/go.mod h1:Uo464wZDiMeuP7GDHvjUjwGbnm72ByuGofk2O2m58yI=
github.com/taubyte/tau v1.1.0 h1:QH3frIsepndNIafkUiSTFcy/v4J5FDPLwBax/yGauS0=
github.com/taubyte/tau v1.1.0/go.mod h1:aMzDFG/f+w3NqefM2GLxPUaAi5s7tGrhJu9hubGK2sY=
github.com/taubyte/utils v0.1.7 h1:iFMOxhBNJKdUrD+Z1UjP9W5559LlQN8178V54uLngdk=
github.com/taubyte/utils v0.1.7/go.mod h1:MWO21qZu7AcBwJkJLsltwb3zWyN84xSexLCU28JC4gM=
github.com/taubyte/vm v1.0.3 h1:Z9IYHdHiWVh0/v1+dvWblGe6Ny+ni3t4yr8GIgfhavg=
github.com/taubyte/vm v1.0.3/go.mod h1:5pRQKirHakEXSdhCPtkbom1VA2z64JO01ce1F4JibBM=
github.com/taubyte/vm v1.0.4 h1:yHM61nU1GYwt+gfqXMvu+AkmA9tr7CuPYja4TJKeY7E=
github.com/taubyte/vm v1.0.4/go.mod h1:WXBnk6d4WaOvT5g05Co66LDXe+gt8SFfO9nEq1srdQo=
github.com/taubyte/vm-core-plugins v0.3.4 h1:NPYZfcL6JTS+YsQ5TYn/fO657L0Sqqk8vte7GBEtlqA=
github.com/taubyte/vm-core-plugins v0.3.4/go.mod h1:jQBHrYYVvHjNP0fy0Sx3KsFQ4JMh8f0cmbSE6OXr+j8=
github.com/taubyte/vm-orbit v1.0.0 h1:oSzlnGUTJWItGoz9WTS6nW68sh0zcllOOQkLtbc0LkU=
Expand Down
163 changes: 163 additions & 0 deletions npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
`Dreamland` is a local development tool that lets you run a full-fledged Taubyte-based Cloud on your machine. For documentation, visit [https://tau.how](https://tau.how).

## Usage

Dreamland can simulate multiple Taubyte networks, each referred to as a 'universe'. You can start a new universe (default name is "blackhole") with the following command:

```bash
$ dream new multiverse
```
Once the message `[SUCCESS] Universe blackhole started!` appears, your local Taubyte instance is ready. You are now running elder, monkey, tns, hoarder, patrick, auth, seer, and substrate nodes locally on your machine.

You can interact with Dreamland using the Web Console. Dreamland can be selected from the network selection dropdown if it's active locally. From here, you can create new projects, import existing ones, trigger builds, and run resources like websites and dFuncs.


## Connecting Console to Dreamland
Similarly to when selecting a network on web console ([console.taubyte.com](https://console.taubyte.com)), dreamland can be selected from the network selection dropdown
If dreamland is active, then a selection option for dreamland will appear in the network selection
![](images/web-console-login.png)


### Import a project
If your intention is to create a new project, follow the steps that you normally would if you were connected to a production cloud, by clicking `Create Project`. Note that this will create a new GitHub repo, so it is recommended that you create this as a private repo.

However, if you want to work on an existing project click on `Import Project`. This will show a menu with two dropdowns, one for your config repository, the other for your inline code repository.
> One convenient feature is that once selecting a config repository, if a code repository is found matching the config, it will be selected automatically.
## Branches
If importing a project, it is recommended that you make changes to your project on a branch, rather than master/main to not affect production deployments.
> If using Web Console Once selecting a project, you may checkout or create a new branch from the top bar.
> ![](images/web-console-branch-selector.png)

By default, ci/cd events are triggered by events on the master/main branch. You will need to override this using a fixture `setBranch`:

```bash
$ dream inject set-branch {name-of-branch}
```

## Websites and Libraries

If importing a project that has a library, or website you will need to register the resource on auth, before being able to trigger a build for these resources. This can be achieved on web console by going to the resource and using the fix repo tool.

![](../images/web-console-fix-repo.png)


## Running HTTP Resources

HTTP resources run locally on Dreamland. You need to add the domains for these resources to your `/etc/hosts` file under `127.0.0.1`. To access these resources, you also need the port that the substrate node is running on. Once you have the domain and the port, you can access the resource at `{domain}:{port}/{path}`.

## Viewing Port Information

You can view the ports that your local Tau protocols are running on using the status command.

To view a specific protocol's port (e.g., seer, auth, patrick, tns, hoarder, substrate):

```bash
$ dream status {protocol-name}
```

Example:
```bash
$ dream status substrate

@ http://127.0.0.1:11429

┌─────────────────────┬────────┬───────┐
│ substrate@blackhole │ http │ 11429 │
│ ├────────┼───────┤
│ │ p2p │ 11182 │
│ ├────────┼───────┤
│ │ copies │ 1 │
│ ├────────┼───────┤
│ │ dns │ 11204 │
└─────────────────────┴────────┴───────┘
```

To view all ports:
```bash
$ dream status universe
```

Output will look like:
```bash
┌───────┬─────────────────────┬────────┬───────┐
│ Nodes │ elder@blackhole │ p2p │ 10951 │
│ ├─────────────────────┼────────┼───────┤
│ │ hoarder@blackhole │ http │ 10900 │
│ │ ├────────┼───────┤
│ │ │ p2p │ 11042 │
│ │ ├────────┼───────┤
│ │ │ copies │ 1 │
│ │ ├────────┼───────┤
│ │ │ dns │ 11204 │
│ ├─────────────────────┼────────┼───────┤
│ │ monkey@blackhole │ p2p │ 11063 │
│ │ ├────────┼───────┤
│ │ │ copies │ 1 │
│ │ ├────────┼───────┤
│ │ │ dns │ 11204 │
│ │ ├────────┼───────┤
│ │ │ http │ 10900 │
│ ├─────────────────────┼────────┼───────┤
│ │ tns@blackhole │ copies │ 1 │
│ │ ├────────┼───────┤
│ │ │ dns │ 11204 │
│ │ ├────────┼───────┤
│ │ │ http │ 11366 │
│ │ ├────────┼───────┤
│ │ │ p2p │ 11126 │
│ ├─────────────────────┼────────┼───────┤
│ │ patrick@blackhole │ copies │ 1 │
│ │ ├────────┼───────┤
│ │ │ dns │ 11204 │
│ │ ├────────┼───────┤
│ │ │ http │ 11324 │
│ │ ├────────┼───────┤
│ │ │ p2p │ 11084 │
│ ├─────────────────────┼────────┼───────┤
│ │ auth@blackhole │ p2p │ 11021 │
│ │ ├────────┼───────┤
│ │ │ copies │ 1 │
│ │ ├────────┼───────┤
│ │ │ dns │ 11204 │
│ │ ├────────┼───────┤
│ │ │ http │ 11345 │
│ ├─────────────────────┼────────┼───────┤
│ │ seer@blackhole │ http │ 11303 │
│ │ ├────────┼───────┤
│ │ │ p2p │ 11105 │
│ │ ├────────┼───────┤
│ │ │ copies │ 1 │
│ │ ├────────┼───────┤
│ │ │ dns │ 11204 │
│ ├─────────────────────┼────────┼───────┤
│ │ client@blackhole │ p2p │ 10952 │
│ ├─────────────────────┼────────┼───────┤
│ │ substrate@blackhole │ dns │ 11204 │
│ │ ├────────┼───────┤
│ │ │ http │ 11429 │
│ │ ├────────┼───────┤
│ │ │ p2p │ 11182 │
│ │ ├────────┼───────┤
│ │ │ copies │ 1 │
└───────┴─────────────────────┴────────┴───────┘
```


## Running Fixtures

Fixtures are used to inject event & data into a universe. The main fixtures you might need are `pushAll` and `attachPlugin`.

`push-all` fixture:

```bash
$ dream inject push-all
```

`attach-plugin` fixture:

```bash
$ dream inject attach-plugin -p {path-to-plugin}
```

120 changes: 120 additions & 0 deletions npm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env node

const fs = require("fs");
const path = require("path");
const axios = require("axios");
const ProgressBar = require("progress");
const { spawn } = require("child_process");
const tar = require("tar");
const packageJson = require("./package.json");

const binaryDir = path.join(__dirname, "bin");
const binaryPath = path.join(binaryDir, "dreamland");
const packageVersion = packageJson.version;

function binaryExists() {
return fs.existsSync(binaryPath);
}

function parseAssetName() {
let os, arch;

if (process.platform === "darwin") {
os = "darwin";
} else if (process.platform === "linux") {
os = "linux";
} else if (process.platform === "win32") {
os = "windows";
} else {
os = null;
}

if (process.arch === "x64") {
arch = "amd64";
} else if (process.arch === "arm64") {
arch = "arm64";
} else {
arch = null;
}

return { os, arch };
}

async function downloadAndExtractBinary() {
if (binaryExists()) {
return;
}

let version = packageVersion;

const { os: currentOs, arch: currentArch } = parseAssetName();
const assetName = `dreamland_${version}_${currentOs}_${currentArch}.tar.gz`;
const assetUrl = `https://github.com/taubyte/dreamland/releases/download/v${version}/${assetName}`;

console.log(`Downloading dreamland v${version}...`);
const { data, headers } = await axios({
url: assetUrl,
method: "GET",
responseType: "stream",
});

const totalLength = headers["content-length"];
const progressBar = new ProgressBar("-> downloading [:bar] :percent :etas", {
width: 40,
complete: "=",
incomplete: " ",
renderThrottle: 1,
total: parseInt(totalLength),
});

if (!fs.existsSync(binaryDir)) {
fs.mkdirSync(binaryDir);
}

const tarPath = path.join(binaryDir, assetName);
const writer = fs.createWriteStream(tarPath);
data.on("data", (chunk) => progressBar.tick(chunk.length));
data.pipe(writer);

return new Promise((resolve, reject) => {
writer.on("finish", async () => {
console.log(`Extracting dreamland v${version}...`);
await tar.x({
file: tarPath,
C: binaryDir,
});
fs.unlinkSync(tarPath); // Remove the tarball after extraction
resolve();
});
writer.on("error", reject);
});
}

function executeBinary() {
if (!binaryExists()) {
console.error("Binary not found. Please run the install script.");
return;
}

// Capture arguments passed to the script, excluding the first two elements
const args = process.argv.slice(2);

const child = spawn(binaryPath, args, {
stdio: "inherit",
});

child.on("error", (err) => {
console.error("Failed to start binary:", err);
});
}

async function main() {
try {
await downloadAndExtractBinary();
executeBinary();
} catch (err) {
console.error(err.message);
}
}

main();
Loading

0 comments on commit 2f9f3b3

Please sign in to comment.