givanz / Vvveb

Powerful and easy to use cms to build websites, blogs or ecommerce stores.
https://www.vvveb.com
GNU Affero General Public License v3.0
390 stars 82 forks source link

Persistent storage volumes #112

Open PencilShavings opened 7 months ago

PencilShavings commented 7 months ago

What folders should be mapped for persistent storage? In the docs “Install using docker” it just says docker run -p 8080:80 vvveb/vvvebcms:latest.

givanz commented 7 months ago

The folder that needs mapping is the apache htdocs folder /var/www/html

sudo docker volume create vvveb-volume
sudo docker run -p 8080:80 --mount source=vvveb-volume,target=/var/www/html vvveb/vvvebcms 

Or with docker compose

services:
  frontend:
    image: vvveb/vvvebcms:latest
    volumes:
      - vvveb-volume:/var/www/html
volumes:
  vvveb-volume:
    external: true
PencilShavings commented 7 months ago

You have to mount the entire site? Is there not just a data/config folder that can be bound?

Is there a way to use bind mounts? I personalty don’t find named-volumes very tangible. Having the ability to place the content wherever on the system is a necessity.

givanz commented 7 months ago

You can bind /config and /public/media folders for persistent assets and config.

If you use SQLite then you can also mount the database folder storage/sqlite/.

sudo docker run -p 8080:80  \
--mount type=bind,source="$(pwd)"/config,target=/var/www/html/config  \
--mount type=bind,source="$(pwd)"/media,target=/var/www/html/public/media \
vvveb/vvvebcms 
PencilShavings commented 7 months ago

public/media/ & storage/sqlite/ seemed to have done part of the trick but mapping /var/www/html/config results in “Internal server error, please try again later.” with a bunch of other code. I am amusing because there are files in that directory that get removed when you mount a local directory to it.

Without it, every time I restart the container I get sent back to the initial setup process.

Error message if it’s useful:

Internal server error, please try again later. 
[Refresh page](http://localhost:8080/install//) 
Error
Error loading session driver 
File
/var/www/html/system/session.php on line 45 
Code
    public function __construct($driver, $expire = 3600) {
        $class = '\\Vvveb\\System\\Session\\' . $driver;

        if (class_exists($class)) {
            $options      = \Vvveb\config(APP . '.session', []);
            $this->driver = new $class($options);
        } else {
            throw new \Exception('Error loading session driver ' . $driver);     // <==
        }

        return $this->driver;
    }

    public function get($key) {
Trace
#0 /var/www/html/system/session.php(33): Vvveb\System\Session->__construct(NULL)
#1 /var/www/html/system/functions.php(318): Vvveb\System\Session::getInstance()
#2 /var/www/html/install/controller/index.php(49): Vvveb\session('language')
#3 /var/www/html/system/core/frontcontroller.php(190): Vvveb\Controller\Index->__construct()
#4 /var/www/html/system/core/frontcontroller.php(298): Vvveb\System\Core\FrontController::call('Vvveb\\Controlle...', 'index', '/var/www/html/i...')
#5 /var/www/html/system/core/frontcontroller.php(364): Vvveb\System\Core\FrontController::redirect('Index', 'index')
#6 /var/www/html/system/core/startup.php(366): Vvveb\System\Core\FrontController::dispatch()
#7 /var/www/html/index.php(138): Vvveb\System\Core\start()
#8 /var/www/html/install/index.php(51): include('/var/www/html/i...')
#9 /var/www/html/public/install/index.php(26): include('/var/www/html/i...')
#10 {main}
givanz commented 7 months ago

Docker does not copy the existing files into bind mounts, and because config/app.php is missing is throwing this error.

You need to connect to the container, download and unzip the cms files to copy the files to the empty bind mounts folders.

docker exec -it <mycontainer> bash
curl -Lo /tmp/vvveb.zip https://www.vvveb.com/download.php
unzip /tmp/vvveb.zip -d /var/www/html
mraf commented 4 months ago

Hi @givanz

building with docker compose from docker hub is great no isssues until the container is restarted. Installation starting again when new conatiner is deployed and wiping off the data from volume and database

services:
  vvveb:
    image: vvveb/vvvebcms:latest
    volumes:
      - vvveb-volume:/var/www/html

is there a way to skip installation again if persistent storage volume is there and have all data ?

givanz commented 4 months ago

Hi

If you are using mysql then in your volumes list must include the volume for mysql.

    volumes:
      - vvveb-volume:/var/www/vvveb/
      - db:/var/lib/mysql

I just tried with the example docker-compose.yaml https://hub.docker.com/repository/docker/vvveb/vvvebcms/general and installation is done only once and data persists after docker image is restarted.

services:
  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: vvveb
      MYSQL_DATABASE: vvveb
      MYSQL_USER: vvveb
      MYSQL_PASSWORD: vvveb
    volumes:
      - db:/var/lib/mysql
    networks:
      - internal

  php:
    image: vvveb/vvvebcms:php8.3-fpm-alpine
    environment:
      DB_HOST: db
      DB_DATABASE: vvveb
      DB_USER: vvveb
      DB_PASSWORD: vvveb
      DB_ENGINE: mysqli #sqlite,pgsql
    volumes:
      - vvveb-volume:/var/www/vvveb/
      - db:/var/lib/mysql
    ports:
      - "8080:80"
    links:
      - db:mysql
    depends_on:
      - db
    networks:
      - internal

volumes:
  vvveb-volume:
  db:

networks:
  internal:
    driver: bridge
mraf commented 4 months ago

Thanks!

While investigating the container, I noticed that my mount destination is set to /var/www/html, but new containers are mounted in /var/www/vvveb, so my storage was skipped and that is why I was getting the install screen every time after a reboot when a new container was created.

setting the volume to the path /var/www/vvveb solved the problem :)

btw I can now post on forum idea how to host vvveb in easy and cool way with docker

givanz commented 4 months ago

Thanks for feedback.

I didn't notice that the document root path was wrong, with docker-compose up it was still persistent even with the wrong path.

I changed document root to correct path.