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

Extension get disabled if container is recreated #81

Open
VincentDugard opened this issue May 5, 2021 · 12 comments
Open

Extension get disabled if container is recreated #81

VincentDugard opened this issue May 5, 2021 · 12 comments

Comments

@VincentDugard
Copy link

Hello, If the container is recreated (for example to toggle debug mode), all extension I added are disabled after restart. Any idea ?

@Magicalex
Copy link
Member

Ok, same problem

@xxxxxliil
Copy link
Contributor

Ok, same problem

I've come up with a solution that may completely refactor https://github.com/mondediefr/docker-flarum/blob/master/rootfs/usr/local/bin/startup#L69-L125 rows

@Magicalex
Copy link
Member

The reason of disabled extensions comes from here
flarum/framework#2629

@smecsia
Copy link

smecsia commented Jun 15, 2021

For anyone else looking for a workaround, I've crafted a script that re-enables extensions that must be enabled:

        <?php

        use Illuminate\Database\Capsule\Manager;

        require_once 'vendor/autoload.php';

        $config = include 'config.php';

        $flarumDbPassword = $config['database']['password'] ? " -p{$config['database']['password']}" : '';

        $db = new Manager();
        $db->addConnection($config['database'], 'flarum');

        // get supposed-to-be-enabled extensions
        $extList = collect(explode("\n", file_get_contents('extensions/list')))
        	->map(function($ext) {
                  return str_replace('/', '-', $ext);
        	})
        	->filter(function ($ext) {
                  return $ext != '';
        	});

        // get all currently enabled extensions and merge with supposed-to-be-enabled
        $res = collect(json_decode($db->getConnection('flarum')
            ->table('settings')
            ->where('key', 'extensions_enabled')
            ->first()->value))
            ->merge($extList);

        var_dump($res);

        // save to database
        $db->getConnection('flarum')
            ->table('settings')
            ->where('key', 'extensions_enabled')
            ->update(['value' => $res->values()->toJson(JSON_OBJECT_AS_ARRAY)]);

We run flarum in Kubernetes, and the above script has to be executed after preparation steps in /usr/local/bin/startup, so we mounted it to /flarum/app/enable-extensions.php and hackily modified startup script to run the enable using the following command for the container:

#...
      command:
        - /bin/sh
        - -c
        - |-
          apk add --update mysql-client bash;
          sed -i '/^exec su-exec.*/i php enable-extensions.php; php flarum migrate; php flarum assets:publish' /usr/local/bin/startup

          /usr/local/bin/startup
#...

I guess this could be contributed, but my PHP knowledge is not the best, so if anyone can improve it, feel free to raise a PR.

@PipecraftNet
Copy link

I solved this problem by adding volumes for vendor, composer.json and composer.lock.
After adding these volumes, the time to recreate the container has been reduced a lot.

 volumes:
       - /mnt/docker/flarum/assets:/flarum/app/public/assets
       - /mnt/docker/flarum/extensions:/flarum/app/extensions
       - /mnt/docker/flarum/storage/logs:/flarum/app/storage/logs
       - /mnt/docker/flarum/nginx:/etc/nginx/flarum
+      - /mnt/docker/flarum/vendor:/flarum/app/vendor
+      - /mnt/docker/flarum/composer.json:/flarum/app/composer.json
+      - /mnt/docker/flarum/composer.lock:/flarum/app/composer.lock

@Magicalex Magicalex pinned this issue Jan 27, 2022
@Marty
Copy link
Contributor

Marty commented Mar 2, 2022

Hi @PipecraftNet how exactly did you do this? Did you first start the container, copied the new three directories/files out of the container and mount them afterwards? I get errors when I mount these before the installation of flarum.

@Marty
Copy link
Contributor

Marty commented Mar 3, 2022

I played around with the possibility to move the files composer.* to a different directory to make this easier.
After the installation of flarum, set the COMPOSER env variable and move those files.
I moved them to /flarum/app/composer and mounted a volume there.

However, when I mount the vendor volume from the start, flarum can not get a connection to the database.
SQLSTATE[HY000] [2002] Connection refused

@oceanlvr
Copy link

oceanlvr commented Mar 19, 2022

However, when I mount the vendor volume from the start, flarum can not get a connection to the database.

Same problem, have you solved this?

@zzzhangqi
Copy link

zzzhangqi commented Apr 12, 2022

I modified dockerfile and startup,Mount the /flarum/app directory.I don't know much about php,It doesn't look very elegant,But it will solve problem.

https://github.com/zzzhangqi/docker-flarum/blob/master/Dockerfile#L60-L61
https://github.com/zzzhangqi/docker-flarum/blob/master/rootfs/usr/local/bin/startup#L3-L11

use my image

version: "3"

services:
  flarum:
    image: registry.cn-hangzhou.aliyuncs.com/zqqq/flarum:1.2.0
    container_name: flarum
    env_file:
      - /mnt/docker/flarum/flarum.env
    volumes:
      - /mnt/flarum:/flarum/app
      - /mnt/flarum/nginx:/etc/nginx/flarum
    ports:
      - 80:8888
    depends_on:
      - mariadb

  mariadb:
    image: mariadb:10.5
    container_name: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=xxxxxxxxxx
      - MYSQL_DATABASE=flarum
      - MYSQL_USER=flarum
      - MYSQL_PASSWORD=xxxxxxxxxx
    volumes:
      - /mnt/docker/mysql/db:/var/lib/mysql

@maikell
Copy link

maikell commented Apr 17, 2022

I solved this problem by adding volumes for vendor, composer.json and composer.lock. After adding these volumes, the time to recreate the container has been reduced a lot.

 volumes:
       - /mnt/docker/flarum/assets:/flarum/app/public/assets
       - /mnt/docker/flarum/extensions:/flarum/app/extensions
       - /mnt/docker/flarum/storage/logs:/flarum/app/storage/logs
       - /mnt/docker/flarum/nginx:/etc/nginx/flarum
+      - /mnt/docker/flarum/vendor:/flarum/app/vendor
+      - /mnt/docker/flarum/composer.json:/flarum/app/composer.json
+      - /mnt/docker/flarum/composer.lock:/flarum/app/composer.lock

First time you'll need to go through the installation procedure without mounting

  - /mnt/docker/flarum/vendor:/flarum/app/vendor
  - /mnt/docker/flarum/composer.json:/flarum/app/composer.json
  - /mnt/docker/flarum/composer.lock:/flarum/app/composer.lock

Then copy the content to your host, define the paths in your composer file and restart the container.

LoneDev6 added a commit to LoneDev6/docker-flarum that referenced this issue Dec 3, 2022
@LoneDev6
Copy link

LoneDev6 commented Dec 3, 2022

This is my working solution: LoneDev6@9d753d6

arthurtemple added a commit to arthurtemple/docker-flarum that referenced this issue Jan 23, 2023
This seems to solve issue mondediefr#81 as calling /flarum/app/flarum before extensions are installed will disable them, as per flarum/framework#2629
@cloudrack-ca
Copy link

For anyone else looking for a workaround, I've crafted a script that re-enables extensions that must be enabled:

        <?php

        use Illuminate\Database\Capsule\Manager;

        require_once 'vendor/autoload.php';

        $config = include 'config.php';

        $flarumDbPassword = $config['database']['password'] ? " -p{$config['database']['password']}" : '';

        $db = new Manager();
        $db->addConnection($config['database'], 'flarum');

        // get supposed-to-be-enabled extensions
        $extList = collect(explode("\n", file_get_contents('extensions/list')))
        	->map(function($ext) {
                  return str_replace('/', '-', $ext);
        	})
        	->filter(function ($ext) {
                  return $ext != '';
        	});

        // get all currently enabled extensions and merge with supposed-to-be-enabled
        $res = collect(json_decode($db->getConnection('flarum')
            ->table('settings')
            ->where('key', 'extensions_enabled')
            ->first()->value))
            ->merge($extList);

        var_dump($res);

        // save to database
        $db->getConnection('flarum')
            ->table('settings')
            ->where('key', 'extensions_enabled')
            ->update(['value' => $res->values()->toJson(JSON_OBJECT_AS_ARRAY)]);

We run flarum in Kubernetes, and the above script has to be executed after preparation steps in /usr/local/bin/startup, so we mounted it to /flarum/app/enable-extensions.php and hackily modified startup script to run the enable using the following command for the container:

#...
      command:
        - /bin/sh
        - -c
        - |-
          apk add --update mysql-client bash;
          sed -i '/^exec su-exec.*/i php enable-extensions.php; php flarum migrate; php flarum assets:publish' /usr/local/bin/startup

          /usr/local/bin/startup
#...

I guess this could be contributed, but my PHP knowledge is not the best, so if anyone can improve it, feel free to raise a PR.

i do have copilot access - might be able to help I'm hoping most of these issues will just get fixed on setup - tbh tho could just make a free flarum on https://flarum.cloud i.e https://freeflarum.com/ as well.

@Magicalex Magicalex unpinned this issue Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests