2019-05-19 17:42:08 +02:00
# ynh-dev - Yunohost dev environment manager
2016-04-27 09:23:32 +02:00
2019-05-21 13:57:13 +02:00
Please report issues on the following repository:
2018-06-23 21:34:41 +02:00
2019-05-21 13:57:13 +02:00
> https://github.com/yunohost/issues
2016-01-30 22:38:29 +01:00
2019-05-21 13:57:13 +02:00
# Table Of Contents
2016-04-27 09:23:32 +02:00
2019-05-21 13:57:13 +02:00
- [Introduction ](#introduction )
* [Local Development Path ](#local-development-path )
* [Remote Development Path ](#remote-development-path )
2016-06-23 13:51:53 +02:00
2019-05-21 13:57:13 +02:00
- [Local Development Environment ](#local-development-environment )
* [1. Setup `ynh-dev` and the development environment ](#1-setup-ynh-dev-and-the-development-environment )
* [2. Manage YunoHost's dev LXCs ](#2-manage-yunohosts-dev-lxcs )
* [3. Development and container testing ](#3-development-and-container-testing )
* [4. Testing the web interface ](#4-testing-the-web-interface )
* [Advanced: using snapshots ](#advanced-using-snapshots )
2019-05-22 22:06:47 +02:00
* [Alternative: Only Virtualbox ](#alternative-using-only-virtualbox )
2021-01-10 03:05:26 +01:00
* [Troubleshooting ](#troubleshooting )
2016-10-27 21:46:35 +02:00
2019-05-21 13:57:13 +02:00
- [Remote Development Environment ](#remote-development-environment )
* [1. Setup your VPS and install YunoHost ](#1-setup-your-vps-and-install-yunohost )
* [2. Setup `ynh-dev` and the development environment ](#2-setup-ynh-dev-and-the-development-environment )
* [3. Develop and test ](#3-develop-and-test )
- [Further Resources ](#further-resources )
---
# Introduction
`ynh-dev` is a CLI tool to manage your local development environment for YunoHost.
This allow you to develop on the various repositories of the YunoHost project.
In particular, it allows you to:
* Create a directory with a clone of each repository of the YunoHost project
* Replace Yunohost debian packages with symlinks to those git clones
Because there are many diverse constraints on the development of the Yunohost
project, there is no "official" one-size-fits-all development environment.
However, we do provide documentation for what developers are using now in
various circumstances.
Please keep this in mind when reviewing the following options with regard to
your capacities and resources when aiming to setup a development environment.
`yhn-dev` can be used for the following scenarios:
## Local Development Path
Yunohost can be developed on using a combination of the following technologies:
* Git (any version is sufficient)
2019-10-01 20:33:36 +02:00
* LXD (>= 2.x) (though only tested with 3.x for now)
2019-05-21 13:57:13 +02:00
2019-10-08 21:20:54 +02:00
Because LXC are containers, they are typically lightweight and quick to start and stop.
But you may find the initial setup complex (in particular network configuration).
LXD makes managing an LXC ecosystem much simpler.
2019-05-21 13:57:13 +02:00
2019-05-21 16:45:04 +02:00
This local development path allows to work without an internet connection,
but be aware that it will *not* allow you to easily test your email stack
or deal with deploying SSL certificates, for example, as your machine is
likely to not be exposed on the internet. A remote machine should be used
for these cases.
2019-05-21 13:57:13 +02:00
If choosing this path, please keep reading at the [local development
environment](#local-development-environment) section.
2019-10-08 21:20:54 +02:00
Alternatively, you may be able to setup a local environnement using Vagrant and
Virtualbox which is kinda more resource-hungry because it is fully virtualized,
but might be more familiar and user-friendly if you already know your way around
Virtualbox's UI.
* Virtualbox (>= 6.x)
* Vagrant (>= ?.?.?)
* Vagrant-virtualbox (>= ?.?.?)
See the [Alternative: Only Virtualbox ](#alternative-using-only-virtualbox )
section for more info.
2019-05-22 22:06:47 +02:00
2019-05-21 13:57:13 +02:00
## Remote Development Path
Yunohost can be deployed as a typical install on a remote VPS. You can then use
`ynh-dev` to configure a development environment on the server.
This method can potentially be faster than the local development environment
2019-05-21 16:45:04 +02:00
assuming you have familiarity with working on VPS machines, if you always have
internet connectivity when working, and if you're okay with paying a fee. It
2019-10-08 21:20:54 +02:00
is also a good option if the required system dependencies (LXD/LXC, Vagrant,
Virtualbox, etc.) are not easily available to you on your distribution.
2019-05-21 13:57:13 +02:00
Please be aware that this method should **not** be used for a end-user facing
production environment.
If choosing this path, please keep reading at the [remote development
environment](#remote-development-environment) section.
# Local Development Environment
2016-10-27 21:46:35 +02:00
Here is the development flow:
2019-05-21 13:57:13 +02:00
1. Setup `ynh-dev` and the development environment
2. Manage YunoHost's development LXCs
3. Develop on your local host and testing in the container
2016-10-27 21:46:35 +02:00
2019-05-21 13:57:13 +02:00
## 1. Setup `ynh-dev` and the development environment
2016-12-04 00:38:25 +01:00
2019-05-21 13:57:13 +02:00
First you need to install the system dependencies.
2019-10-08 21:24:40 +02:00
`ynh-dev` essentially requires Git and the LXD/LXC ecosystem. Be careful that
**LXD can conflict with other installed virtualization technologies such as
libvirt or vanilla LXCs**, especially because they all require a daemon based
on DNSmasq and therefore require to listen on port 53.
2019-10-01 20:33:36 +02:00
On a Debian-based system (regular Debian, Ubuntu, Mint ...), LXD can be
2019-10-08 21:24:40 +02:00
installed using `snapd` . On other systems like Archlinux, you will probably also
be able to install `snapd` using the system package manager (or even
2019-10-01 20:33:36 +02:00
`lxd` directly).
2017-08-05 23:57:15 +02:00
```bash
2019-10-01 20:33:36 +02:00
apt install git snapd
2020-07-26 16:51:04 +02:00
sudo snap install core
2019-10-08 23:13:34 +02:00
sudo snap install lxd
2019-02-06 23:06:15 +01:00
2019-10-08 23:45:39 +02:00
# Adding lxc/lxd to /usr/local/bin to make sure we can use them easily even
# with sudo for which the PATH is defined in /etc/sudoers and probably doesn't
# include /snap/bin
sudo ln -s /snap/bin/lxc /usr/local/bin/lxc
sudo ln -s /snap/bin/lxd /usr/local/bin/lxd
2019-02-06 23:06:15 +01:00
```
2019-10-01 20:33:36 +02:00
Then you shall initialize LXD which will ask you a bunch of question. Usually
answering the default (just pressing enter) to all questions is fine.
2019-05-21 13:57:13 +02:00
2019-10-01 20:33:36 +02:00
```bash
2019-10-08 23:13:34 +02:00
sudo lxd init
2019-05-21 13:57:13 +02:00
```
2019-03-08 17:46:37 +01:00
2021-01-22 01:55:29 +01:00
Pre-built images are centralized on `devbaseimgs.yunohost.org` and we'll download them from there to speed things up:
```bash
sudo lxc remote add yunohost https://devbaseimgs.yunohost.org --public
```
2021-04-19 19:29:27 +02:00
On Archlinux-based distributions (Arch, Manjaro, ...) it was found that it's needed
that LXC/LXD will throw some error about "newuidmap failed to write mapping / Failed
to set up id mapping" ... It can be [fixed with the following ](https://discuss.linuxcontainers.org/t/solved-arch-linux-containers-only-run-when-security-privileged-true/4006/4 ) :
```
# N.B.: this is ONLY for Arch-based distros
$ echo "root:1000000:65536" > /etc/subuid
$ echo "root:1000000:65536" > /etc/subgid
```
2019-05-21 13:57:13 +02:00
Then, go into your favorite development folder and deploy `ynh-dev` with:
2016-08-30 14:09:10 +02:00
2017-08-05 23:57:15 +02:00
```bash
2018-09-04 16:37:34 +02:00
curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
2016-12-04 00:38:25 +01:00
```
2019-05-21 13:57:13 +02:00
This will create a new `ynh-dev` folder with everything you need inside.
In particular, you shall notice that there are clones or the various git
repositories. In the next step, we shall start a LXC and 'link' those folders
between the host and the LXC.
2016-01-30 22:38:29 +01:00
2019-05-21 13:57:13 +02:00
## 2. Manage YunoHost's dev LXCs
2017-08-05 19:55:23 +02:00
2018-09-04 02:25:26 +02:00
When ran on the host, the `./ynh-dev` command allows you to manage YunoHost's dev LXCs.
2017-08-05 19:55:23 +02:00
2021-04-19 19:29:27 +02:00
Start your actual dev LXC using :
2017-08-05 19:55:23 +02:00
2017-08-05 23:57:15 +02:00
```bash
2019-05-21 13:57:13 +02:00
$ cd ynh-dev # if not already done
2019-10-01 20:33:36 +02:00
$ ./ynh-dev start
```
2017-08-05 19:55:23 +02:00
2021-04-19 19:29:27 +02:00
This should automatically download from `devbaseimgs.yunohost.org` a pre-build ynh-dev LXC image running Yunohost unstable, and create a fresh container from it.
2019-10-01 20:33:36 +02:00
After starting the LXC, your terminal will automatically be attached to it. If you later disconnect from the LXC, you can go back in with `./ynh-dev attach` . Later, you might want to destroy the LXC. You can do so with `./ynh-dev destroy` .
2016-01-30 22:38:29 +01:00
2019-05-21 13:57:13 +02:00
## 3. Development and container testing
2016-05-03 14:30:52 +02:00
2018-09-04 02:25:26 +02:00
After SSH-ing inside the container, you should notice that the *directory* `/ynh-dev` is a shared folder with your host. In particular, it contains the various git clones `yunohost` , `yunohost-admin` and so on - as well as the `./ynh-dev` script itself.
2018-05-09 13:16:47 +02:00
2018-09-04 02:25:26 +02:00
Inside the container, `./ynh-dev` can be used to link the git clones living in the host to the code being ran inside the container.
2016-08-30 16:24:18 +02:00
2019-05-21 13:57:13 +02:00
For instance, after running:
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
2019-05-21 13:57:13 +02:00
$ ./ynh-dev use-git yunohost
2016-10-27 21:46:35 +02:00
```
2019-05-21 13:57:13 +02:00
The code of the git clone `'yunohost'` will be directly available inside the container. Which mean that running any `yunohost` command inside the container will use the code from the host... This allows to develop with any tool you want on your host, then test the changes in the container.
2016-01-30 22:38:29 +01:00
2018-11-02 02:29:54 +01:00
The `use-git` action can be used for any package among `yunohost` , `yunohost-admin` , `moulinette` and `ssowat` with similar consequences. You might want to run use-git several times depending on what you want to develop precisely.
2016-04-27 12:26:11 +02:00
2019-05-21 13:57:13 +02:00
***Note***: The `use-git` operation can't be reverted now. Do **not** do this in production.
2016-04-27 12:26:11 +02:00
2019-05-21 13:57:13 +02:00
## 4. Testing the web interface
2016-05-03 14:32:53 +02:00
2018-09-04 02:25:26 +02:00
You should be able to access the web interface via the IP address of the container. The IP can be known from inside the container using either from `ip a` or with `./ynh-dev ip` .
2017-08-05 23:57:15 +02:00
2019-05-21 13:57:13 +02:00
If you want to access to the interface using the domain name, you shall tweak your `/etc/hosts` and add a line such as:
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
111.222.333.444 yolo.test
```
2016-10-27 21:46:35 +02:00
2019-05-21 13:57:13 +02:00
Note that `./ynh-dev use-git yunohost-admin` has a particular behavior: it starts a `gulp` watcher that shall re-compile automatically any changes in the javascript code. Hence this particular `use-git` will keep running until you kill it after your work is done.
2018-06-27 14:16:57 +02:00
2019-05-21 13:57:13 +02:00
## Advanced: using snapshots
2018-06-27 14:25:42 +02:00
2019-10-01 20:33:36 +02:00
You can check `lxc snapshot --help` to learn how to manage lxc snapshots.
2018-06-27 14:25:42 +02:00
2019-05-22 22:06:47 +02:00
## Alternative: Using Only Virtualbox
A Vagrant and Virtualbox (without LXC) guide is provided on another branch of
this repository. This is a known working setup used by some developers. Please
see the ["virtualbox" branch ](https://github.com/YunoHost/ynh-dev/tree/virtualbox#develop-on-your-local-machine )
for more.
2021-01-10 03:05:26 +01:00
## Troubleshooting
If you experiment network issues with your lxd during rebuild container steps. Probably your container are not able to get a local IP with DHCP.
It could be due to bridge conflict (for example if you have lxc installed too) or dnsmasq port already used.
This [ticket ](https://github.com/YunoHost/issues/issues/1664 ) could help.
2019-05-21 13:57:13 +02:00
# Remote Development Environment
2018-06-27 14:25:42 +02:00
2019-05-21 13:57:13 +02:00
Here is the development flow:
2018-06-27 14:25:42 +02:00
2018-09-04 02:25:26 +02:00
1. Setup your VPS and install YunoHost
2019-05-21 13:57:13 +02:00
2. Setup `ynh-dev` and the development environment
2018-09-04 02:25:26 +02:00
3. Develop and test
2018-06-27 14:25:42 +02:00
2019-05-21 13:57:13 +02:00
## 1. Setup your VPS and install YunoHost
2018-06-27 14:25:42 +02:00
2019-05-21 13:57:13 +02:00
Setup a VPS somewhere (e.g. Scaleway, Digital Ocean, etc.) and install YunoHost following the [usual instructions ](https://yunohost.org/#/install_manually ).
2018-06-27 14:25:42 +02:00
2018-09-04 02:25:26 +02:00
Depending on what you want to achieve, you might want to run the postinstall right away - and/or setup a domain with an actually working DNS.
2018-06-27 14:25:42 +02:00
2019-05-21 13:57:13 +02:00
## 2. Setup `ynh-dev` and the development environment
2018-06-27 14:25:42 +02:00
2019-05-21 13:57:13 +02:00
Deploy a `ynh-dev` folder at the root of the filesystem with:
2018-06-27 14:25:42 +02:00
```
2019-05-21 13:57:13 +02:00
$ cd /
$ curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
$ cd /ynh-dev
2016-10-27 21:46:35 +02:00
```
2017-08-05 19:55:23 +02:00
2019-05-21 13:57:13 +02:00
## 3. Develop and test
2016-10-27 21:46:35 +02:00
2018-09-04 02:25:26 +02:00
Inside the VPS, `./ynh-dev` can be used to link the git clones to actual the code being ran.
2016-10-27 21:46:35 +02:00
2019-05-21 13:57:13 +02:00
For instance, after running:
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
2019-05-21 13:57:13 +02:00
$ ./ynh-dev use-git yunohost
2017-08-05 23:57:15 +02:00
```
2016-05-03 14:32:53 +02:00
2019-05-21 13:57:13 +02:00
Any `yunohost` command will run from the code of the git clone.
The `use-git` action can be used for any package among `yunohost` , `yunohost-admin` , `moulinette` and `ssowat` with similar consequences.
2016-01-30 22:38:29 +01:00
2019-05-21 13:57:13 +02:00
# Further Resources
2016-01-30 22:38:29 +01:00
2019-05-21 13:57:13 +02:00
* [yunohost.org/dev ](https://yunohost.org/dev )