doc/packaging_apps.md

146 lines
6.3 KiB
Markdown
Raw Normal View History

2015-11-17 21:57:23 +01:00
# App packaging <img src="https://yunohost.org/images/yunohost_package.png" width=100/>
2013-11-27 13:08:12 +01:00
2015-06-18 20:00:03 +02:00
This document aimed to learn you how to package an application for YunoHost.
### Requirements
To package an application, here are the requirements:
* An account on a git server as [GitHub](https://github.com/) to publish the application;
2015-06-18 20:00:03 +02:00
* Control a minimum `git`, Shell and other programming stuffs;
* A testing [virtual machine or a distant server](/install_en) to package and test the package.
2013-11-27 13:08:12 +01:00
### Content
2014-11-04 09:39:30 +01:00
A YunoHost package is composed of:
2013-11-27 13:08:12 +01:00
2015-06-18 20:00:03 +02:00
* A `manifest.json` file
* A `scripts` directory, which contains five Shell scripts: `install`, `remove`, `upgrade`, `backup` and `restore`
* Optional directories, containing `sources` or `conf` files
* A `LICENSE` file containing the license of the package
* A presentation page of your package in a `README.md` file
2014-11-04 09:39:30 +01:00
2016-02-19 12:10:40 +01:00
<a class="btn btn-lg btn-default" href="https://github.com/YunoHost/example_ynh"> A basic package</a>
feel free to use it as a framework.
2013-11-27 13:08:12 +01:00
2016-01-26 17:33:28 +01:00
## Manifest
<a class="btn btn-lg btn-default" href="packaging_apps_manifest_en">Manifest</a>
2013-11-27 13:08:12 +01:00
## Scripts
2016-02-19 12:28:09 +01:00
<a class="btn btn-lg btn-default" href="packaging_apps_scripts_en">Scripts</a>
2013-11-27 13:08:12 +01:00
2013-11-27 13:32:06 +01:00
### Architecture and arguments
2014-01-01 16:28:01 +01:00
Since YunoHost has a unified architecture, you will be able to guess most of the settings you need. But if you need variable ones, like the domain or web path, you will have to ask the administrator at installation (see `arguments` section in the manifest above).
2013-11-27 13:08:12 +01:00
2016-01-26 20:25:32 +01:00
<a class="btn btn-lg btn-default" href="packaging_apps_arguments_management_en">Arguments management</a>
2013-11-27 13:08:12 +01:00
2016-01-30 19:46:54 +01:00
### Nginx configuration
<a class="btn btn-lg btn-default" href="packaging_apps_nginx_conf_en">Nginx configuration</a>
2013-12-12 18:11:03 +01:00
### Hooks
2014-01-01 16:28:01 +01:00
YunoHost provides a hook system, which is accessible via the packager's script callbacks in moulinette (CLI).
The scripts have to be placed in the `hooks` repository at the root of the YunoHost package, and must be named `priority-hook_name`, for example: `hooks/50-post_user_create` will be executed after each user creation.
2013-12-12 18:11:03 +01:00
2013-12-12 18:12:30 +01:00
**Note**: `priority` is optional, default is `50`.
2014-01-01 16:28:01 +01:00
Take a look at the [ownCloud package](https://github.com/Kloadut/owncloud_ynh) for a working example.
2013-12-12 18:11:03 +01:00
2013-11-27 13:32:06 +01:00
### Helpers
2014-02-22 16:03:43 +01:00
The CLI [moulinette](/moulinette) provides a few tools to make the packager's work easier:
2013-11-27 13:08:12 +01:00
2013-12-01 11:53:50 +01:00
<br>
```bash
sudo yunohost app checkport <port>
```
<blockquote>
2014-01-01 16:28:01 +01:00
This helper checks the port and returns an error if the port is already in use.
2013-12-01 11:53:50 +01:00
</blockquote>
<br>
2013-11-27 13:08:12 +01:00
```bash
sudo yunohost app setting <id> <key> [ -v <value> ]
```
<blockquote>
2013-11-27 15:11:39 +01:00
This is the most important helper of YunoHost. It allows you to store some settings for a specific app, in order to be either reused afterward or used for YunoHost configuration (**e.g.** for the SSO).
2013-11-27 13:08:12 +01:00
<br><br>
It sets the value if you append ```-v <value>```, and gets it otherwise.
<br><br>
** Some useful settings **<br><br>
```skipped_uris```<br><br>
Remove the protection on the uris list provided separated by commas.<br><br>
```protected_uris```<br><br>
Protects the uris list provided separated by commas. Only logged in users will have access.<br><br>
There are also `skipped_regex`, `protected_regex`, `unprotected_uris`, `unprotected_regex`.<br><br>
**Be careful** : you must run `yunohost app ssowatconf` to apply the effect. URIs will be converted into URLs and written to the file /etc/ssowat/conf.json.<br><br>
Example:<br>
```yunohost app setting myapp unprotected_urls -v "/"```<br>
```yunohost app ssowatconf```<br>
These commands will disable the SSO on the root of the aplication like domain.tld/myapp This is useful for public application.
2013-11-27 13:08:12 +01:00
</blockquote>
<br>
```bash
sudo yunohost app checkurl <domain><path> -a <id>
```
<blockquote>
2013-11-27 15:11:39 +01:00
This helper is useful for web apps and allows you to be sure that the web path is not taken by another app. If not, it "reserves" the path.
2013-11-27 13:08:12 +01:00
<br><br>
2015-06-18 20:00:03 +02:00
**Note**: do not prepend `http://` or `https://` to the `<domain><path>`.
2013-11-27 13:08:12 +01:00
</blockquote>
<br>
```bash
sudo yunohost app initdb <db_user> [ -p <db_pwd> ] [ -s <SQL_file> ]
```
<blockquote>
2014-01-01 16:28:01 +01:00
This helper creates a MySQL database. If you do not append a password, it generates one and returns it. If you append a SQL file, it initializes your database with the SQL statements inside.
2013-11-27 13:08:12 +01:00
</blockquote>
<br>
```bash
sudo yunohost app ssowatconf
```
<blockquote>
This helper reloads the SSO configuration. You have to call it at the end of the script when you are packaging a web app.
2013-11-27 13:29:05 +01:00
</blockquote>
2014-01-01 16:28:01 +01:00
### Test it!
In order to test your package, you can execute your script standalone as `admin` (do not forget to append required arguments):
2013-11-27 13:29:05 +01:00
```bash
su - admin -c "/bin/bash /path/to/my/script my_arg1 my_arg2"
```
2015-06-18 20:00:03 +02:00
Or you can use [moulinette](/moulinette_en):
2013-11-27 13:29:05 +01:00
```bash
yunohost app install /path/to/my/app/package
```
Note that it also works with a Git URL:
```bash
yunohost app install https://github.com/author/my_app_package.git
```
2015-08-10 18:46:45 +02:00
### Enhance package
You will find points to verify quality of your scripts:
* scripts should use `sudo cp -a ../sources/. $final_path` instead of `sudo cp -a ../sources/* $final_path`;
* install script must contain support in case of script errors to delete residuals files thanks to `set -e` and `trap`;
* install script should use command line method instead of curl call through web install form;
* install script should save install answers;
* application sources should be checked with a control sum (sha256, sha1 or md5) or a PGP signature;
* scripts had been tested on Debian Jessie as well as 32 bits, 64 bits and ARM architectures;
2015-08-10 18:46:45 +02:00
* backup and restore scripts are present and functional.
2015-06-18 20:00:03 +02:00
### Publish and ask for testing your application
2015-10-06 00:21:54 +02:00
* Publishing a [post on the Forum](https://forum.yunohost.org/) with the [`App integration` category](https://forum.yunohost.org/c/app-integration), to ask tests and returns on your application.
2015-06-18 20:00:03 +02:00
2015-12-03 11:56:56 +01:00
* Ask to add your application in the [app repository](https://github.com/YunoHost/apps) to be displayed in the [non-official apps list](https://yunohost.org/#/apps_in_progress_en). Precise his progress state: `notworking`, `inprogress`, or `working`.
2014-11-09 13:16:25 +01:00
2015-06-18 20:00:03 +02:00
### Officalization of an application
To become an official application, it must be enough tested, stable and should works on 64 bits, 32 bits et ARM processors architectures and on Debian Jessie. If you think thoses conditions are gather, ask for [official integration](https://github.com/YunoHost/apps) of your application.