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

dashboard suite v1 #276

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 20 additions & 0 deletions tfgrid3/dashboard_suite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:22.04

Check failure

Code scanning / Trivy

Image user should not be 'root' High

Artifact: tfgrid3/dashboard_suite/Dockerfile
Type: dockerfile
Vulnerability DS002
Severity: HIGH
Message: Specify at least 1 USER command in Dockerfile with non-root user as argument
Link: DS002

RUN apt update && \
apt install -y git ufw openssh-server

RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \
chmod +x /sbin/zinit

RUN wget -O /sbin/caddy 'https://caddyserver.com/api/download?os=linux&arch=amd64&p=github.com%2Fcaddyserver%2Freplace-response&idempotency=43631173212363' && \
chmod +x /sbin/caddy

RUN mkdir -p /code && \
cd /code && \
git clone https://github.com/threefoldtech/grid_deployment

COPY ./scripts/ /scripts/
COPY ./zinit/ /etc/zinit/
RUN chmod +x /scripts/*.sh

ENTRYPOINT ["/sbin/zinit", "init"]
151 changes: 151 additions & 0 deletions tfgrid3/dashboard_suite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<h1> Dashboard Suite </h1>

<h2> Table of Contents </h2>

- [Introduction](#introduction)
- [Networks](#networks)
- [Create the Docker Image](#create-the-docker-image)
- [Convert the Docker Image to Zero-OS FList](#convert-the-docker-image-to-zero-os-flist)
- [TFGrid Deployment](#tfgrid-deployment)
- [Dashboard Steps](#dashboard-steps)
- [DNS Settings](#dns-settings)
- [Access the Dashboard Suite](#access-the-dashboard-suite)
- [Conclusion](#conclusion)

## Introduction

This Dashboard Suite Flist can be deployed on a micro VM on the ThreeFold Grid, either via the TF Dashboard, or Terraform. This FList uses `Ubuntu 22.04`. This Dashboard Suite Flist is based on the repository [grid_deployment](https://github.com/threefoldtech/grid_deployment). The TF Manual also contains documentation on the [Dashboard Suite](https://manual.grid.tf/documentation/developers/grid_deployment/grid_deployment_full_vm.html).

To simply deploy the available FList on the ThreeFold Dashboard, skip to [this section](#dashboard-steps).

<!--
Note that the official FList for the Dashboard Suite is the following:

```
https://hub.grid.tf/tf-official-apps/threefoldtech-dashboard_suite-latest.flist
```
-->

### Networks

This Flist can deploy the Dashboard Suite on either main, test or dev network.

To deploy the 3 network instances, mainnet, testnet and mainnet, you need to follow the same process for each network on a separate machine or at least on a different VM.

This means that you can either deploy each network instance on 3 different machines, or you can also deploy 3 different VMs on the same machine, e.g. a dedicated node. Then, each VM will run a different network instance. In this case, you will certainly need a machine with NVME storage disk and modern hardware.

## Create the Docker Image

To create the the Dashboard Suite image, clone this repository, then build and push the image to the Docker Hub.

* Clone the repository:
* ```
git clone https://github.com/threefoldtech/tf-images
```
* ```
cd tf-images/tfgrid3/dashboard_suite
```
* Build the image:
* ```
docker build -t <docker_username>/dashboard_suite .
```
* Push the image to the Docker Hub:
* ```
docker push <your_username>/dashboard_suite
```



## Convert the Docker Image to Zero-OS FList

The easiest way to convert the docker image to an FList is by using the [Docker Hub Converter Tool](https://hub.grid.tf/docker-convert). This can be done once you've built and pushed the docker image on the [Docker Hub](https://hub.docker.com/).

> Note: A docker image has already been converted to an FList (see below).

* Go to the [ThreeFold Hub](https://hub.grid.tf/).
* Sign in with the ThreeFold Connect app.
* Go to the [Docker Hub Converter](https://hub.grid.tf/docker-convert) section.
* Next to `Docker Image Name`, add the docker image repository and name, see the example below:
* Template:
* `<docker_username>/docker_image_name:tagname`
* Click `Convert the docker image`.
* Once the conversion is done, the FList is available as a public link on the ThreeFold Hub.
* To get the FList URL, go to the [TF Hub main page](https://hub.grid.tf/), scroll down to your 3Bot ID and click on it.
* Under `Name`, you will see all your available FLists.
* Right-click on the FList you want and select `Copy Clean Link`. This URL will be used when deploying on the ThreeFold Dashboard. We show below the template and an example of what the FList URL looks like.
* Template:
* ```
https://hub.grid.tf/<3BOT_name.3bot>/<docker_username>-<docker_image_name>-<tagname>.flist
```


## TFGrid Deployment

The easiest way to deploy a micro VM using the Dashboard Suite FList is to head to to the [ThreeFold Dashboard](https://dashboard.grid.tf) and deploy a [Micro Virtual Machine](https://dashboard.grid.tf/#/deploy/virtual-machines/micro-virtual-machine/) by providing the FList URL. Make sure to select `IPv4` and `IPv6`.

Make sure to provide the correct entrypoint (`/sbin/zinit init`). Note that the entrypoint should already be set by default when you open the micro VM page.

You could also use Terraform instead of the Dashboard to deploy the Dashboard Suite Micro VM. Read more on this [here](https://github.com/threefoldtech/terraform-provider-grid).

### Dashboard Steps

* Go to the [ThreeFold Dashboard](https://dashboard.grid.tf)
* Log into your TF wallet
* Go to the [Micro VM](https://dashboard.grid.tf/#/deploy/virtual-machines/micro-virtual-machine/) page
* In the section `Config`,
* Choose a name for your VM under `Name`.
* Under `VM Image`, select `Other`.
* Enter the Dashboard Suite FList under `Flist`:
* Template:
* ```
https://hub.grid.tf/<3BOT_name.3bot>/<docker_username>-<docker_image_name>-<tagname>.flist
```
* Example:
* ```
https://hub.grid.tf/tf-official-apps/threefoldtech-dashboard_suite-latest.flist
```
* Under `Entry Point`, the following should be set by default: `/sbin/zinit init`
* `Select instance capacity` should be at 8 vcores, 1000GB of SSD and 32GB of RAM.
* Make sure that `IPv4` and `IPv6` are enabled (required).
* In the tab `Environment Variables`. Click on the `plus` button then add 3 variables:
* `DOMAIN` for `Name` and your domain (e.g. `example.com`) for `Value`.
* `SEED` for `Name` and your TF seed phrase of the network you want to deploy the Dashboard Suite on (main, dev or test) (e.g. `main`) for `Value`.
* Click `Deploy`.

## DNS Settings

You need to set an A record for the IPv4 address and an AAAA record for the IPv6 address with a wildcard subdomain.

The following table explicitly shows how to set the A and AAAA records for your domain for all 3 networks. Note that both `testnet` and `devnet` have a subdomain. The last two lines are for mainnet since no subdomain is needed in this case.

| Type | Host | Value |
| ---- | ---- | -------------- |
| A | \*.dev | <devnet_ipv4_address> |
| AAAA | \*.dev | <devnet_ipv6_address> |
| A | \*.test | <testnet_ipv4_address> |
| AAAA | \*.test | <testnet_ipv6_address> |
| A | \* | <mainnet_ipv4_address> |
| AAAA | \* | <mainnet_ipv6_address> |

As stated above, each network instance must be on its own VM or machine to work properly. Make sure to adjust the DNS records accordingly.

## Access the Dashboard Suite

You can now access the Dashboard Suite at the associated domains:

```
dashboard.example.com
metrics.example.com
tfchain.example.com
graphql.example.com
relay.example.com
gridproxy.example.com
activation.example.com
stats.example.com
```

## Conclusion

We've seen the overall process of creating a new FList to deploy a Dashboard Suite workload on a Micro VM on the ThreeFold Dashboard.

If you have any questions or feedback, please let us know by either writing a post on the [ThreeFold Forum](https://forum.threefold.io/), or by chatting with us on the [TF Grid Tester Community](https://t.me/threefoldtesting) Telegram channel.
3 changes: 3 additions & 0 deletions tfgrid3/dashboard_suite/scripts/caddy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

caddy reverse-proxy -r --from ${DOMAIN} --to :80
22 changes: 22 additions & 0 deletions tfgrid3/dashboard_suite/scripts/dashboard_suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Go to the network directory
cd /code/grid_deployment/docker-compose/${NETWORK}net

# Copy the secret env file
cp .secrets.env-example .secrets.env

# Create a subkey and store into KEY variable, with .gitignore exception
grep -qxF ".subkey_${NETWORK}net" .gitignore || echo -e "\n.subkey_${NETWORK}net" >> .gitignore
../../apps/subkey generate-node-key > .subkey_${NETWORK}net
KEY=$(cat .subkey_${NETWORK}net)

# Set variables in secret env file
sed -i "s/DOMAIN\=grid.tf/example.com/g" .secrets.env
sed -i "s/DOMAIN\=/DOMAIN\=${DOMAIN}/g" .secrets.env
sed -i "s/TFCHAIN_NODE_KEY\=/TFCHAIN_NODE_KEY\=${KEY}/g" .secrets.env
sed -i "s/ACTIVATION_SERVICE_MNEMONIC\=\"\"/ACTIVATION_SERVICE_MNEMONIC\=\"${SEED}\"/g" .secrets.env
sed -i "s/GRID_PROXY_MNEMONIC\=\"\"/GRID_PROXY_MNEMONIC\=\"${SEED}\"/g" .secrets.env

# Load and deploy the TFGrid Stack
yes y | sh install_grid_bknd.sh
7 changes: 7 additions & 0 deletions tfgrid3/dashboard_suite/scripts/sshd_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

mkdir -p ~/.ssh
mkdir -p /var/run/sshd
chmod 600 ~/.ssh
chmod 600 /etc/ssh/*
echo $SSH_KEY >> ~/.ssh/authorized_keys
6 changes: 6 additions & 0 deletions tfgrid3/dashboard_suite/scripts/ufw_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 30333/tcp
ufw allow 22/tcp
1 change: 1 addition & 0 deletions tfgrid3/dashboard_suite/zinit/caddy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec: /scripts/caddy.sh
4 changes: 4 additions & 0 deletions tfgrid3/dashboard_suite/zinit/dashboard_suite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exec: /scripts/dashboard_suite.sh
oneshot: true
after:
- sshd
2 changes: 2 additions & 0 deletions tfgrid3/dashboard_suite/zinit/ssh-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exec: /scripts/sshd_init.sh
oneshot: true
3 changes: 3 additions & 0 deletions tfgrid3/dashboard_suite/zinit/sshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec: bash -c "/usr/sbin/sshd -D"
after:
- ssh-init
3 changes: 3 additions & 0 deletions tfgrid3/dashboard_suite/zinit/ufw-init.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exec: /scripts/ufw_init.sh
oneshot: true

4 changes: 4 additions & 0 deletions tfgrid3/dashboard_suite/zinit/ufw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exec: ufw --force enable
oneshot: true
after:
- ufw-init
Loading