2017-08-05 23:57:15 +02:00
# ynh-dev - Yunohost dev environnement manager
2016-04-27 09:23:32 +02:00
2017-08-05 23:57:15 +02:00
ynh-dev is a CLI tool to manage your local development environement for YunoHost. This allow you to develop on the various repository of the YunoHost project.
2016-01-30 22:38:29 +01:00
2017-08-05 23:57:15 +02:00
In particular, it allows :
2016-04-27 09:23:32 +02:00
2017-08-05 23:57:15 +02:00
* to create a directory with a clone of each repository of the YunoHost project ;
* to replace already installed yunohost debian packages by symlinks to those git clones ;
* to manage yunohost instances on your host machine with Vagrant by:
* creating a Vagrant VM with a pre-installed Yunohost system ;
* sharing the dev environnement your host the VM (so you can develop directly on your host)
2016-10-27 21:46:35 +02:00
* finding the ip address of your yunohost vagrant vm
2016-06-23 13:51:53 +02:00
2017-08-05 23:57:15 +02:00
yhn-dev can be used :
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
1. on your local machine with VMs (more comfortable)
2. on a remote machine dedicated to dev (e.g. if you need the VM to be exposed on internet : test let's encrypt, email stack ...)
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
## Develop on your local machine
2016-10-27 21:46:35 +02:00
Here is the development flow:
2017-08-05 23:57:15 +02:00
1. [first time] Setup ynh-dev and the development environnement
2016-10-27 21:46:35 +02:00
2. Create or run a yunohost vagrant instance
3. Upgrade, postinstall and deploy development version from repositories
2017-08-05 23:57:15 +02:00
4. Develop on your host
5. Test via the CLI or webadmin
2016-10-27 21:46:35 +02:00
6. Suspend or kill your vm
2017-08-05 23:57:15 +02:00
### 1. [first time] Setup ynh-dev and the development environnement
2016-10-27 21:46:35 +02:00
These operation need to be done on the host machine.
#### Install dependencies
2016-12-04 00:38:25 +01:00
2017-08-05 23:57:15 +02:00
- Debian, Ubuntu, Mint
```bash
2016-07-08 19:23:30 +02:00
sudo apt-get install vagrant virtualbox git
2016-01-30 22:38:29 +01:00
```
2017-08-05 23:57:15 +02:00
- Fedora
```bash
2016-07-08 19:23:30 +02:00
sudo dnf install vagrant git
2016-06-23 13:51:53 +02:00
```
2016-08-30 16:24:18 +02:00
2017-08-05 23:57:15 +02:00
[Install Virtualbox 5.1.x ](http://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-rhel )
- Archlinux, Manjaro
2016-08-30 14:09:10 +02:00
2017-08-05 23:57:15 +02:00
```bash
2016-12-04 00:38:25 +01:00
sudo pacman -S vagrant virtualbox git
sudo pacman -S linux44-virtualbox-host-modules
sudo modprobe vboxdrv
sudo modprobe vboxnetadp
sudo insmod /lib/modules/4.4.33-1-MANJARO/extramodules/vboxnetflt.ko.gz
sudo insmod /lib/modules/4.4.33-1-MANJARO/extramodules/vboxnetadp.ko.gz
```
2016-01-30 22:38:29 +01:00
2016-10-27 21:46:35 +02:00
#### Install ynh-dev
2017-08-05 19:55:23 +02:00
Clone the ynh-dev repo :
2017-08-05 23:57:15 +02:00
```bash
2017-08-05 19:55:23 +02:00
git clone https://github.com/YunoHost/ynh-dev
cd ynh-dev
2016-01-30 22:38:29 +01:00
```
2016-04-27 09:23:32 +02:00
2016-10-27 21:46:35 +02:00
#### Create the environment
2017-08-05 19:55:23 +02:00
This command create a clone of all Yunohost's main git repositories in `./` .
2017-08-05 23:57:15 +02:00
```bash
2017-08-05 19:55:23 +02:00
./ynh-dev create-env ./
2016-01-30 22:38:29 +01:00
```
2017-08-05 23:57:15 +02:00
### 2. Create or run a yunohost vagrant instance
2016-05-27 13:15:38 +02:00
2017-08-05 23:57:15 +02:00
This command is a helper to run a Vagrant virtual machine in the right place with YunoHost pre-installed.
2017-08-05 19:55:23 +02:00
2017-08-05 23:57:15 +02:00
```bash
2017-08-05 19:55:23 +02:00
./ynh-dev run yolo.test unstable
2016-01-30 22:38:29 +01:00
```
2016-05-27 13:15:38 +02:00
The `run` command takes 2 arguments: domain and YunoHost version.
2016-10-27 21:46:35 +02:00
After running the container, you'll be automatically logged inside a new yunohost VM or inside the previous suspended VM.
2016-05-03 14:30:52 +02:00
2017-08-05 19:55:23 +02:00
#### Shared folder between host and virtual machines
2016-05-03 14:32:53 +02:00
2017-08-05 19:55:23 +02:00
One logged into the VM, you can go to `/vagrant` and find all the files from your dev environnement, including the `ynh-dev` script itself.
2016-05-03 14:32:53 +02:00
2017-08-05 23:57:15 +02:00
### 3. Upgrade and configure your dev instance
2016-04-27 09:23:32 +02:00
2017-08-05 23:57:15 +02:00
According to what you intend to develop or test, you might need to upgrade, to postinstall.
2016-08-30 16:24:18 +02:00
2016-10-27 21:46:35 +02:00
For example if you want :
* to test an app => upgrade and postinstall
* to test a common core code => upgrade, postinstall and deploy your code
* to test the impact of a core code on postinstall => upgrade, deploy your code, postinstall
2016-04-27 09:23:32 +02:00
2016-10-27 21:46:35 +02:00
#### Upgrade
2016-01-30 22:38:29 +01:00
2017-08-05 23:57:15 +02:00
If the container is not up to date, you can run the following command to update debian packages, including YunoHost ones.
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
/vagrant/ynh-dev upgrade
2016-10-27 21:46:35 +02:00
```
2017-08-05 23:57:15 +02:00
#### Use your git repositories in place of debian package
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
When doing `create-env` command, every YunoHost package have been cloned in the
corresponding path. You can link your VM to use these git clones such that changes you make in the code are directly used in the VM :
2016-05-03 14:32:53 +02:00
2017-08-05 23:57:15 +02:00
```bash
/vagrant/ynh-dev use-git PACKAGE
2016-10-27 21:46:35 +02:00
```
2016-01-30 22:38:29 +01:00
2017-08-05 23:57:15 +02:00
PACKAGE should can be ssowat, yunohost, moulinette or yunohost-admin. 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
2017-08-05 23:57:15 +02:00
***Note***: The `use-git` operation can't be reverted now. DON'T DO THIS IN PRODUCTION !
2016-05-03 14:32:53 +02:00
2016-04-27 12:26:11 +02:00
2017-08-05 23:57:15 +02:00
#### Postinstall
2016-04-27 12:26:11 +02:00
2017-08-05 23:57:15 +02:00
If you need a properly installed YunoHost to develop and test, you probably want to run the postinstall now:
2016-05-03 14:32:53 +02:00
2017-08-05 23:57:15 +02:00
```bash
(sudo) yunohost tools postinstall -d yolo.test
```
2016-01-30 22:38:29 +01:00
2017-08-05 23:57:15 +02:00
### 4. Develop on your host
2016-10-27 21:46:35 +02:00
At this point, you are able to code on your host machine, with the EDI of your choice.
All change will be available on the container inside the share folder /vagrant.
2016-04-27 09:23:32 +02:00
2017-08-05 23:57:15 +02:00
### 5. Test changes via the CLI or the web interface
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
#### Tests in CLI
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
If you have run `use-git` , all changes on the local git clones are automatically available in your VM, so you can run any `yunohost foo bar` command.
2016-05-03 14:32:53 +02:00
2017-08-05 23:57:15 +02:00
#### Tests the web interface
2016-01-30 22:38:29 +01:00
2017-08-05 23:57:15 +02:00
You should be able to access the web interface via the IP address on the vagrant container. The IP can be known from inside the container with :
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
/vagrant/ynh-dev ip
```
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
2017-08-05 23:57:15 +02:00
### 6. Suspend or kill your vm
When you're finished or if you want to shut down your computer, you should kill or suspend the VM.
2016-10-27 21:46:35 +02:00
To kill the vm, just do on your host:
2017-08-05 23:57:15 +02:00
```bash
2016-10-27 21:46:35 +02:00
cd /path/to/dev/env
vagrant destroy unstable
# or
./ynh-dev kill
```
2017-08-05 23:57:15 +02:00
To suspend the VM:
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
2016-10-27 21:46:35 +02:00
cd /path/to/dev/env
vagrant suspend unstable
```
2017-08-05 23:57:15 +02:00
## Develop on a remote server
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
Firstly, you need to understand that it is a dev tool : you shouldn't run it on a production environment !
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
This case allows you to use ynh-dev on a vm exposed on the internet. This can be useful when testing features for which the server is required to be reachable from the whole internet (e.g. Let's Encrypt certificate install, or mail-related features). An alterative is to use a VPN (through vpnclient_ynh) with an IPv4.
2016-10-27 21:46:35 +02:00
The development flow is quite similar to the first method:
1. [first time] Setup ynh-dev and Setup a copy of each git repository
2. Upgrade, postinstall and deploy development version from repositories
3. Code on your host
4. Test by cli on the instance or test on your host browser
2017-08-05 23:57:15 +02:00
### 1. Setup
It's possible to setup ynh-dev inside an existing instance of YunoHost rather than create vagrant vm with ynh-dev. In this particular case, you need to setup your env inside a `/vagrant/` directory even if you don't use vagrant.
2016-10-27 21:46:35 +02:00
2017-08-05 23:57:15 +02:00
```bash
2016-10-27 21:46:35 +02:00
sudo apt-get install git
2017-08-05 19:55:23 +02:00
git clone https://github.com/YunoHost/ynh-dev /vagrant/
cd /vagrant/
2016-10-27 21:46:35 +02:00
```
2017-08-05 19:55:23 +02:00
2017-08-05 23:57:15 +02:00
### 2. Upgrade, postinstall and use git repositories
2017-08-05 19:55:23 +02:00
2016-10-27 21:46:35 +02:00
Identical to 1.3, but take care to don't postinstall on a yunohost already postinstalled !
Important, when you use the git repositories, you can't do the reverse operation simply... (To do it you need to wait an update of the concern package)
2017-08-05 23:57:15 +02:00
### 3. Code on the instance directly
2017-08-05 19:55:23 +02:00
2016-10-27 21:46:35 +02:00
Contrary to the first method, you have not a share folder so you need to develop inside the instance. Alternatively, you could explore to setup sshfs or this kind of solution.
2017-08-05 23:57:15 +02:00
### 4. Test
2016-10-27 21:46:35 +02:00
Identical to 1.5, but ynh-dev ip doesn't work. You should prefer this command to find your ip address:
2017-08-05 23:57:15 +02:00
```bash
ip addr
```
2016-05-03 14:32:53 +02:00
2016-10-27 21:46:35 +02:00
Keep in mind, that if you use your /etc/hosts file, let's encrypt or other service couldn't access the VM. So you probably need to set up a correct domain.
2016-04-27 09:23:32 +02:00
2016-05-03 14:32:53 +02:00
2016-01-30 22:38:29 +01:00
2016-10-27 21:46:35 +02:00
## More info
2016-01-30 22:38:29 +01:00
2016-08-30 16:24:18 +02:00
[yunohost.org/dev_fr ](https://yunohost.org/dev_fr ) (in french) not up-to-date.