mirror of
https://github.com/YunoHost/ynh-dev.git
synced 2024-09-03 20:05:59 +02:00
Merge branch 'master' of https://github.com/YunoHost/ynh-dev
This commit is contained in:
commit
55e83478eb
4 changed files with 279 additions and 253 deletions
267
README.md
267
README.md
|
@ -1,173 +1,268 @@
|
||||||
# ynh-dev - Yunohost dev environment manager
|
# ynh-dev - Yunohost dev environment manager
|
||||||
|
|
||||||
Report issues here: https://github.com/yunohost/issues
|
Please report issues on the following repository:
|
||||||
|
|
||||||
ynh-dev is a CLI tool to manage your local development environment for YunoHost. This allow you to develop on the various repository of the YunoHost project.
|
> https://github.com/yunohost/issues
|
||||||
|
|
||||||
In particular, it allows :
|
# Table Of Contents
|
||||||
|
|
||||||
* to create a directory with a clone of each repository of the YunoHost project ;
|
- [Introduction](#introduction)
|
||||||
* to replace already installed yunohost debian packages by symlinks to those git clones ;
|
* [Local Development Path](#local-development-path)
|
||||||
* to manage yunohost instances on your host machine with Vagrant by:
|
* [Remote Development Path](#remote-development-path)
|
||||||
* 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)
|
|
||||||
* finding the ip address of your yunohost vagrant vm
|
|
||||||
|
|
||||||
yhn-dev can be used either :
|
- [Local Development Environment](#local-development-environment)
|
||||||
1. on your local machine with LXCs (you can peacefully develop independently of your internet connection)
|
* [1. Setup `ynh-dev` and the development environment](#1-setup-ynh-dev-and-the-development-environment)
|
||||||
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 ...)
|
* [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)
|
||||||
|
* [Alternative: Only Virtualbox](#alternative-using-only-virtualbox)
|
||||||
|
|
||||||
## Develop on your local machine
|
- [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)
|
||||||
|
* LXD (>= 2.x) (though only tested with 3.x for now)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
If choosing this path, please keep reading at the [local development
|
||||||
|
environment](#local-development-environment) section.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
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
|
||||||
|
is also a good option if the required system dependencies (LXD/LXC, Vagrant,
|
||||||
|
Virtualbox, etc.) are not easily available to you on your distribution.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
Here is the development flow:
|
Here is the development flow:
|
||||||
|
|
||||||
1. Setup ynh-dev and the development environnement
|
1. Setup `ynh-dev` and the development environment
|
||||||
2. Manage YunoHost's dev LXCs
|
2. Manage YunoHost's development LXCs
|
||||||
3. Developping on your host, and testing in the container
|
3. Develop on your local host and testing in the container
|
||||||
|
|
||||||
### 1. Setup ynh-dev and the development environment
|
## 1. Setup `ynh-dev` and the development environment
|
||||||
|
|
||||||
First you need to install the dependencies. ynh-dev essentially requires git, vagrant, and an LXC ecosystem.
|
First you need to install the system dependencies.
|
||||||
|
|
||||||
Please consider using the [latest Vagrant version from their website](https://www.vagrantup.com/downloads.html), distribution versions can include weird bugs that have been fixed upstream. If you still prefer to do that, here are the instructions:
|
`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.
|
||||||
|
|
||||||
The following commands should work on **Linux Mint 19** (and possibly on any Debian Stretch?) :
|
On a Debian-based system (regular Debian, Ubuntu, Mint ...), LXD can be
|
||||||
|
installed using `snapd`. On other systems like Archlinux, you will probably also
|
||||||
|
be able to install `snapd` using the system package manager (or even
|
||||||
|
`lxd` directly).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt update
|
apt install git snapd
|
||||||
sudo apt install git vagrant lxc-templates lxctl lxc cgroup-lite redir bridge-utils libc6 debootstrap
|
sudo snap install core
|
||||||
vagrant plugin install vagrant-lxc
|
sudo snap install lxd
|
||||||
echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" | sudo tee -a /etc/fstab
|
|
||||||
sudo mount /sys/fs/cgroup
|
# Adding lxc/lxd to /usr/local/bin to make sure we can use them easily even
|
||||||
lxc-checkconfig
|
# with sudo for which the PATH is defined in /etc/sudoers and probably doesn't
|
||||||
echo "veth" | sudo tee -a /etc/modules
|
# include /snap/bin
|
||||||
|
sudo ln -s /snap/bin/lxc /usr/local/bin/lxc
|
||||||
|
sudo ln -s /snap/bin/lxd /usr/local/bin/lxd
|
||||||
```
|
```
|
||||||
|
|
||||||
On **Debian Buster**, I had to re-patch the driver.rb of vagrant-lxc plugin with [this version](https://raw.githubusercontent.com/fgrehm/vagrant-lxc/2a5510b34cc59cd3cb8f2dcedc3073852d841101/lib/vagrant-lxc/driver.rb) (especially the `roofs_path` function). I also had to install `apparmor` then `systemctl restart apparmor` for `lxc-start` to work. Also check instruction on https://feeding.cloud.geek.nz/posts/lxc-setup-on-debian-stretch/
|
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.
|
||||||
|
|
||||||
If you run **Archlinux**, this page should be quite useful to setup LXC : https://github.com/fgrehm/vagrant-lxc/wiki/Usage-on-Arch-Linux-hosts
|
```bash
|
||||||
|
sudo lxd init
|
||||||
On **both Debian and Archlinux**, typically `/etc/default/lxc-net` and `/etc/lxc/default.conf` should look like this :
|
|
||||||
|
|
||||||
```
|
|
||||||
> cat /etc/default/lxc-net
|
|
||||||
USE_LXC_BRIDGE="true"
|
|
||||||
LXC_BRIDGE="lxcbr0"
|
|
||||||
LXC_ADDR="10.0.3.1"
|
|
||||||
LXC_NETMASK="255.255.255.0"
|
|
||||||
LXC_NETWORK="10.0.3.0/24"
|
|
||||||
LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
|
|
||||||
LXC_DHCP_MAX="253"
|
|
||||||
|
|
||||||
> cat /etc/lxc/default.conf
|
|
||||||
lxc.net.0.type = veth
|
|
||||||
lxc.net.0.link = lxcbr0
|
|
||||||
lxc.net.0.flags = up
|
|
||||||
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
|
|
||||||
```
|
```
|
||||||
|
|
||||||
On **Debian Buster**, for backup stuff to work correctly with apparmor, I also had to add `mount options=(ro, remount, bind, rbind),` and ` mount options=(ro, remount, bind, relatime),` to `/etc/apparmor.d/lxc/lxc-default-cgns` and restart the apparmor service.
|
Then, go into your favorite development folder and deploy `ynh-dev` with:
|
||||||
|
|
||||||
Then, go into your favorite development folder and deploy ynh-dev with :
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
|
curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
This will create a new `ynh-dev` folder with everything you need inside.
|
||||||
|
|
||||||
### 2. Learn how to manage YunoHost's dev LXCs
|
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.
|
||||||
|
|
||||||
|
## 2. Manage YunoHost's dev LXCs
|
||||||
|
|
||||||
When ran on the host, the `./ynh-dev` command allows you to manage YunoHost's dev LXCs.
|
When ran on the host, the `./ynh-dev` command allows you to manage YunoHost's dev LXCs.
|
||||||
|
|
||||||
First, you might want to start a new LXC with :
|
First, you might want to build the base LXC with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd ynh-dev # if not already done
|
$ cd ynh-dev # if not already done
|
||||||
./ynh-dev start
|
$ ./ynh-dev rebuild
|
||||||
|
# ... This will take some time, grab your favorite beverage ...
|
||||||
```
|
```
|
||||||
|
|
||||||
This should download an already built LXC from `build.yunohost.org`. If this does not work (or the LXC is outdated), you might want to (re)build a fresh LXC locally with `./ynh-dev rebuild`.
|
This should create a fresh Debian Stretch LXC, install Yunohost inside and save
|
||||||
|
the result as `ynh-dev-base` which can then be used to create your actual dev
|
||||||
|
LXC. (This base can then be used to recreate a fresh Yunohost LXC if you need to
|
||||||
|
destroy your work LXC)
|
||||||
|
|
||||||
After starting the LXC, you should be automatically SSH'ed inside. If you later disconnect from the LXC, you can go back in with `./ynh-dev ssh`
|
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) :
|
||||||
|
|
||||||
Later, you might want to destroy the LXC. You can do so with `./ynh-dev destroy`.
|
```
|
||||||
|
$ echo "root:1000000:65536" > /etc/subuid
|
||||||
|
$ echo "root:1000000:65536" > /etc/subgid
|
||||||
|
```
|
||||||
|
|
||||||
|
Then start your actual dev LXC using :
|
||||||
|
|
||||||
### 3. Developping on your host, and testing in the container
|
```bash
|
||||||
|
$ ./ynh-dev start
|
||||||
|
```
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
## 3. Development and container testing
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
For instance, after running
|
For instance, after running:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./ynh-dev use-git yunohost
|
$ ./ynh-dev use-git yunohost
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
***Note***: The `use-git` operation can't be reverted now. DON'T DO THIS IN PRODUCTION !
|
***Note***: The `use-git` operation can't be reverted now. Do **not** do this in production.
|
||||||
|
|
||||||
|
## 4. Testing the web interface
|
||||||
#### Testing the web interface
|
|
||||||
|
|
||||||
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`.
|
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`.
|
||||||
|
|
||||||
If you want to access to the interface using the domain name, you shall tweak your /etc/hosts and add a line such as:
|
If you want to access to the interface using the domain name, you shall tweak your `/etc/hosts` and add a line such as:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
111.222.333.444 yolo.test
|
111.222.333.444 yolo.test
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
## Advanced: using snapshots
|
||||||
|
|
||||||
#### Advanced : using snapshots
|
You can check `lxc snapshot --help` to learn how to manage lxc snapshots.
|
||||||
|
|
||||||
Vagrant is not well integrated with LXC snapshots. However, you may still use `lxc-snapshot` directly to manage snapshots.
|
## Alternative: Using Only Virtualbox
|
||||||
|
|
||||||
## Develop on a remote server
|
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.
|
||||||
|
|
||||||
Instead of running a LXC locally, you may choose (or need) to develop on a dev VPS. *Be aware that this is a dev tool : do NOT run this procedure on a production environment !*.
|
# Remote Development Environment
|
||||||
|
|
||||||
Since you do not need to manage LXC, the setup is somewhat "easier" :
|
Here is the development flow:
|
||||||
|
|
||||||
1. Setup your VPS and install YunoHost
|
1. Setup your VPS and install YunoHost
|
||||||
2. Setup ynh-dev and the development environnement
|
2. Setup `ynh-dev` and the development environment
|
||||||
3. Develop and test
|
3. Develop and test
|
||||||
|
|
||||||
### 1. Setup your VPS and install YunoHost
|
## 1. Setup your VPS and install YunoHost
|
||||||
|
|
||||||
Setup a VPS somewhere (e.g. Scaleway, Digital Ocean, ...) and install YunoHost following https://yunohost.org/#/install_manually
|
Setup a VPS somewhere (e.g. Scaleway, Digital Ocean, etc.) and install YunoHost following the [usual instructions](https://yunohost.org/#/install_manually).
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
### 2. Setup ynh-dev and the development environnement
|
## 2. Setup `ynh-dev` and the development environment
|
||||||
|
|
||||||
Deploy a `ynh-dev` folder at the root of the filesystem with :
|
Deploy a `ynh-dev` folder at the root of the filesystem with:
|
||||||
|
|
||||||
```
|
```
|
||||||
cd /
|
$ cd /
|
||||||
curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
|
$ curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
|
||||||
cd /ynh-dev
|
$ cd /ynh-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Develop and test
|
## 3. Develop and test
|
||||||
|
|
||||||
Inside the VPS, `./ynh-dev` can be used to link the git clones to actual the code being ran.
|
Inside the VPS, `./ynh-dev` can be used to link the git clones to actual the code being ran.
|
||||||
|
|
||||||
For instance, after running
|
For instance, after running:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./ynh-dev use-git yunohost
|
$ ./ynh-dev use-git yunohost
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
Any `yunohost` command will run from the code of the git clone.
|
||||||
|
|
||||||
## More info
|
The `use-git` action can be used for any package among `yunohost`, `yunohost-admin`, `moulinette` and `ssowat` with similar consequences.
|
||||||
|
|
||||||
* [yunohost.org/dev](https://yunohost.org/dev) not up-to-date.
|
# Further Resources
|
||||||
|
|
||||||
|
* [yunohost.org/dev](https://yunohost.org/dev)
|
||||||
|
|
36
Vagrantfile
vendored
36
Vagrantfile
vendored
|
@ -1,36 +0,0 @@
|
||||||
# -*- mode: ruby -*-
|
|
||||||
# vi: set ft=ruby :
|
|
||||||
|
|
||||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
|
||||||
VAGRANTFILE_API_VERSION = "2"
|
|
||||||
|
|
||||||
NETWORK = "10.0.3."
|
|
||||||
|
|
||||||
HOSTS = {
|
|
||||||
"ynh-dev" => ["83", "ynh-dev"],
|
|
||||||
"compta" => ["85", "ynh-dev"],
|
|
||||||
"ynh-dev-buster" => ["84", "ynh-dev-buster"],
|
|
||||||
}
|
|
||||||
|
|
||||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
||||||
|
|
||||||
# Force guest type, because YunoHost /etc/issue can't be tuned
|
|
||||||
config.vm.guest = :debian
|
|
||||||
|
|
||||||
HOSTS.each do | (name, cfg) |
|
|
||||||
ipaddr, version = cfg
|
|
||||||
|
|
||||||
config.vm.define name do |machine|
|
|
||||||
machine.vm.box = "yunohost/" + version
|
|
||||||
# Force guest type, because YunoHost /etc/issue can't be tuned
|
|
||||||
machine.vm.guest = :debian
|
|
||||||
|
|
||||||
machine.vm.provider "lxc" do |lxc|
|
|
||||||
config.vm.box_url = "https://build.yunohost.org/" + version + "-lxc.box"
|
|
||||||
config.vm.synced_folder ".", "/ynh-dev", id: "vagrant-root"
|
|
||||||
config.vm.network :private_network, ip: NETWORK + ipaddr, lxc__bridge_name: 'lxcbr0'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end # HOSTS-each
|
|
||||||
|
|
||||||
end
|
|
58
prebuild/Vagrantfile
vendored
58
prebuild/Vagrantfile
vendored
|
@ -1,58 +0,0 @@
|
||||||
# -*- mode: ruby -*-
|
|
||||||
# vi: set ft=ruby :
|
|
||||||
|
|
||||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
|
||||||
VAGRANTFILE_API_VERSION = "2"
|
|
||||||
|
|
||||||
$script = <<SCRIPT
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
|
||||||
|
|
||||||
# Configure guest hostname
|
|
||||||
sudo bash -c 'echo 127.0.1.1 yunohost.yunohost.org yunohost >> /etc/hosts'
|
|
||||||
sudo hostname yunohost.yunohost.org
|
|
||||||
sudo bash -c 'echo yunohost.yunohost.org > /etc/hostname'
|
|
||||||
|
|
||||||
# Define root password
|
|
||||||
echo -e "yunohost\nyunohost" | sudo passwd root
|
|
||||||
|
|
||||||
# Allow sudo removal (YunoHost use sudo-ldap)
|
|
||||||
export SUDO_FORCE_REMOVE=yes
|
|
||||||
|
|
||||||
# Upgrade guest (done in install script)
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get -y --force-yes upgrade
|
|
||||||
sudo apt-get -y --force-yes dist-upgrade
|
|
||||||
|
|
||||||
# Install YunoHost
|
|
||||||
wget https://raw.githubusercontent.com/YunoHost/install_script/stretch/install_yunohost -q -O /tmp/install_yunohost
|
|
||||||
sudo bash /tmp/install_yunohost -a -d unstable
|
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
sudo apt-get clean -y
|
|
||||||
SCRIPT
|
|
||||||
|
|
||||||
NETWORK = "10.0.3."
|
|
||||||
|
|
||||||
HOSTS = {
|
|
||||||
"ynh-dev" => ["83", "stretch64"],
|
|
||||||
"ynh-dev-buster" => ["84", "testing64"],
|
|
||||||
}
|
|
||||||
|
|
||||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
||||||
|
|
||||||
HOSTS.each do | (name, cfg) |
|
|
||||||
|
|
||||||
ipaddr, box = cfg
|
|
||||||
|
|
||||||
config.vm.define name do |machine|
|
|
||||||
machine.vm.box = "debian/" + box
|
|
||||||
machine.vm.provision "shell" do |s|
|
|
||||||
s.inline = $script
|
|
||||||
s.args = ""
|
|
||||||
end
|
|
||||||
machine.vm.provider "lxc" do |lxc|
|
|
||||||
machine.vm.network :private_network, ip: NETWORK + ipaddr, lxc__bridge_name: 'lxcbr0'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
171
ynh-dev
171
ynh-dev
|
@ -6,10 +6,10 @@ function show_usage() {
|
||||||
${BLUE}On the host, to manage the LXC${NORMAL}
|
${BLUE}On the host, to manage the LXC${NORMAL}
|
||||||
${BLUE}==============================${NORMAL}
|
${BLUE}==============================${NORMAL}
|
||||||
|
|
||||||
start [NAME] (Create and) starts a LXC (ynh-dev by default)
|
start [DIST] [NAME] (Create and) starts a LXC (DIST=buster and NAME=ynh-dev by default)
|
||||||
ssh [NAME] SSH into an already started LXC (ynh-dev by default)
|
attach [DIST] [NAME] Attach an already started LXC (DIST=buster and NAME=ynh-dev by default)
|
||||||
destroy [NAME] Destroy the ynh-dev LXC (ynh-dev by default)
|
destroy [DIST] [NAME] Destroy the ynh-dev LXC (DIST=buster and NAME=ynh-dev by default)
|
||||||
rebuild Rebuild a fresh, up-to-date box
|
rebuild [DIST] [NAME] Rebuild a fresh, up-to-date box (DIST=buster and NAME=ynh-dev by default)
|
||||||
|
|
||||||
${BLUE}Inside the dev instance${NORMAL}
|
${BLUE}Inside the dev instance${NORMAL}
|
||||||
${BLUE}=======================${NORMAL}
|
${BLUE}=======================${NORMAL}
|
||||||
|
@ -35,7 +35,7 @@ function main()
|
||||||
help|-h|--help) show_usage $ARGUMENTS ;;
|
help|-h|--help) show_usage $ARGUMENTS ;;
|
||||||
|
|
||||||
start|--start) start_ynhdev $ARGUMENTS ;;
|
start|--start) start_ynhdev $ARGUMENTS ;;
|
||||||
ssh|--ssh) ssh_ynhdev $ARGUMENTS ;;
|
attach|--attach) attach_ynhdev $ARGUMENTS ;;
|
||||||
destroy|--destroy) destroy_ynhdev $ARGUMENTS ;;
|
destroy|--destroy) destroy_ynhdev $ARGUMENTS ;;
|
||||||
rebuild|--rebuild) rebuild_ynhdev $ARGUMENTS ;;
|
rebuild|--rebuild) rebuild_ynhdev $ARGUMENTS ;;
|
||||||
|
|
||||||
|
@ -102,89 +102,105 @@ function create_sym_link() {
|
||||||
local DEST=$1
|
local DEST=$1
|
||||||
local LINK=$2
|
local LINK=$2
|
||||||
# Remove current sources if not a symlink
|
# Remove current sources if not a symlink
|
||||||
[ -L "$LINK" ] || sudo rm -rf $LINK
|
[ -L "$LINK" ] || rm -rf $LINK
|
||||||
# Symlink from Git repository
|
# Symlink from Git repository
|
||||||
sudo ln -sfn $DEST $LINK
|
ln -sfn $DEST $LINK
|
||||||
}
|
}
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
# Actions #
|
# Actions #
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
function check_lxc_setup()
|
function check_lxd_setup()
|
||||||
{
|
{
|
||||||
local LXC_VERSION=$(lxc-info --version)
|
# Check lxd is installed somehow
|
||||||
|
[[ -e /snap/bin/lxd ]] || which lxd &>/dev/null \
|
||||||
|
|| critical "You need to have LXD installed for ynh-dev to be usable from the host machine. Refer to the README to know how to install it."
|
||||||
|
|
||||||
[[ "${LXC_VERSION:0:1}" == 3 ]] \
|
# Check that we'll be able to use lxc/lxd using sudo (for which the PATH is defined in /etc/sudoers and probably doesn't include /snap/bin)
|
||||||
|| critical "You need at least version 3 of LXC otherwise the box won't work"
|
if [[ ! -e /usr/bin/lxc ]] && [[ ! -e /usr/bin/lxd ]]
|
||||||
|
then
|
||||||
|
[[ -e /usr/local/bin/lxc ]] && [[ -e /usr/local/bin/lxd ]] \
|
||||||
|
|| critical "You might want to add lxc and lxd inside /usr/local/bin so that there's no tricky PATH issue with sudo. If you installed lxd/lxc with snapd, this should do the trick: sudo ln -s /snap/bin/lxc /usr/local/bin/lxc && sudo ln -s /snap/bin/lxd /usr/local/bin/lxd"
|
||||||
|
fi
|
||||||
|
|
||||||
[[ $(systemctl is-active lxc-net) == "active" ]] \
|
ip a | grep -q lxdbr0 \
|
||||||
|| critical "Service lxc-net should be running ... You probably need to fix your lxc network conf before being able to use lxc's."
|
|| critical "There is no 'lxdbr0' interface... Did you ran 'lxd init' ?"
|
||||||
|
|
||||||
ip a | grep -q lxcbr0 \
|
|
||||||
|| critical "There is no 'lxcbr0' interface. You probably need to fix your lxc network conf before being able to use lxc's."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_ynhdev()
|
function start_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxc_setup
|
check_lxd_setup
|
||||||
|
|
||||||
local NAME=${1:-ynh-dev}
|
local DIST=${1:-buster}
|
||||||
local BOX_NAME="yunohost/ynh-dev"
|
local BOX=${2:-ynh-dev}-${DIST}
|
||||||
local BOX_URL="https://build.yunohost.org/yunohost-$BOX_NAME-lxc.box"
|
|
||||||
|
|
||||||
set -eu
|
if ! sudo lxc info $BOX &>/dev/null
|
||||||
# Download box if not available
|
then
|
||||||
#if ! vagrant box list | grep -qc $BOX_NAME ; then
|
sudo lxc image info $BOX-base &>/dev/null || critical "You should first build the base YunoHost LXC using ./ynh-dev rebuild"
|
||||||
# info "Vagrant box '$BOX_NAME' is missing. Trying to download it"
|
set -eu
|
||||||
# vagrant box add $BOX_NAME $BOX_URL
|
set -x
|
||||||
#fi
|
sudo lxc launch $BOX-base $BOX
|
||||||
|
sudo lxc config set $BOX security.privileged true
|
||||||
|
sudo lxc config set $BOX security.nesting true # Need this for apparmor for some reason
|
||||||
|
sudo lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$(readlink -f $(pwd))"
|
||||||
|
set +x
|
||||||
|
info "Now attaching to the container"
|
||||||
|
else
|
||||||
|
info "Attaching to existing container"
|
||||||
|
fi
|
||||||
|
|
||||||
# Run VM
|
attach_ynhdev $BOX
|
||||||
vagrant up $NAME
|
|
||||||
|
|
||||||
# Log into the VM
|
|
||||||
ssh_ynhdev $NAME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ssh_ynhdev()
|
function attach_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxc_setup
|
# We need those link for the yunohost-admin build to work without r/w
|
||||||
local NAME=${1:-ynh-dev}
|
# permission in the shared folder.
|
||||||
vagrant ssh $NAME -c "echo 'You are now inside the LXC !'; cd /ynh-dev; sudo su"
|
#
|
||||||
|
# The target folders (/var/cache/ynh-dev/...) are then created during the
|
||||||
|
# './ynh-dev use-git yunohost-admin'
|
||||||
|
if [[ ! -L ./yunohost-admin/src/dist ]]
|
||||||
|
then
|
||||||
|
ln -s /var/cache/ynh-dev/yunohost-admin/node_modules ./yunohost-admin/src/
|
||||||
|
ln -s /var/cache/ynh-dev/yunohost-admin/dist ./yunohost-admin/src/
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_lxd_setup
|
||||||
|
local BOX=${1:-ynh-dev-buster}
|
||||||
|
sudo lxc start $BOX 2>/dev/null || true
|
||||||
|
sudo lxc exec $BOX --cwd /ynh-dev -- /bin/bash
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroy_ynhdev()
|
function destroy_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxc_setup
|
check_lxd_setup
|
||||||
local NAME=${1:-ynh-dev}
|
local DIST=${1:-buster}
|
||||||
vagrant destroy $NAME
|
local BOX=${2:-ynh-dev}-${DIST}
|
||||||
|
sudo lxc stop $BOX
|
||||||
|
sudo lxc delete $BOX
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuild_ynhdev()
|
function rebuild_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxc_setup
|
check_lxd_setup
|
||||||
|
|
||||||
local BOX="ynh-dev"
|
local DIST=${1:-buster}
|
||||||
|
local BOX=${2:-ynh-dev}-${DIST}
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
cd prebuild
|
sudo lxc info $BOX-rebuild >/dev/null && sudo lxc delete $BOX-rebuild --force
|
||||||
|
sudo lxc launch images:debian/$DIST/amd64 $BOX-rebuild
|
||||||
# Create box
|
sudo lxc config set $BOX-rebuild security.privileged true
|
||||||
vagrant up $BOX --provider=lxc --provision || critical "Could not create the box ?"
|
sudo lxc config set $BOX-rebuild security.nesting true # Need this for apparmor for some reason
|
||||||
|
sudo lxc restart $BOX-rebuild
|
||||||
# Package box
|
sleep 5
|
||||||
rm -f /tmp/ynh-dev.box
|
sudo lxc exec $BOX-rebuild -- apt install curl -y
|
||||||
vagrant package $BOX --output /tmp/$BOX.box || critical "Could not package package the box ?"
|
INSTALL_SCRIPT="https://install.yunohost.org"
|
||||||
|
sudo lxc exec $BOX-rebuild -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d unstable"
|
||||||
# Destroy current box
|
sudo lxc stop $BOX-rebuild
|
||||||
vagrant destroy $BOX
|
sudo lxc publish $BOX-rebuild --alias $BOX-base
|
||||||
|
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
# User message, and exit
|
|
||||||
info "The Vagrant box was packaged to /tmp/$BOX.box"
|
|
||||||
info "You might want to run : vagrant box add 'yunohost/ynh-dev' /tmp/$BOX.box --force"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_vm_ip()
|
function show_vm_ip()
|
||||||
|
@ -248,31 +264,40 @@ function use_git()
|
||||||
getent passwd ynhdev > /dev/null
|
getent passwd ynhdev > /dev/null
|
||||||
if [ $? -eq 2 ]; then
|
if [ $? -eq 2 ]; then
|
||||||
useradd ynhdev
|
useradd ynhdev
|
||||||
chown -R ynhdev: /ynh-dev/yunohost-admin
|
fi
|
||||||
|
|
||||||
|
mkdir -p /var/cache/ynh-dev/yunohost-admin/
|
||||||
|
mkdir -p /var/cache/ynh-dev/yunohost-admin/dist
|
||||||
|
chown -R ynhdev /var/cache/ynh-dev/yunohost-admin/
|
||||||
|
create_sym_link "/ynh-dev/yunohost-admin/src/package.json" "/var/cache/ynh-dev/yunohost-admin/package.json"
|
||||||
|
create_sym_link "/ynh-dev/yunohost-admin/src/package-lock.json" "/var/cache/ynh-dev/yunohost-admin/package-lock.json"
|
||||||
|
create_sym_link "/ynh-dev/yunohost-admin/src" "/usr/share/yunohost/admin"
|
||||||
|
|
||||||
|
if [ ! -e /ynh-dev/yunohost-admin/src/dist ]
|
||||||
|
then
|
||||||
|
echo "If npm install fails to create the dist and node_modules folder, maybe you need to run the following *in the host!* : "
|
||||||
|
echo " "
|
||||||
|
echo "cd /your/dev/env/yunohost-admin/src/"
|
||||||
|
echo "ln -s /var/cache/ynh-dev/yunohost-admin/dist ./dist"
|
||||||
|
echo "ln -s /var/cache/ynh-dev/yunohost-admin/node_modules ./node_modules"
|
||||||
|
echo " "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install npm dependencies if needed
|
# Install npm dependencies if needed
|
||||||
which gulp > /dev/null
|
cd /var/cache/ynh-dev/yunohost-admin/
|
||||||
if [ $? -eq 1 ]
|
if [ ! -e node_modules/gulp/bin/gulp.js ]
|
||||||
then
|
then
|
||||||
info "Installing dependencies to develop in yunohost-admin ..."
|
info "Installing dependencies to develop in yunohost-admin ..."
|
||||||
|
apt install nodejs npm -y
|
||||||
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
|
npm install -g npm@latest
|
||||||
sudo apt install nodejs
|
|
||||||
|
|
||||||
cd /ynh-dev/yunohost-admin/src
|
|
||||||
sudo npm install --no-bin-links
|
|
||||||
sudo npm install -g bower
|
|
||||||
sudo npm install -g gulp
|
|
||||||
fi
|
fi
|
||||||
cd /ynh-dev/yunohost-admin/src
|
|
||||||
sudo su -c "bower install" ynhdev
|
|
||||||
sudo su -c "gulp build --dev" ynhdev
|
|
||||||
|
|
||||||
create_sym_link "/ynh-dev/yunohost-admin/src" "/usr/share/yunohost/admin"
|
npm ci --no-bin-links
|
||||||
|
|
||||||
success "Now using Git repository for yunohost-admin"
|
success "Now using Git repository for yunohost-admin"
|
||||||
|
|
||||||
|
cd /ynh-dev/yunohost-admin/src
|
||||||
|
su ynhdev -c "./node_modules/gulp/bin/gulp.js build --dev"
|
||||||
warn "-------------------------------------------------------- "
|
warn "-------------------------------------------------------- "
|
||||||
warn "Launching gulp ... "
|
warn "Launching gulp ... "
|
||||||
warn "NB : This command will keep running and watch for changes"
|
warn "NB : This command will keep running and watch for changes"
|
||||||
|
@ -280,7 +305,7 @@ function use_git()
|
||||||
warn "don't need to re-run npm yourself everytime you change "
|
warn "don't need to re-run npm yourself everytime you change "
|
||||||
warn "something ! "
|
warn "something ! "
|
||||||
warn "-------------------------------------------------------- "
|
warn "-------------------------------------------------------- "
|
||||||
sudo su -c "gulp watch --dev" ynhdev
|
su ynhdev -c "./node_modules/gulp/bin/gulp.js watch --dev"
|
||||||
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -303,7 +328,7 @@ function run_tests()
|
||||||
if ! type "pytest" > /dev/null 2>&1; then
|
if ! type "pytest" > /dev/null 2>&1; then
|
||||||
info "> Installing pytest ..."
|
info "> Installing pytest ..."
|
||||||
apt-get install python-pip -y
|
apt-get install python-pip -y
|
||||||
pip2 install pytest
|
pip2 install pytest pytest-sugar
|
||||||
fi
|
fi
|
||||||
for DEP in "pytest-mock requests-mock mock"
|
for DEP in "pytest-mock requests-mock mock"
|
||||||
do
|
do
|
||||||
|
|
Loading…
Reference in a new issue