diff --git a/Cargo.toml b/Cargo.toml index 5ad443271..4bc7a83e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nexus" version = "0.0.0" -edition = "2033" +edition = "2021" [dependencies] c2pa = "0.21.0" diff --git a/README.md b/README.md index 1a17cf3f0..728cae165 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,130 @@ - Here is the complete set of instructions: +# Nexus -1. Clone the Nexus repository +Welcome to the Nexus! This README will guide you through setting up your development environment and getting started with the project. + +## Prerequisites + +Before you begin, make sure you have the following installed on your system: + +- [Nix](https://nixos.org) +- [Git](https://git-scm.com/) +- [Rust](https://www.rust-lang.org/) +- wasm32-unknown-unknown target +- [OpenSSL 1.1](https://www.openssl.org/) +- [Cosmoonic](https://cosmonic.com) + +## Getting Started + +1. Clone the repository and navigate to the project directory: ```bash -git clone https://github.com/nexus +git clone https://github.com/plurigrid/nexus.git +cd nexus ``` -2. Enter the Nix environment +2. Start nix shell and run the following command to install all required dependencies: ```bash nix-shell +make all ``` -This will activate the flox environment defined in the nexus/flox.nix file. This environment has all the necessary dependencies installed to build and run your project. +This will automatically check for and install Rust, wasm32-unknown-unknown target, OpenSSL 1.1, and Cosmo CLI if they are not already installed on your system. -3. Run cosmo - -Now you can use cosmo launch your project: +3. Create a new actor using Cosmo CLI: ```bash -cosmo +cosmo new actor ``` -**If this is your first run of cosmo**, it will automatically start the tutorial. +Replace `` with your desired project name. -**If not your first run**, you can start the tutorial with: +4. Navigate to your newly created project directory: ```bash -cosmo tutorial hello +cd ``` -4. Explaining the components +5. Edit `src/lib.rs` file in your favorite text editor. -- flox is a tool for managing declarative Nix-based environments. The nexus/flox.nix file defines an environment with all the dependencies for your project. -- cosmo is a tool for building and deploying WebAssembly actors. You use it to build and launch your actor from within the flox environment. -- Nix is a purely functional package manager that is used by flox to define environments. +The default file content looks like this: -5. Installation (if not already completed) +```rust +use wasmbus_rpc::actor::prelude::*; +use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver}; -Follow the instructions to install flox and configure your system to use it. This will install the necessary tools to get started with the Nexus project. +#[derive(Debug, Default, Actor, HealthResponder)] +#[services(Actor, HttpServer)] +struct Actor {} -- Install Nix (if not already installed) -- Install flox +/// Implementation of the HttpServer capability contract +#[async_trait] +impl HttpServer for Actor { + async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult { + Ok(HttpResponse::ok("message")) + } +} +``` -You now have all the necessary components installed and configured to build and run the Nexus project! Let me know if you have any other questions. +You can modify the file to accommodate more text like this: + +```rust +use wasmbus_rpc::actor::prelude::*; +use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver}; + +#[derive(Debug, Default, Actor, HealthResponder)] +#[services(Actor, HttpServer)] +struct Actor {} + +/// Implementation of the HTTP server capability +#[async_trait] +impl HttpServer for Actor { + async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult { + let message: &str = r#"message"#; + + Ok(HttpResponse::ok(message)) + } +} + +``` +## Launching the Project + +1. Login to Cosmonic: + +```bash +cosmo login +``` + +2. Build and sign your actor: + +```bash +cosmo build +``` + +3. Start your wasmCloud host: + +```bash +cosmo up +``` + +4. Launch the actor using Cosmo CLI: + +```bash +cosmo launch +``` + +5. Navigate to [Cosmonic App](https://app.cosmonic.com) and sign in with your account. + +6. In the Logic view, you should see the new actor you just launched. + +7. To make your actor accessible from the web, launch a new provider for an HTTP server with the following OCI URL: `cosmonic.azurecr.io/httpserver_wormhole:0.5.3`. Give the link a name, and note that the HTTP server must be launched on a Cosmonic Manager resource. + +8. Once the HTTP server is launched, link it to your actor. + +9. Launch a wormhole and connect it to your actor link (the HTTP server and the actor). + +10. Your actor should now be accessible at the domain of the wormhole followed by `.cosmonic.app`. For example: `https://white-morning-5041.cosmonic.app`. + +Now you can access your project from any web browser using the provided URL! + +You're all set! You can start building your project and explore the Nexus repository. Happy coding! diff --git a/justfile b/justfile new file mode 100644 index 000000000..e95b1c308 --- /dev/null +++ b/justfile @@ -0,0 +1,41 @@ +scripts_dir := "scripts" + +# Check if Nix is installed, if not install it based on the platform +install-nix: + . {{scripts_dir}}/install_nix.sh; \ + +# Check if Rust is installed, if not install it +install-rust: + @if ! command -v rustc &> /dev/null; then \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh; \ + . {{scripts_dir}}/update_source.sh; \ + fi + +# Check if wasm32-unknown-unknown target is installed, if not install it +install-wasm-target: + @if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then \ + rustup target add wasm32-unknown-unknown; \ + . {{scripts_dir}}/update_source.sh; \ + fi + +# Check if OpenSSL 1.1 is installed +install-openssl: + @if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then \ + . {{scripts_dir}}/install_openssl.sh; \ + . {{scripts_dir}}/update_source.sh; \ + fi + +# Check if cosmo is installed, if not install it +install-cosmo: + @if ! command -v cosmo &> /dev/null; then \ + bash -c "$(curl -fsSL https://cosmonic.sh/install.sh)"; \ + . {{scripts_dir}}/update_path.sh; \ + . {{scripts_dir}}/update_source.sh; \ + fi + +# Print a message to restart the shell +restart-shell-message: + @echo + @echo "\033[1;33mPlease restart your shell to refresh the source before launching Cosmonic.\033[0m" + +all: install-nix install-rust install-wasm-target install-openssl install-cosmo restart-shell-message diff --git a/scripts/install_nix.sh b/scripts/install_nix.sh new file mode 100644 index 000000000..a668a922a --- /dev/null +++ b/scripts/install_nix.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Check if Nix is installed +if ! command -v nix --help >/dev/null 2>&1; then + # Delete problematic backup files for bash and zsh if they exist + if [ -f "/etc/bash.bashrc.backup-before-nix" ]; then + sudo rm -f /etc/bash.bashrc.backup-before-nix + fi + + if [ -f "/etc/bashrc.backup-before-nix" ]; then + sudo rm -f /etc/bashrc.backup-before-nix + fi + + if [ -f "/etc/zshrc.backup-before-nix" ]; then + sudo rm -f /etc/zshrc.backup-before-nix + fi + + # Determine the platform (Linux or macOS) + case `uname` in + Linux*) + echo "Error: Nix package manager is not installed. Installing Nix for Linux..." + curl -L https://nixos.org/nix/install | sh --daemon - + ;; + Darwin*) + echo "Error: Nix package manager is not installed. Installing Nix for macOS..." + curl -L https://nixos.org/nix/install | sh --darwin-use-unencrypted-nix-store-volume - + ;; + *) + echo "Unsupported platform for Nix installation" + exit 1; + ;; + esac + +else + echo "Nix package manager is already installed." +fi diff --git a/scripts/install_openssl.sh b/scripts/install_openssl.sh new file mode 100644 index 000000000..9d22fc85d --- /dev/null +++ b/scripts/install_openssl.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Check if OpenSSL 1.1 is installed +if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then + + # Check the architecture and install OpenSSL 1.1 if needed + if [[ $(uname -m) == "arm64" ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + # MacOS M1 installation + if ! command -v brew &> /dev/null; then + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> "$HOME/.zprofile" + + eval "$(/opt/homebrew/bin/brew shellenv)" + + echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc + + fi + + export PATH="/opt/homebrew/bin:$PATH" + + brew install openssl@1.1 + + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Check for Debian-based system + if grep -qi 'debian' /etc/os-release; then + # Ubuntu ARM installation + + apt update && apt install curl -y + + curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | bash + + apt install wash + + curl -fLO http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u4_arm64.deb + + dpkg -i libssl1.1_1.1.1n-0+deb11u4_arm64.deb + + else + echo "This script is designed for Debian-based systems only." + exit 1 + fi + + else + echo "Unsupported system type." + exit 1 + fi + + else + echo "This script is designed for arm64 systems only." + exit 1 + fi + +fi diff --git a/scripts/update_path.sh b/scripts/update_path.sh new file mode 100644 index 000000000..796a8061f --- /dev/null +++ b/scripts/update_path.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Get the current shell name +current_shell="$(basename "$SHELL")" + +# Update the corresponding configuration file based on the current shell +if [[ "$current_shell" == "bash" ]]; then + cat >> "${HOME}/.bashrc" <> "${HOME}/.zshrc" < /dev/null; then - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - fi - - # Check if wasm32-unknown-unknown target is installed, if not install it - if ! rustup target list --installed | grep -q "wasm32-unknown-unknown"; then - rustup target add wasm32-unknown-unknown - fi - - - # Check if OpenSSL 1.1 is installed - if ! (command -v openssl &> /dev/null && openssl version | grep -q "OpenSSL 1.1"); then - - # Check the architecture and install OpenSSL 1.1 if needed - if [[ $(uname -m) == "arm64" ]]; then - if [[ "$OSTYPE" == "darwin"* ]]; then - # MacOS M1 installation - if ! command -v brew &> /dev/null; then - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - fi - - export PATH="/opt/homebrew/bin:$PATH" - - brew install openssl@1.1 - - elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - # Check for Debian-based system - if grep -qi 'debian' /etc/os-release; then - # Ubuntu ARM installation - - apt update && apt install curl -y - - curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | bash - - apt install wash - - curl -fLO http://ftp.us.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u4_arm64.deb - - dpkg -i libssl1.1_1.1.1n-0+deb11u4_arm64.deb - - else - echo "This script is designed for Debian-based systems only." - exit 1 - fi - - else - echo "Unsupported system type." - exit 1 - fi - - else - echo "This script is designed for arm64 systems only." - exit 1 - fi - - fi - - # Check if cosmo is installed, if not install it - if ! command -v cosmo &> /dev/null; then - bash -c "$(curl -fsSL https://cosmonic.sh/install.sh)" - - # Get the current shell name - current_shell="$(basename ${builtins.getEnv "SHELL"})" - - # Update the corresponding configuration file based on the current shell - if [[ "$current_shell" == "bash" ]]; then - cat >> "${builtins.getEnv "HOME"}/.bashrc" <> "${builtins.getEnv "HOME"}/.zshrc" <