Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README & Docs #241

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,40 @@ It is composed of a frontend written in Svelte, and a backend written in Rust.

For more documentation, please check the `docs/` folder at the root of the repo.

## Building
Run `build.sh` to build the front and and backend. The output will be assembled into `./target`, run `hyde` to start the binary.

## Running
The executable requires a few environment variables be set, see `default.env` for a full list. You may set them on the system or copy `default.env` to `.env`
and place it in a folder named `hyde-data/` and customize as needed. This directory is used to store configs, the sqlite database, and the Github App private key.
The Hyde executable requires the `hyde-data` folder to be present in the same directory. See: [Populating hyde-data.](#populating-hyde-data)

You can also specify your own `.toml` config with the `hyde` binary using the `-c`/`--config` switch:
```bash
./hyde -c ./path/to/.toml
```
You can also use relative pathing:
```bash
./hyde -c ../../path/to/.toml
```
This will ignore any `.toml` config inside `hyde-data`.

## Developing
We accept contributions, and we'll happily mentor individuals through their contributions. Feel free to ask for help, either through Github, or in the r/TechSupport discord server.

Development is supported on Windows (With [some caveats](https://github.com/r-Techsupport/hyde/issues/6)), MacOS, and Linux.

### Installing tools
To build the backend, you need to have the Rust toolchain installed (see <https://www.rust-lang.org/tools/install>). We currently aim to support the latest stable version of Rust. Once that's installed, `cargo` will automatically download and install the appropriate dependencies for the project when it's first built. The source code for the backend is located in `./backend`, so navigate there
To build the backend, you need to have the Rust toolchain installed (see <https://www.rust-lang.org/tools/install>).
We currently aim to support the latest stable version of Rust. Once that's installed, `cargo` will automatically download and install the appropriate dependencies for the project when it's first built.
The source code for the backend is located in `./backend`, so navigate there

To build the frontend, you'll need to have the appropriate Javascript tooling installed (See <https://nodejs.org/en/download/package-manager>). This means Node *and* npm. We aim to use the latest stable version of Node.js (23 at the time of writing).
To build the frontend, you'll need to have the appropriate Javascript tooling installed (See <https://nodejs.org/en/download/package-manager>).
This means Node *and* npm. We aim to use the latest stable version of Node.js (23 at the time of writing).

### Populating `hyde-data`
To keep things organized, the config file and other essential data (sqlite database, Github private key) are stored in a folder in the same directory that the code is run from. This directory is relative to the running process's current directory, so for development, the `hyde-data` folder will be located at `./backend/hyde-data`,
To keep things organized, the config file and other essential data (sqlite database, Github private key) are stored in a folder in the same directory that the code is run from. This directory is relative to the running process's current directory.

Hyde expects:
If you're running hyde via local development, place `hyde-data` folder inside `backend` folder

- A config file to be located at `hyde-data/.env`, relative to the running process's current directory. This means you'll need to copy `./default.env` from the root of the project into `./backend/hyde-data/.env`, and fill out any necessary values. Guides for obtaining these values can be found under `./docs`. Configuration values can also be passed with command line arguments, run the executable with the `--help` flag to see more.
Hyde expects:

- `hyde-data/default.toml` file with all the configuration options. You can find `default.toml` as an example configuration to use in the root of the project.
- `hyde-data/key.pem`, the private key linked to your Github Application deployment.
- `hyde-data/data.db` - If not created, this file will be automatically created and stores permissions and user account info.

Expand All @@ -38,28 +48,38 @@ You can run the backend with `cargo run` from the `backend` folder. This will co

Once the backend is running, in a separate terminal window, run `npm run dev` from the `frontend` folder to start the frontend, listening on `localhost:5173`, viewable from your web browser.

It's recommended that you configure your `rust-analyzer` installation to run `clippy` instead of `check`. See <https://users.rust-lang.org/t/how-to-use-clippy-in-vs-code-with-rust-analyzer/41881/2> for a guide, set `Check On Save: Command` to `clippy`. At the very least, run `cargo clippy` before committing to make sure your code passes lint.
It's recommended that you configure your `rust-analyzer` installation to run `clippy` instead of `check`.
See <https://users.rust-lang.org/t/how-to-use-clippy-in-vs-code-with-rust-analyzer/41881/2> for a guide, set `Check On Save: Command` to `clippy`.
At the very least, run `cargo clippy` before committing to make sure your code passes lint.

## Building

### Building the project in release mode (production)
While build scripts exist for Windows (`./build.ps1`) and *nix (`./build.sh`), you may find it helpful to understand what a production build of Hyde looks like.
### Production
Build scripts exist for Windows (`./build.ps1`) and *nix (`./build.sh`). This will detail what a production build looks like for `hyde`.

Build scripts should assemble the final product into `./target`. It consists of:
The written build scripts should assemble the final product into `./target`, consisting of:

- `hyde`(`.exe`): The actual executable, built by running `cargo run --release`. The generated executable is copied from `./backend/target/release/[HYDE-EXECUTABLE-NAME]` to `./target/hyde`(`.exe`). This executable will serve the frontend files stored in `web`, so there's only a single process running. It listens on port `8080` by default, but this is configurable via the `-p`/`--port` command line option.
- `web`: Svelte is configured to compile the frontend into a collection of static files, which can be generated by running `npm run build` from `./frontend`. Those are copied from `./target/frontend/build/` into `./target/web/`. In that directory, you'll find the relevant HTML, CSS, JavaScript, and any assets used on the site. Svelte is also configured to include Brotli and Gzipped versions of those files to reduce bundle size.
- `hyde`(`.exe`): The actual executable, built by running `cargo run --release`. The generated executable is copied from `./backend/target/release/[HYDE-EXECUTABLE-NAME]` to `./target/hyde`(`.exe`).
This executable will serve the frontend files stored in `web`, so there's only a single process running. It listens on port `8080` by default, but this is configurable via the `-p`/`--port` command line option.
- `web` directory: Svelte is configured to compile the frontend into a collection of static files, which can be generated by running `npm run build` from `./frontend`.
Those are copied from `./target/frontend/build/` into `./target/web/`. In that directory, you'll find the relevant HTML, CSS, JavaScript, and any assets used on the site.
Svelte is also configured to include Brotli and Gzipped versions of those files to reduce bundle size.

There are two ways to copy `hyde-data` folder from `./backend/` to `./target`. First is to manually move the folder, second is to use the build scripts to do it for you:

- Linux: `build.sh -c <path_to_hyde_data>`

- Windows `build.ps1 -C <path_to_hyde_data>`

Certain behaviors do differ between development and production builds, so be aware of them. Notably, in release mode, the application requires `https` to function.
Behaviors can differ between development and production builds. Notably, in release mode, the application requires `https` to function.

Hyde's logging can be configured by setting the `RUST_LOG` environment variable or using the `-v`/`--verbosity` command line flag. Possible values are: `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `OFF`.

Upon startup, Hyde will attempt to open a wiki repository found at `./repo` (relevant to the path of the running executable), and pull any upstream changes, or clone the repo into `./repo` if no repo was detected there. The final product can be found by navigating to <http://localhost:8080> in your web browser.
On first start, Hyde will check if you have a git repository for your wiki at the relative folder `./repo`.
If it is not there, it will clone the repo based on the `repo_url` supplied in the `.toml` config. If it exists
then it will pull upstream changes.

The final product can be found by navigating to <http://localhost:8080> in your web browser.

### Building a containerized version of the project
This does not require that you have language tooling installed (Rust, JavaScript), only requiring an OCI implementation of your choice.
Expand Down
1 change: 0 additions & 1 deletion default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ repo_path = "repo/"
# The URL of the jekyll repository to interface with
repo_url = "https://github.com/r-Techsupport/rTS_Wiki.git"


# Discord is related to discord specific information to pass to Hyde.
[discord]
# The discord username of the admin account
Expand Down
12 changes: 0 additions & 12 deletions docs/env.md

This file was deleted.

30 changes: 30 additions & 0 deletions docs/toml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
| **[files]** | **[discord]** | **[oauth.discord]** | **[oauth.github]** | **[database]** |
|-----------------------|---------------------------|----------------------|----------------------|----------------|
| asset_path = `string` | admin_username = `string` | client_id = `string` | client_id = `string` | url = `string` |
| docs_path = `string` | | secret = `string` | | |
| repo_path = `string` | | url = `string` | | |
| repo_url = `string` | | token_url = `string` | | |

## Descriptions
### Files
- `asset_path`: Location of the markdown file relative to the root of the project
- `docs_path`: Location of the assets files relative to the root of the project
- `repo_path`: Location of where the jekyll repository will be pulled and used
- `repo_url`: URL of the jekyll repository to use

### Discord
- `admin_username`: Discord username of the administrator account

### OAuth.discord
See: [Hyde Discord Documentation](discord.md)
- `client_id`: Discord OAuth2 Client ID.
- `secret`: Discord Application Secret.
- `url`: Generated Discord Application Scope URL
- `token_url`: OAuth2 Token URL. By default can be: `https://discord.com/api/oauth2/token`

### OAuth.github
See: [Hyde GitHub Documentation](github.md)
- `client_id`: GitHub Application Client ID

### Database
- `url`: Database url for Hyde to use