Skip to content

Commit

Permalink
Merge pull request #6 from Thymis-io/chore/adjust-for-landing-page-bu…
Browse files Browse the repository at this point in the history
…ild-and-add-docs

Chore/adjust for landing page build and add docs
  • Loading branch information
elikoga authored Apr 5, 2024
2 parents 117c6bc + 5cf8a93 commit d79f728
Show file tree
Hide file tree
Showing 26 changed files with 287 additions and 75 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Nix
# uses: DeterminateSystems/nix-installer-action@v6
# with:
# extra-conf: |
# system-features = kvm
uses: cachix/install-nix-action@v22
with:
extra_nix_config: |
Expand All @@ -24,14 +20,13 @@ jobs:
run: nix run nixpkgs#nix-eval-jobs -- --gc-roots-dir gcroots --flake .#all-download-images | tee jobs.json
- name: convert jobs json
run: nix run nixpkgs#jq -- -r 'select(.system == "x86_64-linux") | .attr + " " + .drvPath + " " + .name' < jobs.json > jobs
- name: build jobs
run: |
mkdir -p results
while read -r attr drvPath name; do
nix build "$drvPath^*" --out-link "results/$attr-$name" --print-build-logs
done < jobs
- name: upload
uses: actions/upload-artifact@v3
with:
name: results
path: results
# - name: build jobs
# run: |
# mkdir -p results
# while read -r attr drvPath name; do
# nix build "$drvPath^*" --out-link "results/$attr-$name" --print-build-logs
# done < jobs
- name: build generic-x86_64.install-iso
run: nix build .#all-download-images.generic-x86_64.install-iso --print-build-logs
- name: check if nix-eval-jobs produced errors
run: jq -e 'select(.error)' < jobs.json && exit 1 || true
40 changes: 40 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy
on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write # To push a branch
pages: write # To push to a GitHub Pages site
id-token: write # To update the deployment status
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install latest mdbook
run: |
tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')
url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz"
mkdir mdbook
curl -sSL $url | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
- name: Build Book
run: |
# This assumes your book is in the root of your repository.
# Just add a `cd` here if you need to change to another directory.
cd docs
mdbook build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload entire repository
path: 'docs/book'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions controller/thymis_controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from dotenv import load_dotenv

load_dotenv(verbose=True)

from thymis_controller.crud.project import Project
from thymis_controller.models import State, Device, Module, ModuleSettings, SettingValue
43 changes: 43 additions & 0 deletions controller/thymis_controller/crud/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
from pydoc import locate
from pathlib import Path
from thymis_controller.models.state import State
import os


class Project:
def __init__(self, path):
self.path = path

def is_initialized(self):
return Path(self.path).is_dir() and (Path(self.path) / "state.json").is_file()

def initialize(self):
Path(self.path).mkdir(exist_ok=True)
# TODO git reop init - git config user and email
state = State(
version="0.0.1",
tags=[],
devices=[],
)
self.update_state(state.model_dump())

def load_state_from_file(self):
with open(Path(self.path) / "state.json", "r", encoding="utf-8") as f:
state_dict = json.load(f)
return State.load_from_dict(state_dict)

def update_state(self, state):
old_state = self.load_state_from_file()
try:
state = State.load_from_dict(state)
state.save(self.path)
state.write_nix(self.path)
except Exception as e:
old_state.save(self.path)
old_state.write_nix(self.path)
raise e


REPO_PATH = os.getenv("REPO_PATH")
global_project = Project(REPO_PATH)
45 changes: 0 additions & 45 deletions controller/thymis_controller/crud/state.py

This file was deleted.

15 changes: 10 additions & 5 deletions controller/thymis_controller/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from thymis_controller.crud import state
from fastapi import Depends
from thymis_controller.crud.project import Project, global_project


def get_or_init_state():
if not state.is_initialized():
state.initialize()
def get_or_init_project():
if not global_project.is_initialized():
global_project.initialize()

return state.load_from_file()
return global_project


def get_or_init_state(project: Project = Depends(get_or_init_project)):
return project.load_state_from_file()
3 changes: 2 additions & 1 deletion controller/thymis_controller/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .setting import Setting, ModuleSettings
from .setting import Setting, ModuleSettings, SettingValue
from .module import Module
from .modules import ALL_MODULES
from .tag import Tag
from .device import Device
from .state import State
9 changes: 9 additions & 0 deletions controller/thymis_controller/models/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ def write_nix_settings(
assert isinstance(my_attr, models.Setting)
my_attr.write_nix(f, value, priority)

def create_settings_object(self, settings: dict):
return models.ModuleSettings(
type=self.type,
settings={
key: models.SettingValue(value=value) # TODO: why
for key, value in settings.items()
},
)

@staticmethod
def read_into_base64(path: str):
try:
Expand Down
10 changes: 6 additions & 4 deletions controller/thymis_controller/routes/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from thymis_controller.models.state import State
from fastapi import APIRouter, Depends, Request, BackgroundTasks, WebSocket
from fastapi.responses import FileResponse, RedirectResponse
from ..dependencies import get_or_init_state
from thymis_controller.dependencies import get_or_init_state, get_or_init_project
from thymis_controller import models
from thymis_controller.crud import state
from thymis_controller.crud import project
import subprocess
from urllib.parse import urljoin

Expand All @@ -25,8 +25,10 @@ def get_available_modules():


@router.patch("/state")
async def update_state(new_state: Request):
return state.update(await new_state.json())
async def update_state(
new_state: Request, project: project.Project = Depends(get_or_init_project)
):
return project.update_state(await new_state.json())


last_build_status = [None]
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book
6 changes: 6 additions & 0 deletions docs/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[book]
authors = ["Eli Kogan-Wang"]
language = "en"
multilingual = false
src = "src"
title = "Thymis Documentation"
15 changes: 15 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Summary

[Introduction](introduction.md)

- [Getting Started](getting_started.md)
- [Creating a Thymis-Controller Device Image](getting_started/creating_a_thymis_controller_device_image.md)
- [Running the Thymis-Controller Device Image](getting_started/running_the_thymis_controller_device_image.md)
- [Configuration](configuration.md)
- [Adding a Device](configuration/adding_a_device.md)
- [Managing Devices using Tags](configuration/managing_devices_using_tags.md)
- [Configure Pre-Defined Modules](configuration/configure_pre_defined_modules.md)
- [Adding custom Modules](configuration/adding_custom_modules.md)
- [Deployment](deployment.md)
- [Deployment History](deployment/history.md)
- [Monitoring](monitoring.md)
4 changes: 4 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Configuration

Once you have your Thymis-Controller device up and running, you can start configuring the Thymis Project to suit your needs.
Quickly [add devices](configuration/adding_a_device.md), [manage devices using tags](configuration/managing_devices_using_tags.md), [configure pre-defined modules](configuration/configure_pre_defined_modules.md), and [add custom modules](configuration/adding_custom_modules.md) to your Thymis Project.
8 changes: 8 additions & 0 deletions docs/src/configuration/adding_a_device.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Adding a Device

To add a device to Thymis, follow these steps:

1. Navigate to the Thymis-Controller web interface.
2. Click on the "Devices" tab.
3. Click on the "Add Device" button.
4. Follow the on-screen instructions to add the device to your Thymis Project.
14 changes: 14 additions & 0 deletions docs/src/configuration/adding_custom_modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Adding custom Modules

TODO

You can add custom modules to your Thymis Project to extend the functionality of your IoT devices.

To add a custom module to your Thymis Project, follow these steps:

1. Navigate to the Thymis-Controller web interface.
2. Click on the "Modules" tab.
3. Click on the "Add Module" button.
4. Enter the module name and description.
5. Click on the "Add Module" button.
6. Follow the on-screen instructions to add the module to your Thymis Project.
11 changes: 11 additions & 0 deletions docs/src/configuration/configure_pre_defined_modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Configure Pre-Defined Modules

Thymis comes with a set of pre-defined modules that you can use to extend the functionality of your IoT devices. You can configure these modules to suit your needs.

To configure a pre-defined module, follow these steps:

1. Navigate to the Thymis-Controller web interface.
2. Click on the "Devices" tab.
3. Click the "Edit" button next to the device you want to configure.
4. Add the pre-defined module to the device by clicking on the "Add Module" button.
5. Configure the module by entering the required information.
16 changes: 16 additions & 0 deletions docs/src/configuration/managing_devices_using_tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Managing Devices using Tags

Tags are a powerful way to manage your devices in Thymis.
You can use tags to group devices together, filter devices based on specific criteria, and perform actions on multiple devices at once.

## Adding Tags to a Device

To add tags to a device, follow these steps:

1. Navigate to the Thymis-Controller web interface.
2. Click on the "Devices" tab.
3. Add tags to a device using the UI-Elements in the `Tags` column.

## Managing Tags

You can assign and configure modules for your Tags in the same way you would for individual devices.
3 changes: 3 additions & 0 deletions docs/src/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Deployment

Click the Deploy button to deploy your Thymis Project to your IoT devices.
6 changes: 6 additions & 0 deletions docs/src/deployment/history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Deployment Versioning

Thymis keeps track of past deployments and allows you to revert to a previous deployment if needed.
This feature is useful when you need to roll back to a previous version of your Thymis Project.

See the History tab in the Thymis-Controller web interface for more information.
8 changes: 8 additions & 0 deletions docs/src/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Getting Started

In order to get started with Thymis, you need to create a Thymis-Controller image and run it on your machine.

Follow the instructions below to create a Thymis-Controller image.

- [Creating a Thymis-Controller Device Image](getting_started/creating_a_thymis_controller_device_image.md)
- [Running the Thymis-Controller Device Image](getting_started/running_the_thymis_controller_device_image.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Creating a Thymis-Controller Device Image

You can create a Thymis-Controller device image on the Thymis website.

To create a Thymis-Controller device image, follow these steps:

## Choose a Device

Choose the type of device that you want to create a Thymis-Controller image for.

Currently, the Thymis-Controller supports the following devices:

- Raspberry Pi 4
- Generic x86_64 device

## Add Device Information

Give your device a name and add any additional information that you want to include in the device image.

## Add network configuration

Add network configuration to the device image.

## Add SSH keys

Add SSH keys to the device image.

## Generate the Image

Click the "Generate Image" button to generate the device image.

Follow the instructions on the Thymis website to download the device image and flash it to an SD card/USB drive/Bootable disk.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Running the Thymis-Controller Device Image

Once you have created, downloaded, and flashed the Thymis-Controller device image to an SD card/USB drive/Bootable disk, you can run it on your machine.

Follow your device's instructions to boot from the SD card/USB drive/Bootable disk.

Once the device has booted, you will see a screen that looks like this:

![Thymis-Controller Device Image](images/thymis-controller-device-image.png)

You can connect to the Thymis-Controller using the address shown on the screen, using the credentials that you set when you created the device image.

Once you have connected to the Thymis-Controller, you can start generating, deploying, and managing your IoT devices.
Loading

0 comments on commit d79f728

Please sign in to comment.