Skip to content

Instantly share code, notes, and snippets.

@darookee
Last active February 4, 2018 20:01
Show Gist options
  • Save darookee/f1e490ffe95ff3369d7ef275f945bc1b to your computer and use it in GitHub Desktop.
Save darookee/f1e490ffe95ff3369d7ef275f945bc1b to your computer and use it in GitHub Desktop.
Convert Gitlab installation from MySQL to a docker-based installation using PostgresQL
  1. Create a backup of the source gitlab server with gitlab-rake gitlab:backup:create
  2. Create a seperate MySQL dump of the source database using mysqldump [...] <gitlab-database-name> > database.sql
  3. Create a new directory to store the mysql-dump and the docker-compose-mysql.yml; database.sql belongs into the subfolder 'mysql' (as it is set in the docker-compose.yml) ./ ./mysql/database.sql ./docker-compose-mysql.yml
  4. Optional: edit docker-compose-mysql.yml to use the correct database images, mysql should be the same as your source mysql (or mariadb) version, postgres should match the version used in your gitlab-docker-image
  5. Start the two containers using docker-compose -f docker-compose-mysql.yml up --build -d
  6. Start the gitlab container using docker-compose, adding the database related configration from docker-compose-gitlab.yml to your own configuration
  7. Link the two containers using docker network connect <name-of-gitlab-network> <name-of-pgsql-server>
  8. Set the corret IP address for the pgsql server in the docker-compose.yml of the gitlab container and rebuilt it
  • Wait a few seconds/minutes until the database migrations from the gitlab container are done
  1. Download or install 'pgloader' and basically follow the 'official' migration guide from here
  • Be sure to use the correct IP addresses for the two database containers, use the addresses that are in the same network
  • Your Database should now be copied to the postgres server
  1. docker-compose exec gitlab bash and create a new backup using gitlab-rake gitlab:backup:create
  2. Untar the db/database.sql.gz from the newly created backup
  3. Untar the backup from the old installation into a clean directory
  4. Replace the db/databse.sql.gz from the old backup with the one from the new backup
  5. tar this updated directory up and copy the resulting file to the backup folder of the gitlab container, make sure that it is called _gitlab_backup.tar
  6. Stop the gitlab container and the databse containers (you should not need them anymore)
  7. Edit the docker-compose-gitlab.yml and remove the postgres configuration you added previously
  8. Start the gitlab container, wait again until the configuration is done and the internal postgres server is prepared for gitlab
  9. docker-compose exec gitlab bash again and now use gitlab-rake gitlab:backup:restore BACKUP=<name-of-your-updated-backup-minus_gitlab_backup.tar>
  10. Follow the instructions and wait for the script to finish
  11. You should now have all your data back again
LOAD DATABASE
FROM mysql://root:123456@172.21.0.3/gitlabhq_production
INTO postgresql://postgres:123456@172.21.0.2/gitlabhq_production
WITH include no drop, truncate, disable triggers, create no tables,
create no indexes, preserve index names, no foreign keys,
data only
ALTER SCHEMA 'gitlabhq_production' RENAME TO 'public'
;
version: '2'
services:
gitlab:
image: gitlab/gitlab-ce:<same-gitlab-version-as-the-source>
restart: always
container_name: gitlab
environment:
GITLAB_SKIP_PG_UPGRADE: 1
GITLAB_OMNIBUS_CONFIG: |
...
postgresql['enable'] = false
gitlab_rails['db_adapter'] = 'postgresql'
gitlab_rails['encoding'] = 'utf8'
gitlab_rails['db_host'] = "172.18.0.2"
gitlab_rails['db_port'] = 5432
gitlab_rails['db_username'] = 'postgres'
gitlab_rails['db_password'] = '123456'
volumes:
...
version: '2'
services:
mysql:
image: mariadb:10.0
environment:
MYSQL_ROOT_PASSWORD: 123456
volumes:
- ./mysql/:/docker-entrypoint-initdb.d
command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
pgsql:
image: postgres:9.3
environment:
POSTGRES_PASSWORD: 123456
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment