Moodle unattended upgrades inside docker

Moodle unattended upgrades inside docker

by Juan Daniel Burró Aláez -
Number of replies: 8

We're going to deploy dozens of small  Moodles and we would like to automate the process of upgrades. Each Moodle will go in a docker container, running all in the same host (but increasing hosts & moodle containers).

It's going to be a long post so I'll number my issues so you can answer me the ones you know. Feel free to "break my rules if needed". Thanks in advanced, its a hard work on my part, so any help is really welcome. I hardly have Moodle experience so  I can miss some important points, so any suggestion is more than welcome.

First of all, due to our infraestructure, we need to design a system upgrade with some specific requirements:
  • It should be completely unattended
  • Each Moodle could have different plugins that should persist (not defined in the dockerfile)
  • As efficient and prone error as possible (being unattended errors could not be seen).

My GitHub repo is https://github.com/juanda99/moodle-docker-production and I would like to integrate the solution as soon as possible (in case anyone finds it useful).

First I thought of just of just doing as Moodle docs say:

git pull && /usr/bin/php admin/cli/upgrade.php

But in a docker way:

docker-compose pull (get new docker image of Moodle)

docker-compose restart

As dockers containers are ephemeral, with the restart command all previous code would be lost (let say for example Moodle 3.7.0) and my container would have code of the new image (for example 3.8.2)

As I don’t want to loose my customization I would try to persist some folders using volumes:

• /path/to/moodle/theme/ - themes

• /path/to/moodle/mod/ - activity modules and resources

• /path/to/moodle/blocks/ - sidebar blocks

• /path/to/moodle/question/type/ - question types

• /path/to/moodle/course/format/ - course formats

• /path/to/moodle/admin/report/ - admin reports

So my first question is, (1)Are all of these the folders with some kind of customization? Do I miss any?

When I looked at that folders I realized they were not empty in a brand new Moodle installation.  So my method would have failed as  I should sync new 3.8.2 “original plugin folders” with “3.7.0 plugin folders + customization”. Do I make myself clear?

I’ve run into just one solution, run a script (docker entrypoint) to solve this sync issue and to execute the upgrade.php script.

I have 2 approaches in order to sync, using git or using a tar file. The good think is that as I should sync from the base directory (much simpler), I could persist /path/to/moodle and I won’t have to worry about volumes for all custom directories (which I’m not use which they are, and future changes in them).

So now it’s my 2nd question. (2) Which method should work the best? Any other solution?

Git aproach:

I could do git logic in my entrypoint

I don’t like this way because:

  • There would be be many network requests at the same time ( too many Moodle containers upgrading at the same time)
  • I should add git to my image (small issue)
  • I could get issues like git checkout / git pull not possible because you have unmerged files (I guess I could solved it with through git documetation, —force or whatever).

Tar/Zip approach:

 - Using a tar file. Currently my docker file work like this. I should untar the new version in Moodle document root.

I like this approach because:

  • The tar file is in the image so it’s only downloaded once for all containers (docker cache).
  • Its also smaller: 52.8M (tar.gz Moodle release file) vs 292M (Moodle git fetch specific branch).

My drawbacks with the tar approach is that my “new installation” would not be “clean” as I would have old files, not present in the new version that would not been overwritting. But... do the make any harm? Also doing things different to Moodle docs (untar instead of git pull).

Average of ratings: Useful (1)
In reply to Juan Daniel Burró Aláez

Re: Moodle unattended upgrades inside docker

by Juan Daniel Burró Aláez -
Finally we've decided to upgrade removing all the code and installating new one via tar. Plugins will alse be installed again and upgraded if needed. Plugin list and settings will be saved centrally.
Average of ratings: Useful (1)
In reply to Juan Daniel Burró Aláez

Ri: Re: Moodle unattended upgrades inside docker

by Corrado Nestola -

Really interesting.

I'm going to do the same for my company activities. Nice to browse your git!

let me study your solution and then try to contribute



Corrado


In reply to Corrado Nestola

Re: Ri: Re: Moodle unattended upgrades inside docker

by Juan Daniel Burró Aláez -

I'm not involved in this deploy anymore,  but related somehow.  It started on production 3 months ago and everything is going ok.

In reply to Juan Daniel Burró Aláez

Re: Ri: Re: Moodle unattended upgrades inside docker

by Shane Hughes -

A little late to the party, but did you ever figure out how to persist your plugins? that's the issue I am running into trying to deploy to kubernetes. I have the moodle code baked into the container and moodledata persists but I need to figure out how to keep customizations and plugins between container reloads. I noticed in your entrypoint you install the plugins on each boot but what about the config for said plugins? my case is the oidc plugin I need to keep the configuration for it, And will be the first of many config files needed to persist.

In reply to Shane Hughes

Re: Ri: Re: Moodle unattended upgrades inside docker

by Juan Daniel Burró Aláez -
We persist not only moodledata but also moodle code dir. Moodle arquitecture is not really good from a docker perspective. (same as Wikipedia and opposite to Wordpress).
Our scripts are executed just once, then we remove x permissions. However if we make an upgrade (Moodle version) we just remove all our Moodle code and make a fresh install (executing plugin scripts again), that's the reason why we have all plugins through scripts using moosh.
In reply to Juan Daniel Burró Aláez

Re: Ri: Re: Moodle unattended upgrades inside docker

by Shane Hughes -
Ahh see I was thinking of doing the same, then I thought about the upgrade path. Have you ben through one yet? How was it like? Did you loose anything between upgrades replacing the code like that?
In reply to Shane Hughes

Re: Ri: Re: Moodle unattended upgrades inside docker

by Juan Daniel Burró Aláez -
Just testing everything was ok or was fixed without important issues. What really matters is to automate with the script what you do with the admin backend, and to understand what each plugin is doing in the moodlecode dir. Something out of sync could be a problem so we tested it carefully. As we had many installations it was a time well spent.
In reply to Juan Daniel Burró Aláez

Re: Ri: Re: Moodle unattended upgrades inside docker

by Shane Hughes -
Thank you again for your insight, I will be busy today adding some scripts lol..