info_tfgrid/docs/hero_mdbook_fullvm.md

169 lines
6.5 KiB
Markdown
Raw Normal View History

<h1>Hero and mdbook on a Full VM</h1>
<h2>Table of Contents</h2>
- [Introduction](#introduction)
- [Setting the Full VM](#setting-the-full-vm)
2024-02-15 19:55:04 +00:00
- [Remote Explorer Access](#remote-explorer-access)
2024-03-23 17:14:21 +00:00
- [Set the SSH Key Pair](#set-the-ssh-key-pair)
2024-04-02 19:31:42 +00:00
- [Install Hero, Crystallib and V](#install-hero-crystallib-and-v)
2024-03-23 17:14:21 +00:00
- [Use Hero to Generate mdbooks](#use-hero-to-generate-mdbooks)
2024-03-23 18:40:01 +00:00
- [Troubleshooting](#troubleshooting)
2024-04-02 19:31:42 +00:00
- [Fix the error: "cli execution error: Cannot pull repo..."](#fix-the-error-cli-execution-error-cannot-pull-repo)
2024-03-23 18:40:01 +00:00
- [Fix: Git hangs at "Cloning into..."](#fix-git-hangs-at-cloning-into)
- [Distinctions between mdbook and hero mdbook](#distinctions-between-mdbook-and-hero-mdbook)
***
## Introduction
2024-04-02 19:31:42 +00:00
In this tutorial, we show all the steps to deploy an mdbook with the [Hero](https://github.com/freeflowuniverse/crystallib/tree/development/cli/hero) tool.
2024-02-15 19:55:04 +00:00
For this guide, we show an example using the mdbook from the repository [info_tfgrid](https://git.ourworld.tf/tfgrid/info_tfgrid). This setup can be done locally or on a VM. Note that it should be run as root.
2024-02-15 19:55:04 +00:00
We show the steps for a full VM deployed on the TFGrid with WireGuard. We use `10.20.4.2` as a WireGuard IP address. Adjust according to your own setup.
We will be using SSH to connect to the VM and to create an SSH tunnel between the local machine and the VM. This will allow the mdbook output to be displayed on a local browser.
To manage the mdbook files, we will be using the remote explorer feature of either VSCodium or VSCode.
2024-04-02 19:31:42 +00:00
We also include some troubleshooting tips.
2024-03-23 18:40:01 +00:00
2024-02-15 19:55:04 +00:00
## Setting the Full VM
We start by deploying a full VM with WireGuard on the TFGrid. We also set an SSH tunnel.
- Deploy a full VM with WireGuard on the TFGrid
2024-03-23 17:14:21 +00:00
- Set an SSH tunnel, on port 5173 for both local and VM
```
2024-03-23 17:14:21 +00:00
ssh -4 -L 5173:127.0.0.1:5173 root@10.20.4.2
```
2024-02-15 19:55:04 +00:00
Instead of working on the SSH tunnel terminal window, we will be using the remote explorer feature of a source-code editor.
2024-02-15 19:55:04 +00:00
### Remote Explorer Access
You can use the remote explorer feature of both [VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode.remote-repositories) and [VSCodium](https://open-vsx.org/extension/jeanp413/open-remote-ssh) to manage the mdbook.
- Open the window `Remote Explorer`, click on `Add New` and write the following in the SSH config file:
```
Host 10.20.4.2
HostName 10.20.4.2
User root
```
- Click on `Connect to Host`
- Open the main `/root` directory
- Right-click on the main window of the directory and select `Open in Integrated Terminal`
2024-03-23 17:14:21 +00:00
- Update and prepare the VM
```
apt update && apt install curl -y && apt install openssh-client -y
```
## Set the SSH Key Pair
- Generate an SSH key pair
2024-04-02 19:31:42 +00:00
- To make it work with info_tfgrid, save it here: `/root/.ssh/books`
2024-03-23 17:14:21 +00:00
```
2024-04-02 19:31:42 +00:00
ssh-keygen
2024-03-23 17:14:21 +00:00
```
- Note the public key
```
2024-04-02 19:31:42 +00:00
cat /root/.ssh/books.pub
2024-03-23 17:14:21 +00:00
```
2024-03-26 14:26:32 +00:00
- Add the SSH public key on [git.ourworld.tf](https://git.ourworld.tf/user/settings/keys) and [github](https://github.com/settings/keys)
2024-04-02 19:31:42 +00:00
- Optional: on git.ourworld.tf, verify the key. Make sure to put the proper token.
2024-03-23 17:14:21 +00:00
```
2024-04-02 19:31:42 +00:00
echo -n 'token' | ssh-keygen -Y sign -n gitea -f /root/.ssh/books
2024-03-23 17:14:21 +00:00
```
- Start the ssh agent
```
eval $(ssh-agent)
```
- Add private key to the agent
```
ssh-add /root/.ssh/books
```
2024-04-02 19:31:42 +00:00
## Install Hero, Crystallib and V
We install hero, Crystallib and V with a script.
2024-03-23 17:14:21 +00:00
```
2024-04-26 22:08:12 +00:00
curl https://raw.githubusercontent.com/freeflowuniverse/crystallib/development/scripts/installer_hero.sh > /tmp/build_hero.sh
2024-03-23 17:14:21 +00:00
bash /tmp/build_hero.sh
```
## Use Hero to Generate mdbooks
2024-04-02 19:31:42 +00:00
We generate mdbooks with Hero.
Download the git repository from a URL:
2024-03-27 19:08:46 +00:00
- Download the repository
2024-03-23 17:14:21 +00:00
```
hero mdbook -u https://git.ourworld.tf/tfgrid/info_tfgrid/src/branch/main/heroscript/bookname -gp
```
2024-04-02 19:31:42 +00:00
- The line above will clone the repository `info_tfgrid` at the path `/root/code/git.ourworld.tf/tfgrid`. The same result can be obtained by running the following lines:
```
mkdir -p /root/code/git.ourworld.tf/tfgrid
cd /root/code/git.ourworld.tf/tfgrid
git clone https://git.ourworld.tf/tfgrid/info_tfgrid
```
For the next steps, you can either run the commands locally (with -p and the proper path) or remotely (with -u and the proper URL). Running the command locally is useful when you are doing changes to the mdbook and you want to test them before pushing the new files to the remote repository.
2024-03-27 19:08:46 +00:00
- Build the book
2024-04-15 19:07:52 +00:00
- Note: add the parameter `-o` at the end of the line to open the book with your local browser
2024-04-02 19:31:42 +00:00
- Option 1: Build the book with a URL
```
hero mdbook -u https://git.ourworld.tf/tfgrid/info_tfgrid/src/branch/main/heroscript/bookname
```
2024-03-23 17:14:21 +00:00
2024-04-02 19:31:42 +00:00
- Option 2: Build the book with a local path
```
hero mdbook -p /path/to/tfgrid/info_tfgrid/src/branch/main/heroscript/bookname
```
> Note: In all cases, make sure to replace **bookname** by the name of your book, e.g. test.
2024-04-15 19:07:52 +00:00
If you are running hero on a VM with an SSH tunnel, to preview the mdbook on a local browser (via the file **index.html**), run the following command and open a browser with the URL **localhost:5173**. Make sure to replace `<book_name>` with the name of the book.
2024-03-23 17:14:21 +00:00
```
2024-03-29 17:58:09 +00:00
pushd /root/hero/www/info/<book_name>/; python3 -m http.server 5173; popd;
2024-03-23 17:14:21 +00:00
```
2024-02-15 19:55:04 +00:00
2024-03-23 18:40:01 +00:00
## Troubleshooting
2024-04-02 19:31:42 +00:00
### Fix the error: "cli execution error: Cannot pull repo..."
2024-03-23 18:40:01 +00:00
2024-04-02 19:31:42 +00:00
If you get the following error: "cli execution error: Cannot pull repo: /root/code/git.ourworld.tf/tfgrid/info_tfgrid because there are changes in the dir.", you can try the following as a fix:
2024-03-23 18:40:01 +00:00
```
rm -r /root/code/git.ourworld.tf/tfgrid/info_tfgrid
```
### Fix: Git hangs at "Cloning into..."
Run this command to fix this issue:
```
git config --global credential.provider generic
```
If it happens another time, you can try to download it manually:
```
mkdir -p /root/code/git.ourworld.tf/tfgrid && cd $_
git clone https://git.ourworld.tf/tfgrid/info_tfgrid
```
## Distinctions between mdbook and hero mdbook
2024-05-27 13:04:04 +00:00
There are some distinctions between mdbook and hero mdbook. This is subject to change since hero is continually being improved.
2024-05-27 13:04:04 +00:00
- hero mdbook cannot use parentheses in tables of contents (e.g. in SUMMARY.md)
- hero mdbook uses the following include template:
```
2024-12-03 22:46:56 +00:00
\!!wiki.include page:'collection_name:file_name.md'
2024-05-27 13:04:04 +00:00
```
- hero mdbook cannot parse codes with tabs or spaces
- list contents are parsed as paragraphs (e.g. defs, comments, text, links), they can't contain code blocks