Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a -v/--verbose flag to print debug output #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 8 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,89 +30,32 @@ The app is expected to contain a `tests.toml` file (see below) to tell package_c

## Usage

<!--STARTHELP-->

```text
> ./package_check.sh --help
Usage: package_check.sh [OPTION]... PACKAGE_TO_CHECK

-b, --branch=BRANCH Specify a branch to check.
-b, --branch=BRANCH Specify a branch to check.
-a, --arch=ARCH
-d, --dist=DIST
-y, --ynh-branch=BRANCH
-D, --dry-run Show a JSON representing which tests are going to be ran (meant for debugging)
-i, --interactive Wait for the user to continue before each remove
-e, --interactive-on-errors Wait for the user to continue on errors
-s, --force-stop Force the stop of running package_check
-r, --rebuild (Re)Build the base container
(N.B.: you're not supposed to use this option,
images are supposed to be fetch from
devbaseimgs.yunohost.org automatically)
-S, --storage-dir DIRECTORY Where to store temporary test files like yunohost backups
-v, --verbose Prints the complete debug log to screen
-h, --help Display this help
```

## Deploying package_check

First you need to install the system dependencies.

Package check is based on 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 which may list on port 53.

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
apt install git snapd lynx jq
sudo snap install core
sudo snap install lxd

# Adding lxc/lxd to /usr/local/bin to make sure we can use them easily even
# with sudo for which the PATH is defined in /etc/sudoers and probably doesn't
# include /snap/bin
sudo ln -s /snap/bin/lxc /usr/local/bin/lxc
sudo ln -s /snap/bin/lxd /usr/local/bin/lxd
```

NB. : you should **make sure that your user is in the `lxd` group** so that it's
able to run `lxc` commands without sudo... You can check this with the command
`groups` where you should see `lxd`. Otherwise, add your user to this group
(don't forget that you may need to reload your entire graphical session for this
to propagate (sigh))

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. Just pay
attention to :

- the storage backend driver. Possibly `zfs` is the best, but requires a kernel >= 5.x
and corresponding kernel module loaded. You can fallback to the `dir` driver.
- the size of the default storage it'll create (the default is 5G but you may
want 10G for heavy usage ?) (if you're using the 'dir' driver, this won't be asked)

```bash
lxd init
Pass YNHDEV_BACKEND=incus|lxd to use a specific LXD-compatible backend.
```

The base images for tests are centralized on `devbaseimgs.yunohost.org` and we'll download them from there to speed things up:

```bash
lxc remote add yunohost https://devbaseimgs.yunohost.org --public
```

(At the time this README is written, fingerprint is d9ae6e76c374e3c58c3c20a881cffe7435809adb3b222ec393805f5bd01bb522 )

Then you can install package check :

```
git clone https://github.com/YunoHost/package_check
cd package_check
```

Then test your packages :

```
./package_check.sh your_app_ynh
```
<!--ENDHELP-->

## You can start a container on a different architecture with some hacks

Expand Down
8 changes: 7 additions & 1 deletion lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ function log_small_title()

function log_debug()
{
echo "$1" >> /proc/self/fd/3
if [[ "$verbose_log" = "1" ]]; then
# Append to log file and print to screen
echo "${1}" | tee -a /proc/self/fd/3
else
# Only append to log file, don't print to screen
echo "$1" >> /proc/self/fd/3
fi
}

function log_info()
Expand Down
32 changes: 32 additions & 0 deletions lib/update_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env python3

import os
from pathlib import Path

BASEDIR = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + "/..")
README = Path(BASEDIR) / "README.md"
SCRIPT = Path(BASEDIR) / "package_check.sh"

with open(SCRIPT) as f:
content = f.read()
help = content.split("#STARTHELP")[1].split("#ENDHELP")[0]
# Remove first 2 lines
help = "\n".join(help.split("\n")[2:])
# Remove last 3 lines
help = "\n".join(help.split("\n")[:-3])

with open(README) as f:
content = f.read()
start = content.split("<!--STARTHELP-->")[0]
end = content.split("<!--ENDHELP-->")[1]

readme_content = start \
+ "<!--STARTHELP-->\n\n" \
+ "```text\n" \
+ "> ./package_check.sh --help\n" \
+ help \
+ "\n```\n\n<!--ENDHELP-->" \
+ end

with open(README, "w") as f:
f.write(readme_content)
17 changes: 15 additions & 2 deletions package_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ source "./lib/tests_coordination.sh"
source "./lib/build_base_lxc.sh"

print_help() {
#STARTHELP
cat << EOF
Usage: package_check.sh [OPTION]... PACKAGE_TO_CHECK

-b, --branch=BRANCH Specify a branch to check.
-b, --branch=BRANCH Specify a branch to check.
-a, --arch=ARCH
-d, --dist=DIST
-y, --ynh-branch=BRANCH
Expand All @@ -22,11 +23,13 @@ print_help() {
images are supposed to be fetch from
devbaseimgs.yunohost.org automatically)
-S, --storage-dir DIRECTORY Where to store temporary test files like yunohost backups
-v, --verbose Prints the complete debug log to screen
-h, --help Display this help

Pass YNHDEV_BACKEND=incus|lxd to use a specific LXD-compatible backend.

EOF
#ENDHELP
exit 0
}

Expand All @@ -46,6 +49,7 @@ interactive_on_errors=0
rebuild=0
force_stop=0
storage_dir="${YNH_PACKAGE_CHECK_STORAGE_DIR:-}"
verbose_log=0

function parse_args() {

Expand All @@ -65,6 +69,7 @@ function parse_args() {
arguments[$i]=${arguments[$i]//--rebuild/-r}
arguments[$i]=${arguments[$i]//--force-stop/-s}
arguments[$i]=${arguments[$i]//--storage-dir/-s}
arguments[$i]=${arguments[$i]//--verbose/-v}
arguments[$i]=${arguments[$i]//--help/-h}
getopts_built_arg+=("${arguments[$i]}")
done
Expand All @@ -80,7 +85,7 @@ function parse_args() {
# Initialize the index of getopts
OPTIND=1
# Parse with getopts only if the argument begin by -
getopts ":b:Diresh" parameter || true
getopts ":b:Direshv" parameter || true
case $parameter in
b)
# --branch=branch-name
Expand Down Expand Up @@ -117,6 +122,11 @@ function parse_args() {
storage_dir=$OPTARG
shift_value=2
;;
v)
# --verbose
verbose_log=1
shift_value=1
;;
h)
# --help
print_help
Expand Down Expand Up @@ -209,6 +219,9 @@ trap 'exit 2' TERM
# Main code
#==========================

# Enable debug log?
export verbose_log

assert_we_are_connected_to_the_internets
assert_we_have_all_dependencies

Expand Down