Giter VIP home page Giter VIP logo

dream's Introduction

Dream
Dream

Local Coding Equals Global Production

Release License

Dream is a CLI tool that forms part of Taubyte's suite of development tools, designed to create local cloud environments.

Installation

npm

Run:

$ npm i @taubyte/dream

Script

Run:

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

Source

Source is located in https://github.com/taubyte/tau under tools/dream.

Usage

Dream 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:

$ 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 Dream using the Web Console. Dream 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 Dream

Similarly to when selecting a network on web console (console.taubyte.com), dream can be selected from the network selection dropdown If dream is active, then a selection option for dream will appear in the network selection

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.

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

$ 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.

Running HTTP Resources

HTTP resources run locally on Dream. 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):

$ dream status {protocol-name}

Example:

$ dream status substrate

@ http://127.0.0.1:11429

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

To view all ports:

$ dream status universe 

Output will look like:

┌───────┬─────────────────────┬────────┬───────┐
│ 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:

$ dream inject push-all

attach-plugin fixture:

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

dream's People

Contributors

samyfodil avatar tafseer-khan avatar arontaubyte avatar

Stargazers

Torkild Dyvik Olsen avatar Tertius Stander avatar Nikolaus Schlemm avatar Adam Żbikowski avatar Yongbin Xu avatar Guillaume Bonnet avatar Jeff Bouchard avatar Minho Ryang avatar Antoine avatar Zhiqiang ZHOU avatar 0xrinegade avatar M Haidar Hanif avatar Erick Heredia avatar  avatar Ryuta Suzuki avatar Steve Manuel avatar  avatar Traian Simedru avatar Sachit avatar  avatar Abhishek Nair avatar Tim avatar Rurick Maqueo Poisot avatar  avatar  avatar Chris Ulanowicz avatar  avatar Brock Vojkovic avatar Magnus Jurdal avatar Eugene Klimov avatar Gabriel Dumitrescu avatar Sven Hohlfeld avatar Darren Bennett avatar FILstorage avatar George Reyes avatar Nicholas Cheung avatar Dev avatar Alan Nhan avatar Nicholas Guerrero avatar  avatar Edward Fernandes avatar Can Evgin avatar  avatar Vinny Shipley avatar Jan Rychlý avatar  avatar Tarish K. avatar Nikolay Kolev avatar Kaviyabharathi avatar Prudo Lodonou avatar Achuthan Ram avatar Riyad Shauk avatar Nelson avatar Margaret Camilletti avatar  avatar Jacob Melosi avatar  avatar Lucy Conner avatar jayser avatar Amandagifford101 avatar  avatar Diana Palafox avatar Stardust avatar  avatar Luis Lobo Borobia avatar

Watchers

 avatar Magnus Jurdal avatar

dream's Issues

Handling imports

Hey guys, I'm not experienced in Go, but have a great experience programming in general.

I was investigating api.go file and have a suggestion related to the imports that can be handled better with a simple try catch.

It would be easy to print which package is dealing failing to import locally(cause: versioning, updates, path, broken)

Apart from that, I really enjoyed playing with the app. Great invention!

Create a npm wrapper

Make is easy to install and use even if you don't have golang

npm i dreamland
$ dream

Ran Gosec and found security vulnerabilities

[/Users/margaretcamilletti/go/src/dreamland/service/new.go:30-32] - G402 (CWE-295): TLS MinVersion too low. (Confidence: HIGH, Severity: HIGH)
29: c.client.Transport = &http.Transport{

30: TLSClientConfig: &tls.Config{
31: RootCAs: rootCAs,
32: },
33: }

[/Users/margaretcamilletti/go/src/dreamland/service/new.go:37] - G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH)
36: TLSClientConfig: &tls.Config{

37: InsecureSkipVerify: true,
38: },

[/Users/margaretcamilletti/go/src/dreamland/cli/inject/service.go:40] - G602 (CWE-118): Potentially accessing slice out of bounds (Confidence: MEDIUM, Severity: MEDIUM)
39: if http != 0 {

40: others["http"] = http
41: }

[/Users/margaretcamilletti/go/src/dreamland/service/cors/helpers.go:26] - G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)
25: func OutError(w http.ResponseWriter, code int, msg string) {

26: w.Write([]byte(msg))
27: w.WriteHeader(code)

[/Users/margaretcamilletti/go/src/dreamland/cli/command/universe0.go:28] - G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)
27: }

28: ctx.Set("universe", universe)
29: return action(ctx)

[/Users/margaretcamilletti/go/src/dreamland/cli/command/universe.go:30] - G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)
29: }

30: ctx.Set("universe", universe)
31: return action(ctx)

[/Users/margaretcamilletti/go/src/dreamland/cli/command/names.go:28] - G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)
27: }

28: ctx.Set("names", names)
29: return action(ctx)

[/Users/margaretcamilletti/go/src/dreamland/cli/command/name.go:39] - G104 (CWE-703): Errors unhandled. (Confidence: HIGH, Severity: LOW)
38: }

39: ctx.Set("name", name)
40: return action(ctx)

Proposed Changes

I would like to suggest of adding comments on each part of a method or a function that what exactly it is doing or what each function parameter represents. This would help a new reader to under stand the code easily. And Also If I were you I would have use better variables names or meaning full variable names like what it is doing.

Needs to be Rehauled and Refactored

Proposing to rebuild this cli from the ground up.

This module can be simplified greatly, some more helpers should be added to tau/libdream before rebuilding though.

Proposed Changes

service/universe_test.go

code contains some code that could be more compartmentalized into a function for easier readability. The err variable is reassigned often and can be challenging to track
eg. lines 96-108

  func TestKillService(t *testing.T) {
	  err := universe.KillService("seer")
  
	  if err != nil {      // should not fail
		  t.Errorf("Failed kill call with error: %v", err)
	  } else { 		  // should fail
		  err = universe.KillService("seer")
		  if err == nil {
			  t.Error("Expected killing seer again to fail")
		  }
	  }
  }

lines 73-94 could also be compartmentalized.

Improvements and Fixes Suggeations

Using consistent naming conventions in the imported packages to improve the code readability.
Consider using the library 'logrus' for better error handling.

Code Analysis and Improvement Suggestions

Hi there! I had a chance to analyse a code of this repo and I have a few suggections for you:

1.Consider adding comments and documentation to your code to explain the purpose of the functions, expected input and output, and any relevant details about how the HTTP requests are being handled. This will make it easier for others (and your future self) to understand and use the package.
2. The code unmarshals the HTTP response body twice in some cases (once to check for errors and then to parse the response into the ret interface). You can optimize this by unmarshaling once and reusing the result if there are no errors.
3. Be cautious when sending and handling sensitive data, such as authorization tokens. Ensure that sensitive data is handled securely and doesn't leak in error messages or logs.

Let me know if there is something I'm missing or if you have any questions
Thanks for your time

Clean up bindConfigServices function

Description:
The current implementation of the bindConfigServices function could create outputs and/or errors that would be confusing to debug.

Issue:
Looking at the https://github.com/taubyte/dreamland/blob/main/cli/new/helpers.go file, it seems that if the conditional check on line 78 fails, then we will end up with a port of 0 and a sub of "" for any given service. Apparently it is possible to use port 0 to bind to a random available port, however this could cause problems with the use of TCP as 0 is a reserved port not intended to be used. In any case, a sub of "" is not in the list of ValidSubBinds found in the file https://github.com/taubyte/dreamland/blob/main/cli/common/vars.go. We see sub being validated on line 86, but not if the conditional check on line 78 fails. So this seems like a contradiction of logic: likely it should be validated both times.

Also, if it is possible for any service to bind to port 0, I would expect the conditional on line 112 to fail from time to time, in which case we would get an error for two services having duplicate port bindings. And the reason they are duplicate is just that they ended up taking on a default value after the conditional on line 78 failed. This gives the appearance that the code is written assuming the conditional on 78 will not fail.

Possible Solution:
It would likely be better to save the confusion by just creating a requirement that the result of strings.Split(bind, "@") on line 63 have a length == 2, instead of letting the inputs fall all the way through to the validation of duplicate ports to fail. This could save some debugging efforts insofar as we would not have to read all the times that port gets initialized, reassigned, or accessed on the binds map.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.