We have our project running on different servers using the provided cockpit Docker image. Now on all these servers, we need the same data-structure in cockpit (currently about 2 singletons and 2 collections).
Is it possible to add the data-scheme somehow to the Docker image, so that we don’t have to setup cockpit every single time?
@tommueller, @gnagnu Can you explain your use cases with some more details, please? Do you need only the structure (/storage/collections/*.php and /storage/singletons/*.php) or also some default data in the database? Data might need some importing scripts…
Some possible solutions:
You could create your own Docker image with the existing files and use that instead. Something like this:
The use case is, that we are providing a white-label software, that can be filled with content provided by cockpit. So for every new customer, we set up a new server, and run our software there, including cockpit, which runs within docker.
Now to net have to setup the singletons and collections with all the fields every time by hand, it would be nice to have a way to already include this into the docker image. Your first suggestions seems like it could work.
I thought that cockpit was using sqllite?! But collections and singleton schemas are stored in php files? Is there documentation about this somewhere?
I’ve been working on this finally now, but haven’t really found a good solution.
My first try was to extend the cockpit Docker image and copy the files into it. This does not work, because I have to use volumes and the volumes override any possible content in the folders.
What I am trying now is to have the files in the repo and mount them as volumes from there. This is also not ideal, as it then interacts with the files in my repo, so when switching branches etc. it might break. Also I don’t want to commit the content changes in cockpit into the repo obviously.
So the solution should probably be something like a shellscript, which copies the files to the volume-mount destination first and then starts cockpit with docker-compose, right?
Just wanted to give an update with my current solution. It is working fine, I am however not completely happy with it, as it seems a bit of dirty hack. So any suggestions / comments on how to get this a bit cleaner would be highly appreciated!
I myself wasn’t able to find a cleaner solution, mostly because the VOLUME is already defined in the cockpit docker image that I am extending from, so I cannot copy anything to the folder anymore.
So I basically copy the assets to a tmp-folder in the image and execute an init-script each time the container is started, in which I check if the files already exist or not:
#!/usr/bin/env sh
set -e
if [ ! -f /var/www/html/storage/collections/static_content.collection.php ]; then
cp -R /tmp/initial-data/storage/* /var/www/html/storage
fi
chown -R www-data:www-data /var/www/html/storage