Skip to content

Commit

Permalink
Merge pull request #16 from yast/use-cockpit
Browse files Browse the repository at this point in the history
Replace yastd-proxy with cockpit infrastructure
  • Loading branch information
imobachgs committed Feb 2, 2022
2 parents 8c1eff3 + f0bc1e0 commit aa2cd4a
Show file tree
Hide file tree
Showing 32 changed files with 5,271 additions and 9,774 deletions.
19 changes: 19 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Development Notes

## Development Mode

As explained in the [main README](README.md), you can run the web UI in *development mode*, so the
code gets reloaded everytime you make a change. In that scenario, the code is served by `npm`
instead of `cockpit-ws`.

However, the UI needs to access `cockpit-ws` through a different port to log in and interact with
the underlying system. It happens automatically thanks to a [proxy](./web/src/setupProxy.js) which
is configured automatically. If you need to proxy other URLs, just add them to the configuration.

## npm start

`npm start` cleans up the screen during the initialization. It might cause that you miss some
important messages, like the proxy configuration. If you need to check those messages, you can
use this command instead:

$ COLOR=1 npm start | cat
71 changes: 40 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Service-based Experimental Installer
# Service-Based Experimental Installer

The idea of this repository is to build a proof-of-concept of a Linux installer that runs as a
service. At first sight, we have identified these components:
Expand All @@ -8,26 +8,33 @@ service. At first sight, we have identified these components:
disk, etc.).
* A [D-Bus](https://www.freedesktop.org/wiki/Software/dbus/) service which exposes the installer's
API.
* A user interface. For this experiment, we have decided to use a
[Cockpit](https://cockpit-project.org/) module.
* A user interface. For this experiment, we have decided to base on
[Cockpit](https://cockpit-project.org/), although it does not run as a
regular mode (it only uses Cockpit's infrastructure).

## Trying it
## Quickstart

To quickly see what it can do always use VM as it is still experimental. Boot to any OpenSUSE Tumbleweed
!Live! image. And in that image open console and run
:warning: :warning: **This is a proof-of-concept so, PLEASE, use a virtual machine to give it a try.** :warning: :warning:

Boot to any [openSUSE Tumbleweed Live
image](https://get.opensuse.org/tumbleweed) and, in the console, type:

$ wget https://raw.githubusercontent.com/yast/the-installer/master/deploy.sh
$ # inspect content to ensure that nothing malicious is done there
$ sh deploy.sh

This process may take a while. Use `linux`/`linux` when the browser opens the log in form.

The *Setup* section explains how to set-up the installer manually.

TODO: use a url shortener

## Requirements
## Setup

To build and run this software you need a few tools. To install them on openSUSE
Tumbleweed just type:

$ sudo zypper in gcc gcc-c++ make openssl-devel ruby-devel augeas-devel npm
$ sudo zypper in gcc gcc-c++ make openssl-devel ruby-devel augeas-devel npm cockpit

## yastd

Expand All @@ -44,7 +51,8 @@ To run the service, type:
$ bundle install
$ sudo bunle exec bin/yastd

You can use a tool like [busctl](https://www.freedesktop.org/wiki/Software/dbus/) (or
To check that `yastd` is working, you can use a tool like
[busctl](https://www.freedesktop.org/wiki/Software/dbus/) (or
[D-Feet](https://wiki.gnome.org/Apps/DFeet) if you prefer a graphical one:

$ busctl call org.opensuse.YaST /org/opensuse/YaST/Installer \
Expand All @@ -55,38 +63,39 @@ If you want to get the properties, just type:
$ busctl call org.opensuse.YaST /org/opensuse/YaST/Installer \
org.freedesktop.DBus.Properties GetAll s org.opensuse.YaST.Installer

## yastd-proxy

The `yastd-proxy` allows accessing the D-Bus interface through HTTP. Additionally, it uses
a websocket to forward `PropertiesChanged` signals (not implemented yet).

Note: at this point in time, it is a minimal Rails application (it does not include a database,
JavaScript, etc.). In the future, we could replace it with anything even smaller.
## Cockpit

To start the proxy, just type:
The user interface uses Cockpit infrastructure to interact with the D-Bus interface, so you
need to make sure that `cockpit` is running:

$ cd yastd-proxy
$ bundle install
$ bundle exec bin/yastd-proxy
$ sudo systemctl start cockpit

Now you can try to access the D-Bus service using cURL:
## Web-Based User Interface

$ curl http://localhost:3000/properties
[{"Disk":"/dev/sda","Product":"openSUSE-Addon-NonOss","Language":"en_US","Status":0}]
$ curl -X PUT -d value=/dev/sda http://localhost:3000/properties/Disk
$ curl -X POST -d meth=GetStorage http://localhost:3000/calls
[{"mount":"/boot/efi","device":"/dev/sda1","type":"vfat","size":"536870912"},...
The current UI is a small web application built with [React](https://reactjs.org/). On production it
is meant to be served by `cockpit-ws` from an directory in `XDG_DATA_DIRS` (e.g.,
`/usr/share/cockpit/static/installer`). Building the code might time some time, so there is a
*development mode* available that reloads the code everytime it changes.

## Web UI
### Development Mode

The current UI is a small web application built with [React](https://reactjs.org/). It allows to set a few installation parameters and start the installation (not implemented yet).
It allows to set a few installation parameters and start the installation (not implemented yet).

$ cd web
$ npm install
$ npm start

Point your browser to http://localhost:3000 and enjoy!
Point your browser to http://localhost:3000 and happy hacking!

### Production-like Mode

$ cd web
$ npm run build
$ sudo mkdir /usr/share/cockpit/static/installer
$ sudo mount -o bind build /usr/share/cockpit/static/installer

Point your browser to http://localhost:9090/cockpit/static/installer/index.html and enjoy!

# References
## References

* https://etherpad.opensuse.org/p/H_bqkqApbfKB5RwNIYSm
* [Development Notes](./DEVELOPMENT.md)
23 changes: 17 additions & 6 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
#! /bin/sh
sudo zypper --non-interactive install gcc gcc-c++ make openssl-devel ruby-devel npm git augeas-devel || exit 1
sudo zypper --non-interactive install gcc gcc-c++ make openssl-devel ruby-devel \
npm git augeas-devel cockpit || exit 1

git clone https://github.com/yast/the-installer || exit 1
cd the-installer

# set up yastd
sudo cp yastd/share/dbus-yastd.conf /etc/dbus-1/system.d/yastd.conf
cd yastd; bundle config --set local path vendor/bundle; bundle install; cd -
cd yastd-proxy; bundle config --set local path vendor/bundle; bundle install; cd -
cd web; npm install; cd -
cd yastd; sudo bundle exec bin/yastd& cd -
cd yastd-proxy; bundle exec bin/yastd-proxy& cd -
cd web; npm start& cd -
cd yastd; sudo bundle.ruby3.1 exec bin/yastd& cd -

# set up the web UI
cd web; npm install; npm run build; cd -
sudo mkdir /usr/share/cockpit/static/installer
sudo mount -o bind web/build /usr/share/cockpit/static/installer
sudo systemctl start cockpit

# set 'linux' as password
echo "linux:Nk1RhI1GqlxdA | sudo chpasswd -e linux
# open the installer
xdg-open http://localhost:9090/cockpit/static/installer/index.html
wait
Loading

0 comments on commit aa2cd4a

Please sign in to comment.