How to update Gitlab, running in Docker container, from 11.10 to 13.5

Tags: gitlab docker update

Categories: linux

I want to update Gitlab to the latest version because I need feature that exist on version 13.x. My installation is on 11.10.8 version of Gitlab, running on Docker container.
I try with standard way of updating:

  • pull newer Docker image
  • stop and delete old container
  • start new container with new image

Error on Postgresql database

When I run container, follow logs:

docker logs -f gitlab

Error was:

Recipe: gitlab::database_migrations
 * bash[migrate gitlab-rails database] action run
  [execute] rake aborted!
  PG::ConnectionBad: could not connect to server: No such file or directory
  Is the server running locally and accepting
  connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
------------------------------------
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
  Expected process to exit with [0], but received '1'

And database log (follow current file):

DETAIL:  The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 11.7.
FATAL:  database files are incompatible with server

Resolving the problem

On Gitlab site is document, Upgrade packaged PostgreSQL server, where is explained how to upgrade database. More info about PostgreSQL versions shipped with Gitlab.
Gitlab provides command, gitlab-ctl pg-upgrade, to update PostgrSQL server to a later version(if one is included in the package).
Before upgrading, be sure that:

  • You running Gitlab and is working
  • You have sufficient disk space for two copies of your database( du -sh /var/opt/gitlab/postgresql/data/ and df -h)
  • You create backup

Steps that perform gitlab-ctl pg-upgrade

  1. Checks to ensure the database is in a known good state.
  2. Checks if there’s enough free disk space and aborts otherwise. You can skip this by appending the –skip-disk-check flag.
  3. Shuts down the existing database, any unnecessary services, and enables the GitLab deploy page.
  4. Changes the symlinks in /opt/gitlab/embedded/bin/ for PostgreSQL to point to the newer version of the database.
  5. Creates a new directory containing a new, empty database with a locale matching the existing database.
  6. Uses the pg_upgrade tool to copy the data from the old database to the new database.
  7. Moves the old database out of the way.
  8. Moves the new database to the expected location.
  9. Calls sudo gitlab-ctl reconfigure to do the required configuration changes and starts the new database server.
  10. Starts the remaining services and removes the deploy page.
  11. If any errors are detected during this process, it reverts to the old version of the database.

After the upgrade is complete, verify that everything is working as expected.
After you have verified that your GitLab instance is running correctly, you can clean up the old database files:

gotanbl:~>sudo rm -rf /var/opt/gitlab/postgresql/data.<old_version>
gotanbl:~>sudo rm -f /var/opt/gitlab/postgresql-version.old

Upgrade from 11.10 to 11.11

I have Gitlab version 11.10.x and PotgreSQL 9.6. I need latest Docker image with version 11.11.x because that image contain Postgresql version 9.6.x and 10.x.
Pull the image from Docker hub:

gotanbl:~>docker pull gitlab/gitlab-ce:11.11.8-ce.0

Stop previous container, delete and run new container with pulled image. After that in container run:

gotanbl:~>docker exec -it gitlab bash
gitlab:~>gitlab-ctl pg_upgrade

If everything is successfull we have PostgreSQL server, version 10.x.

Upgrade from 11.11 to 12.8

Gitlab, version 12.8.x shipped with PostgreSQL 10.x and 11.x. So, pull Docker image 12.8.x from hub.

gotanbl:~>docker pull gitlab/gitlab-ce:12.8.10-ce.0

Repeat commands from previous upgrade, except database server upgrade. You must specify on which version you want to upgrade.

gitlab:~>gitlab-ctl pg_upgrade -V 11

If successfull finished, PostgreSQL server is on 11.x version.

Upgrade from 12.8 to 13.x

First step is to upgrade to 13.0.x version of Gitlab, because it’s mandatory step and it’s not possible upgrading to latest version of 13.x release.
So, steps are the same …

gotanbl:~>docker pull gitlab/gitlab-ce:13.0.14-ce.0

We have Gitlab 13.0.14 version!
Next release on which is possible to upgrade PostgreSQL server is Gitlab 13.3.x, shipped with 11.x and 12.x.
Pull Docker image of Gitlab 13.3.x.

gotanbl:~>docker pull gitlab/gitlab-ce:13.3.8-ce.0

Repeat steps and specify database version update to.

gitlab:~>gitlab-ctl pg_upgrade -V 12

If everything is successfull we have PostgreSQL server, version 12.x.

Upgrade to latest release

Latest Gitlab release is 13.5.1. If you want to update to that version, pull that image from Docker hub.

gotanbl:~>docker pull gitlab/gitlab-ce:13.5.1-ce.0

Stop, remove and start container with new image and you have up and running latest version og Gitlab!