Flyspray

  • Status Unconfirmed
  • Percent Complete
    0%
  • Task Type Feature Request
  • Category Installer and Upgrader
  • Assigned To No-one
  • Operating System Linux
  • Severity Low
  • Priority Very Low
  • Reported Version 1.0-rc10
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: Flyspray
Opened by bbase - 11.08.2021

FS#2649 - Docker Container: is there a way to hook into the setup from CLI?

Docker11.08.2021bbase

Hi, in my free time of the last few days I begun developping a Docker container: https://github.com/blu-base/flyspray-docker. I derived it from a nextcloud docker container… For now, I limited my focus on an apache/debian buster container. I’d be happy to contribute the project to the official placeholder when it is ready.

Anyhow, in the entrypoint script, I use some environment variables to create the flyspray.conf.php from scratch. and would now need to populate the database. I understand i have to use the respective xml scheme as the setup/index.php does.


I am not experienced with php and database applications and would like to ask you for advice how to proceed efficiently.

Since the current setup is indented to be interactive in the browser, i would need to use a cli tool or a purposely-build php script to do the same task on the command line/on container startup. But this seems to me this would be code duplication and introduce more maintenance work.

  • Is it possible to hook into only some of the functions of the setup/index.php?
  • What could be the next best approach to populate the db on first start?
  • Would it be a viable solution in trying to further modularize the setup - allowing to run parts on cli, like nextcloud’s occ tool?
bbase commented on 11.08.2021 20:13

In parts this WIP is trying to add a respective feature for future releases.

Though the question would still be valid for the last couple of releases.

Project Manager

You might sent POST requests to trigger the setup install steps.

This are portions of logged setup steps with Selenium Firefox browser plugin.
Either use curl from shell or use PHP's curl_* functions.

curl 'http://10.0.0.5/fs1rc9/setup/index.php' 
  -H 'Host: 10.0.0.5' 
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0) Gecko/20100101 Firefox/56.0' 
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' 
  -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' 
  --compressed 
  -H 'Referer: http://10.0.0.5/fs1rc9/setup/index.php' 
  -H 'Content-Type: application/x-www-form-urlencoded' 
  -H 'Cookie: PHPSESSID=fmmmujesve89acbvegtlh44l822athbf' 
  -H 'Connection: keep-alive' 
  -H 'Upgrade-Insecure-Requests: 1' 
  --data 'admin_email=example%40example.com&admin_username=admin&admin_password=password&syntax_plugin=dokuwiki&reminder_daemon=1&db_type=mysqli&db_hostname=localhost&db_username=flyspray&db_password=flyspray&db_name=flyspray&db_prefix=flyspray_&action=complete'
 
curl 'http://10.0.0.5/fs1rc9/setup/cleanupaftersetup.php' 
  -H 'Host: 10.0.0.5' 
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0) Gecko/20100101 Firefox/56.0' 
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' 
  -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' 
  --compressed 
  -H 'Referer: http://10.0.0.5/fs1rc9/' 
  -H 'Cookie: flyspray=95og9p3ke4gdk5ga3nb6m61ns60gj6ln; PHPSESSID=fmmmujesve89acbvegtlh44l822athbf' 
  -H 'Connection: keep-alive' 
  -H 'Upgrade-Insecure-Requests: 1'

or

$baseurl='http://10.0.0.5/fs1rc9/';
$cookiejar='cookies.txt';
 
# index ->forwards to setup/
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_URL, $baseurl);
 
ob_start(); // prevent any output
$buf1=curl_exec($ch); // execute the curl command
echo "<pre>".$buf1;
 
ob_end_clean();  // stop preventing output
 
curl_close($ch);
unset($ch);
 
# press proceed button
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "action=database");
 
ob_start(); // prevent any output
curl_exec($ch); // execute the curl command
ob_end_clean(); // stop preventing output
 
curl_close($ch);
unset($ch);
 
# send database info
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_URL, $baseurl.'setup/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "db_hostname=localhost&db_type=mysqli&db_name=flyspray&db_username=flyspray&db_password=&db_prefix=fs_");
 
ob_start(); // prevent any output
$dbbuf=curl_exec($ch); // execute the curl command
echo "<pre>".$dbbuf;
ob_end_clean();  // stop preventing output
 
curl_close($ch);
unset($ch);
echo "\ndb info sent";
 
# configure adminaccount
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($ch, CURLOPT_URL, $baseurl.'setup/index.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "admin_email=example@example.com&admin_username=flyspray@example.com&admin_password=flyspray&syntax_plugin=dokuwiki&reminder_daemon=1");
 
ob_start();     // prevent any output
curl_exec($ch); // execute the curl command
ob_end_clean(); // stop preventing output
 
curl_close($ch);
unset($ch);
echo "\ndb admin info sent.\n";
 
 
 
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
curl_setopt($ch, CURLOPT_URL, $baseurl.'/myprofile');
 
$buf2 = curl_exec($ch);
 
curl_close($ch);

Do not forget to replace the file for Postgresql as the official 5.21 ADOdb postgres driver ist not working with the xmlschema03 stuff required for Flyspray.

Instead required to copy setup/upgrade/1.0/datadict-postgres.inc.php to vendor/adodb/adodb-php/datadict/datadict-postgres.inc.php until an official ADOdb releases fixes this.

bbase commented on 12.08.2021 07:12

Thanks for this thorough guide!
I'll likely implement this in the coming days.

bbase commented on 13.08.2021 11:42

Posting the information does work. I only had to split one of your suggestions. The action administration needs to be executed separately since the db populating happens in the previous stage.

curl http://localhost/setup/index.php \
        -H 'Content-Type: application/x-www-form-urlencoded' \
        --data-urlencode "db_type=$DB_TYPE" \
        --data-urlencode "db_hostname=$DB_HOST" \
        --data-urlencode "db_name=$DB_NAME" \
        --data-urlencode "db_username=$DB_USER" \
        --data-urlencode "db_password=$DB_PW" \
        --data-urlencode "db_prefix=$DB_PREFIX" \
        --data-urlencode "action=administration"
 
echo "finalize flyspray instance setup"
curl http://localhost/setup/index.php \
        -H 'Content-Type: application/x-www-form-urlencoded' \
        --data-urlencode "db_type=$DB_TYPE" \
        --data-urlencode "db_hostname=$DB_HOST" \
        --data-urlencode "db_name=$DB_NAME" \
        --data-urlencode "db_username=$DB_USER" \
        --data-urlencode "db_password=$DB_PW" \
        --data-urlencode "db_prefix=$DB_PREFIX" \
        --data-urlencode "admin_username=$ADMIN_USERNAME" \
        --data-urlencode "admin_password=$ADMIN_PASSWORD" \
        --data-urlencode "admin_email=$ADMIN_EMAIL" \
        --data-urlencode "admin_realname=$ADMIN_REALNAME" \
        --data-urlencode "admin_xmpp=$ADMIN_XMPP" \
        --data-urlencode "syntax_plugin=$SYNTAX_PLUGIN" \
        --data-urlencode "reminder_daemon=$REMINDER_DAEMON" \
        --data-urlencode "action=complete" \
 
curl http://localhost/setup/cleanupaftersetup.ph

There is on conceptional problem, though. The apache server in the respective docker container is started in the very end of the entrypoint script. It means, i cannot curl the web root before that… I'll need to figure out a way to maybe temporarily start the apache server with the proper settings…

Project Manager

Well, it was just snippets of an experiment I made 2 years ago. So my posted code was more to get an idea of one way how it could be done, not meaning it is the best way to do to automate setup.

I stick to vagrant boxes for testing, mostly using Debian and OpenSUSE boxes.

bbase commented on 13.08.2021 13:27

I didn't mean to sound like complaining. The previous post was meant to be an information on what i learned.

I found the dangling repo on the flyspray docker and thought, this might be something i am able to contribute.

Project Manager

All fine.

Yea, I created placeholder https://github.com/Flyspray/flyspray-docker

But I am not familiar with Docker and can only help on database or PHP topics.

bbase commented on 25.08.2021 23:05

It took a bit longer than anticipated to find time.
Anyhow, I have commited likely functional tool set to initialize non-interactively.

For reference, the curl commands in the previous comment needed to be extended to catch and submit the php session cookie.

In order to run the curl commands after the apache process has been initialized, i had to do a somewhat ugly process fork in the entrypoint script (the startup script for the docker container). Lacking an idea for an elegant way to wait for the db container to start up, i inserted a sleeping step as well…

Nevertheless, the default setup seems to be initialing satisfyingly now. https://github.com/blu-base/flyspray-docker

More testing is likely needed for edge cases and implement some automatic upgrade paths.

Project Manager

@bbase FS#2652 Maybe related and you can verify that?

I tried

docker build https://raw.githubusercontent.com/blu-base/flyspray-docker/main/1.0-rc10/apache/Dockerfile

inside a vagrant opensuse box, but it ended like this:

  - Installing guzzle/guzzle (v3.9.3): Extracting archive
  - Installing league/oauth2-client (0.12.1): Extracting archive
  - Installing swiftmailer/swiftmailer (v5.4.12): Extracting archive
    0 [>---------------------------]    0 [>---------------------------]
9 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Generating autoload files
> rm -rf vendor/dapphp/securimage/captcha.html vendor/dapphp/securimage/example_form.php vendor/dapphp/securimage/example_form.ajax.php vendor/dapphp/securimage/securimage_play.swf vendor/dapphp/securimage/examples/
> rm -rf vendor/dapphp/securimage/audio/*
> rm -rf vendor/dapphp/securimage/backgrounds/*
> echo '<?php return array("session_name"=>"flyspray"); ?>' > vendor/dapphp/securimage/config.inc.php
Removing intermediate container 562b505fc574
 ---> 7e828f48a340
Step 13/15 : COPY *.sh upgrade.exclude /
COPY failed: file not found in build context or excluded by .dockerignore: stat upgrade.exclude: file does not exist

As I am not using or familiar with Docker, what is the proper way to build/run it?

bbase commented on 27.08.2021 19:17

The Dockerfile needs the other files in the same directory. With getting only the Dockerfile it will not be possible to include the required scripts into the docker image. It is simpler this way than 'hard-coding' to curl a remote address instead.

You either download the whole directory first.

Or otherwise download the Dockerfile, entrypoint.sh, cron.sh, and upgrade.exclude into the same directory (the latter doesn't do much yet). Then run the following from that directory.

docker build .

Loading...

Available keyboard shortcuts

Tasklist

Task Details

Task Editing