Merge pull request #43 from alexAubin/pr

Rewrite ynh-dev
This commit is contained in:
Alexandre Aubin 2018-11-04 21:34:00 +01:00 committed by GitHub
commit 480231e2c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 410 additions and 510 deletions

288
README.md
View file

@ -13,27 +13,21 @@ In particular, it allows :
* sharing the dev environnement your host the VM (so you can develop directly on your host) * 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 * finding the ip address of your yunohost vagrant vm
yhn-dev can be used : yhn-dev can be used either :
1. on your local machine with LXCs (you can peacefully develop independently of your internet connection)
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 ...) 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 ...)
## Develop on your local machine ## Develop on your local machine
Here is the development flow: Here is the development flow:
1. [first time] Setup ynh-dev and the development environnement 1. Setup ynh-dev and the development environnement
2. Create or run a yunohost vagrant instance 2. Manage YunoHost's dev LXCs
3. Upgrade, postinstall and deploy development version from repositories 3. Developping on your host, and testing in the container
4. Develop on your host
5. Test via the CLI or webadmin
6. Suspend or kill your vm
### 1. [first time] Setup ynh-dev and the development environnement ### 1. Setup ynh-dev and the development environnement
These operation need to be done on the host machine. First you need to install the dependencies. ynh-dev essentially requires git, vagrant, and an LXC ecosystem.
#### Install 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: 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:
@ -43,124 +37,67 @@ Please consider using the [latest Vagrant version from their website](https://ww
sudo apt-get install vagrant virtualbox git sudo apt-get install vagrant virtualbox git
``` ```
- Fedora The following commands should work on Linux Mint 19 (and possibly on any Debian Stretch?) :
```bash ```bash
sudo dnf install vagrant git apt update
apt install git vagrant lxc-templates lxctl lxc cgroup-lite redir bridge-utils libc6 debootstrap
vagrant plugin install vagrant-lxc
echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" | sudo tee -a /etc/fstab
sudo mount /sys/fs/cgroup
lxc-checkconfig
echo "veth" | sudo tee -a /etc/modules
``` ```
[Install Virtualbox 5.1.x](http://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-rhel) 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
- Archlinux, Manjaro Then, go into your favorite development folder and deploy ynh-dev with :
```bash ```bash
sudo pacman -S vagrant virtualbox git curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
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
``` ```
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.
#### Install ynh-dev ### 2. Learn how to manage YunoHost's dev LXCs
Clone the ynh-dev repo : 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 :
```bash ```bash
git clone https://github.com/YunoHost/ynh-dev ./ynh-dev start
cd ynh-dev
``` ```
#### Create the environment 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 command create a clone of all Yunohost's main git repositories in `./`. 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`
Later, you might want to destroy the LXC. You can do so with `./ynh-dev destroy`.
### 3. Developping on your host, and testing in the container
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.
For instance, after running
```bash ```bash
./ynh-dev create-env ./ ./ynh-dev use-git yunohost
``` ```
### 2. Create or run a yunohost vagrant instance 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.
This command is a helper to run a Vagrant virtual machine in the right place with YunoHost pre-installed. 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.
```bash
./ynh-dev run yolo.test stretch-unstable
```
The `run` command takes 2 arguments: domain and YunoHost version.
After running the container, you'll be automatically logged inside a new yunohost VM or inside the previous suspended VM.
If you meet an error with `vboxsf` you might need to install the guest addons:
```bash
vagrant plugin install vagrant-vbguest
```
#### Shared folder between host and virtual machines
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.
### 3. Upgrade and configure your dev instance
According to what you intend to develop or test, you might need to upgrade, to postinstall.
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
#### Upgrade
If the container is not up to date, you can run the following command to update debian packages, including YunoHost ones.
```bash
/vagrant/ynh-dev upgrade
```
#### Use your git repositories in place of debian package
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 :
```bash
/vagrant/ynh-dev use-git PACKAGE
```
PACKAGE 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.
***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. DON'T DO THIS IN PRODUCTION !
#### Postinstall #### Testing the web interface
If you need a properly installed YunoHost to develop and test, you probably want to run the postinstall now: 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`.
```bash
(sudo) yunohost tools postinstall -d yolo.test
```
### 4. Develop on your host
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.
### 5. Test changes via the CLI or the web interface
#### Tests in CLI
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.
#### Tests the web interface
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 :
```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: If you want to access to the interface using the domain name, you shall tweak your /etc/hosts and add a line such as:
@ -168,143 +105,50 @@ If you want to access to the interface using the domain name, you shall tweak yo
111.222.333.444 yolo.test 111.222.333.444 yolo.test
``` ```
### 6. Suspend or kill your vm 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.
When you're finished or if you want to shut down your computer, you should kill or suspend the VM.
To kill the vm (this will destroy it), just do on your host:
```bash
cd /path/to/dev/env
vagrant destroy stretch-unstable
# or
./ynh-dev kill
```
To suspend the VM:
```bash
cd /path/to/dev/env
vagrant suspend stretch-unstable
```
Alternatively you can shut it down:
```bash
cd /path/to/dev/env
vagrant halt stretch-unstable
```
## 7. Other common operation
There are several other operations that you might want to perform directly
using Vagrant. All those operation needs to be done in the environment (where
the VagrantFile is located).
Show vagrant commands:
```bash
vagrant
```
See all running boxes:
```bash
vagrant status
```
Open a terminal on a running box:
```bash
vagrant ssh stretch-unstable
```
Start a box (only do that after the boxe as already been created by ynh-dev)
```bash
vagrant up stretch-unstable
```
## 8. Box snapshots for easy testing
You might want to play with vagrant snapshots to do saves of you box, test
things and restore it before the tests to have a clean box. Here how to do that:
```bash #### Advanced : using snapshots
cd /path/to/dev/env
# to make a snapshot Vagrant is not well integrated with LXC snapshots. However, you may still use `lxc-snapshot` directly to manage snapshots.
vagrant snapshot save stretch-unstable some_name_for_the_snapshot
# to restore it
vagrant snapshot restore stretch-unstable some_name_for_the_snapshot
```
Alternatively if you don't want to give a name to your snapshot you can do it this way:
```bash
cd /path/to/dev/env
# to make a snapshot
vagrant snapshot push stretch-unstable
# to restore it
vagrant snapshot pop stretch-unstable
```
And to list all snapshots:
```bash
vagrant snapshot list stretch-unstable
```
And there is also the `vagrant snapshot delete` command to remove a snapshot.
## Develop on a remote server ## Develop on a remote server
Firstly, you need to understand that it is a dev tool : you shouldn't run it on a production environment ! 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 !*.
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. Since you do not need to manage LXC, the setup is somewhat "easier" :
The development flow is quite similar to the first method: 1. Setup your VPS and install YunoHost
2. Setup ynh-dev and the development environnement
3. Develop and test
1. [first time] Setup ynh-dev and Setup a copy of each git repository ### 1. Setup your VPS and install YunoHost
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
### 1. Setup Setup a VPS somewhere (e.g. Scaleway, Digital Ocean, ...) and install YunoHost following https://yunohost.org/#/install_manually
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. 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.
```bash ### 2. Setup ynh-dev and the development environnement
sudo apt-get install git
git clone https://github.com/YunoHost/ynh-dev /vagrant/ Deploy a `ynh-dev` folder at the root of the filesystem with :
cd /vagrant/
```
cd /
curl https://raw.githubusercontent.com/yunohost/ynh-dev/master/deploy.sh | bash
cd /ynh-dev
``` ```
### 2. Upgrade, postinstall and use git repositories ### 3. Develop and test
Identical to 1.3, but take care to don't postinstall on a yunohost already postinstalled ! Inside the VPS, `./ynh-dev` can be used to link the git clones to actual the code being ran.
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) For instance, after running
### 3. Code on the instance directly
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.
### 4. Test
Identical to 1.5, but ynh-dev ip doesn't work. You should prefer this command to find your ip address:
```bash ```bash
ip addr ./ynh-dev use-git yunohost
``` ```
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. 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.
## More info ## More info

35
Vagrantfile vendored Executable file
View file

@ -0,0 +1,35 @@
# -*- 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"],
"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

20
deploy.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/bash
set -x
git clone https://github.com/yunohost/ynh-dev
cd ./ynh-dev
git clone https://github.com/YunoHost/moulinette
git clone https://github.com/YunoHost/yunohost
git clone https://github.com/YunoHost/yunohost-admin
git clone https://github.com/YunoHost/SSOwat ssowat
mkdir -p apps
set +x
echo " "
echo "---------------------------------------------------------------------"
echo "Done ! You should cd into 'ynh-dev' then check out './ynh-dev --help'"
echo "---------------------------------------------------------------------"
echo " "

58
prebuild/Vagrantfile vendored Normal file
View file

@ -0,0 +1,58 @@
# -*- 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

19
prebuild/prebuild.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
# Compute box name
BOX="ynh-dev"
# Create box
vagrant up $BOX
# Package box
vagrant package $BOX --output /tmp/$BOX.box
# Destroy current box
vagrant destroy $BOX
# User message, and exit
echo ""
echo "Your Vagrant box was packaged to /tmp/$BOX.box"
echo "You might want to run : vagrant box add 'yunohost/ynh-dev' /tmp/$BOX.box"
exit

500
ynh-dev
View file

@ -1,382 +1,306 @@
#!/bin/bash #!/bin/bash
usage() { function show_usage() {
cat <<EOF cat <<EOF
Usage :
On the host ${BLUE}On the host, to manage the LXC${NORMAL}
`basename $0` create-env PATH ${BLUE}==============================${NORMAL}
Create a dev environment into PATH
`basename $0` run DOMAIN [VERSION]
Run a vagrant or virtualbox vm
# `basename $0` kill
# Kill all vagrant
Inside the vm start [NAME] (Create and) starts a LXC (ynh-dev by default)
`basename $0` ip ssh [NAME] SSH into an already started LXC (ynh-dev by default)
Give the ip of the guest container destroy [NAME] Destroy the ynh-dev LXC (ynh-dev by default)
`basename $0` upgrade rebuild Rebuild a fresh, up-to-date box
Upgrade the container
`basename $0` use-git [PACKAGES [PACKAGES ...]]
Use Git repositories from dev environment path
`basename $0` test [PACKAGES [PACKAGES ...]]
Deploy, update and run tests for some packages
`basename $0` self-update
Update this script (`basename $0`)
PACKAGES : ${BLUE}Inside the dev instance${NORMAL}
moulinette ${BLUE}=======================${NORMAL}
ssowat
yunohost ip Give the ip of the guest container
yunohost-admin use-git [PKG] Use Git repositories from dev environment path
test [PKG] Deploy, update and run tests for some packages
VERSION
unstable
EOF EOF
} }
check_yunohost_vm() { function main()
if [ ! -d /etc/yunohost ] {
then local ACTION="$1"
echo "You need to install YunoHost first. Maybe you are not in a vm ?" local ARGUMENTS="${@:2}"
exit 100;
fi [ -z "$ACTION" ] && show_usage && exit 0
case "${ACTION}" in
help|-h|--help) show_usage $ARGUMENTS ;;
start|--start) start_ynhdev $ARGUMENTS ;;
ssh|--ssh) ssh_ynhdev $ARGUMENTS ;;
destroy|--destroy) destroy_ynhdev $ARGUMENTS ;;
rebuild|--rebuild) rebuild_ynhdev $ARGUMENTS ;;
ip|--ip) show_vm_ip $ARGUMENTS ;;
use-git|--use-git) use_git $ARGUMENTS ;;
test|--test) run_tests $ARGUMENTS ;;
*) critical "Unknown action ${ACTION}." ;;
esac
} }
create_sym_link() { ##################################################################
# Misc helpers #
##################################################################
readonly NORMAL=$(printf '\033[0m')
readonly BOLD=$(printf '\033[1m')
readonly faint=$(printf '\033[2m')
readonly UNDERLINE=$(printf '\033[4m')
readonly NEGATIVE=$(printf '\033[7m')
readonly RED=$(printf '\033[31m')
readonly GREEN=$(printf '\033[32m')
readonly ORANGE=$(printf '\033[33m')
readonly BLUE=$(printf '\033[34m')
readonly YELLOW=$(printf '\033[93m')
readonly WHITE=$(printf '\033[39m')
function success()
{
local msg=${1}
echo "[${BOLD}${GREEN} OK ${NORMAL}] ${msg}"
}
function info()
{
local msg=${1}
echo "[${BOLD}${BLUE}INFO${NORMAL}] ${msg}"
}
function warn()
{
local msg=${1}
echo "[${BOLD}${ORANGE}WARN${NORMAL}] ${msg}" 2>&1
}
function error()
{
local msg=${1}
echo "[${BOLD}${RED}FAIL${NORMAL}] ${msg}" 2>&1
}
function critical()
{
local msg=${1}
echo "[${BOLD}${RED}CRIT${NORMAL}] ${msg}" 2>&1
exit 1
}
function assert_inside_vm() {
[ -d /etc/yunohost ] || critical "There's no YunoHost in there. Are you sure that you are inside the container ?"
}
function create_sym_link() {
local DEST=$1
local LINK=$2
# Remove current sources if not a symlink # Remove current sources if not a symlink
if [ ! -L '$2' ]; then [ -L "$LINK" ] || sudo rm -rf $LINK
sudo rm -rf $2
fi
# Symlink from Git repository # Symlink from Git repository
sudo ln -sfn $1 $2 sudo ln -sfn $DEST $LINK
} }
packages=${@:2} ##################################################################
if [ "$#" = "1" ]; then # Actions #
packages=('moulinette' 'ssowat' 'yunohost' 'yunohost-admin') ##################################################################
fi
BASE_DIR=./ function start_ynhdev()
IP_BASE="192.168.33." {
local NAME=${1:-ynh-dev}
################## local BOX_NAME="yunohost/$NAME"
## Help message ## local BOX_URL="https://build.yunohost.org/yunohost-$BOX_NAME-lxc.box"
##################
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "help" ]; then
usage
######################################
## Create a development environment ##
######################################
elif [ "$1" = "create-env" ]; then
set -x
pwd=`pwd`
if [ ! "$2" ]
then
echo "I need a destination folder to create the dev environement"
exit 1
fi
[ -e "$2" ] || mkdir -p $2
cd $2
# Create apps & backup folder
mkdir -p apps
mkdir -p backup
# Get YunoHost packages
git clone -b unstable https://github.com/YunoHost/SSOwat ssowat
git clone -b unstable https://github.com/YunoHost/yunohost-admin yunohost-admin
git clone -b unstable https://github.com/YunoHost/yunohost yunohost
git clone -b unstable https://github.com/YunoHost/moulinette moulinette
# Get YunoHost Vagrantfile
git clone -b master https://github.com/YunoHost/Vagrantfile vagrant
ln -s vagrant/Vagrantfile Vagrantfile
# Get YunoHost dev tools
git clone -b master https://github.com/YunoHost/ynh-dev ynh-dev-tools
cp ynh-dev-tools/ynh-dev ynh-dev
#################################
## Run a vm and give a prompt ##
#################################
elif [ "$1" = "run" ]; then
if [[ $2 == *"-"* ]]; then
echo "ERROR: Vagrant virtual machine ($2) cannot contain any dash"
exit 2
fi
DOMAIN=$2
VERSION='stable'
if [ "$#" = "3" ]; then
VERSION=$3
fi
echo "Creating $DOMAIN virtual machine with YunoHost $VERSION version"
echo ""
# Get vagrant box info from version
if [ "$VERSION" = "unstable" ]; then
BOX_NAME="yunohost/jessie-unstable"
BOX_URL="https://build.yunohost.org/yunohost-jessie-unstable.box"
elif [ "$VERSION" = "stretch-unstable" ]; then
BOX_NAME="yunohost/stretch-unstable"
BOX_URL="https://build.yunohost.org/yunohost-stretch-unstable.box"
else
echo "ERROR: Incorrect version '$VERSION'. See '$(basename $0) --help' for usage."
exit 102
fi
set -eu
# Download box if not available # Download box if not available
if ! vagrant box list | grep -qc $BOX_NAME ; then #if ! vagrant box list | grep -qc $BOX_NAME ; then
echo "Vagrant box '$BOX_NAME' is missing. Trying to download it" # info "Vagrant box '$BOX_NAME' is missing. Trying to download it"
vagrant box add $BOX_NAME $BOX_URL --provider virtualbox # vagrant box add $BOX_NAME $BOX_URL
echo "" #fi
fi
# Deduce the vm name
VMNAME=${DOMAIN//./_}
# Add the vm vagrant config in Vagrantfile
vagrant status $VMNAME &> /dev/null || {
# Find an available ip
for i in `seq 2 254`;
do
grep "${IP_BASE//./\.}$i" Vagrantfile &> /dev/null || {
IP="${IP_BASE}$i"
break
}
done
# Update Vagrantfile
grep "### END AUTOMATIC YNH-DEV ###" ./Vagrantfile &> /dev/null || {
pushd ./vagrant &> /dev/null
git pull
popd &> /dev/null
rm ./Vagrantfile
ln -s vagrant/Vagrantfile Vagrantfile
}
# Adapt vagrantfile
perl -i -pe "s| (### END AUTOMATIC YNH-DEV ###)|\
config.vm.define \"${VMNAME}\" do \|${VMNAME}\| \
\n ${VMNAME}.vm.box = \"${BOX_NAME}\" \
\n ${VMNAME}.vm.network :private_network, ip: \"${IP}\" \
\n end \
\n \1|" ./Vagrantfile
}
# Run VM # Run VM
vagrant up $VMNAME --provider virtualbox vagrant up $NAME
# Warn user about hosts file
IP_LINE="[[:space:]]*${VMNAME}.vm.network[[:space:]]*:private_network,[[:space:]]*ip:[[:space:]]*\""
IP=$(grep "$IP_LINE" Vagrantfile | sed "s/${IP_LINE}//" | tr -d '"')
echo "/!\ Please add '$IP $DOMAIN' to your /etc/hosts file /!\\"
echo "sudo bash -c 'echo \"$IP $DOMAIN\" >> /etc/hosts'"
echo ""
# Log into the VM # Log into the VM
vagrant ssh $VMNAME -c "sudo -i" ssh_ynhdev $NAME
}
function ssh_ynhdev()
{
local NAME=${1:-ynh-dev}
vagrant ssh $NAME -c "echo 'You are now inside the LXC !'; cd /ynh-dev; sudo su"
}
##################### function destroy_ynhdev()
## Kill running VM ## {
##################### local NAME=${1:-ynh-dev}
elif [ "$1" = "kill" ]; then vagrant destroy $NAME
vagrant destroy }
function rebuild_ynhdev()
{
local BOX="ynh-dev"
####################### set -x
## Update current VM ## cd prebuild
#######################
elif [ "$1" = "upgrade" ]; then
check_yunohost_vm
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
# Create box
vagrant up $BOX
####################### # Package box
## Get current VM IP ## vagrant package $BOX --output /tmp/$BOX.box
#######################
elif [ "$1" = "ip" ]; then
check_yunohost_vm
# Print IP
ip=$(/bin/ip a | grep 'inet 192.168' | awk -F " " '{print $2}' | awk -F "/" '{print $1}')
echo "IP: $ip"
# Destroy current box
vagrant destroy $BOX
########################################### set +x
## Use Git version for YunoHost packages ##
###########################################
elif [ "$1" = "use-git" ]; then
check_yunohost_vm
VERSION=$2
for i in ${!packages[@]}; do # User message, and exit
case ${packages[i]} in 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"
}
function show_vm_ip()
{
assert_inside_vm
hostname --all-ip-addresses | tr ' ' '\n'
}
function use_git()
{
assert_inside_vm
local PACKAGES="$@"
for PACKAGE in "$PACKAGES";
do
case $PACKAGE in
ssowat) ssowat)
echo "Using Git repository for SSOwat" create_sym_link "/ynh-dev/ssowat" "/usr/share/ssowat"
create_sym_link "/vagrant/ssowat" "/usr/share/ssowat" success "Now using Git repository for SSOwat"
echo "↳ Don't forget to do 'sudo yunohost app ssowatconf' when hacking SSOwat"
echo ""
;; ;;
moulinette) moulinette)
create_sym_link "/vagrant/moulinette/locales" "/usr/share/moulinette/locale" create_sym_link "/ynh-dev/moulinette/locales" "/usr/share/moulinette/locale"
create_sym_link "/vagrant/moulinette/moulinette" "/usr/lib/python2.7/dist-packages/moulinette" create_sym_link "/ynh-dev/moulinette/moulinette" "/usr/lib/python2.7/dist-packages/moulinette"
echo "" success "Now using Git repository for Moulinette"
;; ;;
yunohost) yunohost)
echo "Using Git repository for yunohost"
# bin # bin
create_sym_link "/vagrant/yunohost/bin/yunohost" "/usr/bin/yunohost" create_sym_link "/ynh-dev/yunohost/bin/yunohost" "/usr/bin/yunohost"
create_sym_link "/vagrant/yunohost/bin/yunohost-api" "/usr/bin/yunohost-api" create_sym_link "/ynh-dev/yunohost/bin/yunohost-api" "/usr/bin/yunohost-api"
# data # data
create_sym_link "/vagrant/yunohost/data/bash-completion.d/yunohost" "/etc/bash_completion.d/yunohost" create_sym_link "/ynh-dev/yunohost/data/bash-completion.d/yunohost" "/etc/bash_completion.d/yunohost"
create_sym_link "/vagrant/yunohost/data/actionsmap/yunohost.yml" "/usr/share/moulinette/actionsmap/yunohost.yml" create_sym_link "/ynh-dev/yunohost/data/actionsmap/yunohost.yml" "/usr/share/moulinette/actionsmap/yunohost.yml"
create_sym_link "/vagrant/yunohost/data/hooks" "/usr/share/yunohost/hooks" create_sym_link "/ynh-dev/yunohost/data/hooks" "/usr/share/yunohost/hooks"
create_sym_link "/vagrant/yunohost/data/templates" "/usr/share/yunohost/templates" create_sym_link "/ynh-dev/yunohost/data/templates" "/usr/share/yunohost/templates"
create_sym_link "/vagrant/yunohost/data/helpers" "/usr/share/yunohost/helpers" create_sym_link "/ynh-dev/yunohost/data/helpers" "/usr/share/yunohost/helpers"
create_sym_link "/vagrant/yunohost/data/helpers.d" "/usr/share/yunohost/helpers.d" create_sym_link "/ynh-dev/yunohost/data/helpers.d" "/usr/share/yunohost/helpers.d"
create_sym_link "/vagrant/yunohost/data/other" "/usr/share/yunohost/yunohost-config/moulinette" create_sym_link "/ynh-dev/yunohost/data/other" "/usr/share/yunohost/yunohost-config/moulinette"
# debian # debian
create_sym_link "/vagrant/yunohost/debian/conf/pam/mkhomedir" "/usr/share/pam-configs/mkhomedir" create_sym_link "/ynh-dev/yunohost/debian/conf/pam/mkhomedir" "/usr/share/pam-configs/mkhomedir"
# lib # lib
create_sym_link "/vagrant/yunohost/lib/metronome/modules/ldap.lib.lua" "/usr/lib/metronome/modules/ldap.lib.lua" create_sym_link "/ynh-dev/yunohost/lib/metronome/modules/ldap.lib.lua" "/usr/lib/metronome/modules/ldap.lib.lua"
create_sym_link "/vagrant/yunohost/lib/metronome/modules/mod_auth_ldap2.lua" "/usr/lib/metronome/modules/mod_auth_ldap2.lua" create_sym_link "/ynh-dev/yunohost/lib/metronome/modules/mod_auth_ldap2.lua" "/usr/lib/metronome/modules/mod_auth_ldap2.lua"
create_sym_link "/vagrant/yunohost/lib/metronome/modules/mod_legacyauth.lua" "/usr/lib/metronome/modules/mod_legacyauth.lua" create_sym_link "/ynh-dev/yunohost/lib/metronome/modules/mod_legacyauth.lua" "/usr/lib/metronome/modules/mod_legacyauth.lua"
create_sym_link "/vagrant/yunohost/lib/metronome/modules/mod_storage_ldap.lua" "/usr/lib/metronome/modules/mod_storage_ldap.lua" create_sym_link "/ynh-dev/yunohost/lib/metronome/modules/mod_storage_ldap.lua" "/usr/lib/metronome/modules/mod_storage_ldap.lua"
create_sym_link "/vagrant/yunohost/lib/metronome/modules/vcard.lib.lua" "/usr/lib/metronome/modules/vcard.lib.lua" create_sym_link "/ynh-dev/yunohost/lib/metronome/modules/vcard.lib.lua" "/usr/lib/metronome/modules/vcard.lib.lua"
# src # src
create_sym_link "/vagrant/yunohost/src/yunohost" "/usr/lib/moulinette/yunohost" create_sym_link "/ynh-dev/yunohost/src/yunohost" "/usr/lib/moulinette/yunohost"
# locales # locales
create_sym_link "/vagrant/yunohost/locales" "/usr/lib/moulinette/yunohost/locales" create_sym_link "/ynh-dev/yunohost/locales" "/usr/lib/moulinette/yunohost/locales"
success "Now using Git repository for YunoHost"
echo ""
;; ;;
yunohost-admin) yunohost-admin)
# Trick to check vagrant user exists (for install on VPS..) getent passwd ynhdev > /dev/null
getent passwd vagrant > /dev/null
if [ $? -eq 2 ]; then if [ $? -eq 2 ]; then
useradd vagrant useradd ynhdev
chown -R vagrant: /vagrant/yunohost-admin chown -R ynhdev: /ynh-dev/yunohost-admin
fi fi
# Install npm dependencies if needed # Install npm dependencies if needed
which gulp > /dev/null which gulp > /dev/null
if [ $? -eq 1 ] if [ $? -eq 1 ]
then then
release=$(lsb_release -c | cut -d ":" -f 2 | sed 's/\s*//') info "Installing dependencies to develop in yunohost-admin ..."
if [ $release == "stretch" ] curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
then sudo apt install nodejs
# for watever reason npm is not in stretch anymore
# because why the fuck debian
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt install nodejs
else
sudo apt-get update --fix-missing
sudo apt-get -y install nodejs-legacy npm
fi
cd /vagrant/yunohost-admin/src cd /ynh-dev/yunohost-admin/src
sudo npm install sudo npm install
sudo npm install -g bower sudo npm install -g bower
sudo npm install -g gulp sudo npm install -g gulp
fi fi
cd /vagrant/yunohost-admin/src cd /ynh-dev/yunohost-admin/src
sudo su -c "bower install" vagrant sudo su -c "bower install" ynhdev
sudo su -c "gulp build --dev" vagrant sudo su -c "gulp build --dev" ynhdev
echo "Using Git repository for yunohost-admin" create_sym_link "/ynh-dev/yunohost-admin/src" "/usr/share/yunohost/admin"
create_sym_link "/vagrant/yunohost-admin/src" "/usr/share/yunohost/admin"
echo "--------------------------------------------------------" success "Now using Git repository for yunohost-admin"
echo "Launching gulp ... "
echo "NB : This command will keep running and watch for changes" warn "-------------------------------------------------------- "
echo " in the folder /vagrant/yunohost-admin/src, such that you" warn "Launching gulp ... "
echo "don't need to re-run npm yourself everytime you change" warn "NB : This command will keep running and watch for changes"
echo "something !" warn " in the folder /ynh-dev/yunohost-admin/src, such that you"
echo "--------------------------------------------------------" warn "don't need to re-run npm yourself everytime you change "
sudo su -c "gulp watch --dev" vagrant warn "something ! "
warn "-------------------------------------------------------- "
sudo su -c "gulp watch --dev" ynhdev
;; ;;
esac esac
done done
}
function run_tests()
elif [ "$1" = "test" ]; then {
check_yunohost_vm assert_inside_vm
VERSION=$2 local PACKAGES="$@"
for PACKAGE in "$PACKAGES";
for i in ${!packages[@]}; do do
case ${packages[i]} in case $PACKAGE in
yunohost) yunohost)
# Pytest and tests dependencies # Pytest and tests dependencies
if ! type "pytest" > /dev/null; then if ! type "pytest" > /dev/null; then
echo "=======================" info "> Installing pytest ..."
echo "> Installing pytest ..." apt-get install python-pip -y
echo "======================="
apt-get install python-pip
pip2 install pytest pip2 install pytest
fi fi
PIP_DEPENDENCIES="pytest-mock requests-mock mock" for DEP in "pytest-mock requests-mock mock"
for DEP in $PIP_DEPENDENCIES
do do
if [ -z "$(pip show $DEP)" ]; then if [ -z "$(pip show $DEP)" ]; then
echo "=======================" info "Installing $DEP with pip"
echo "Installing $DEP with pip"
echo "======================="
pip2 install $DEP pip2 install $DEP
fi fi
done done
# Apps for test # Apps for test
cd /vagrant/yunohost/src/yunohost/tests cd /ynh-dev/yunohost/src/yunohost/tests
if [ ! -d "apps" ]; then [ -d "apps" ] || git clone https://github.com/YunoHost/test_apps ./apps
git clone https://github.com/YunoHost/test_apps ./apps cd apps
else git pull > /dev/null 2>&1
cd apps
git pull > /dev/null 2>&1
fi
# Run tests # Run tests
echo "Running tests for YunoHost" echo "Running tests for YunoHost"
cd /vagrant/yunohost/ cd /ynh-dev/yunohost/
py.test tests py.test tests
cd /vagrant/yunohost/src/yunohost cd /ynh-dev/yunohost/src/yunohost
py.test tests py.test tests
;; ;;
esac esac
done done
}
main "$@"
elif [ "$1" = "self-update" ]; then
check_yunohost_vm
cd /vagrant/vagrant && git pull origin master
cd /vagrant/ynh-dev-tools && git pull origin master && cp ynh-dev ../ynh-dev
# Fallback to print usage
else
usage
exit 101
fi
exit 0;