Browse Source

Add guide for Gitlab migration to Cloudron

keep-around/eecd327ffbb287d519acac737c31ba1d26ad972b
Elias Hackradt 2 months ago
parent
commit
eecd327ffb
No known key found for this signature in database GPG Key ID: 32B038A64E6697B1
  1. 165
      knowledgebase/docs/apps/gitlab.md

165
knowledgebase/docs/apps/gitlab.md

@ -95,3 +95,168 @@ $ bundle exec rails c -e production # (takes about 10 sec to bring up rails term
There are various other settings GitLab supports via `gitlab.rb`. On Cloudron those are specified in `/app/data/gitlab.yml`.
The upstream docs are referring to the key style of `gitlab.rb` and the mapping of keys for the yml file are described [here](https://docs.gitlab.com/omnibus/settings/gitlab.yml.html).
## Migration to Cloudron
This guide aims to assist in migrating an already running Gitlab into the Gitlab Cloudron app.
If you have any problems please do not delay and seek help in the [Forum](https://forum.cloudron.io/category/25/gitlab).
This guide got written for a migration from a Gitlab installation via Omnibus.
!!! warning "Make sure both Gitlab instances are running the same version! Before continuing to the next step!"
The backup Rake task GitLab provides does not store your configuration files. The primary reason for this is that your database contains items including encrypted information for two-factor authentication and the CI/CD secure variables. Storing encrypted information in the same location as its key defeats the purpose of using encryption in the first place.
At the very minimum, you must backup:
For Omnibus:
- `/etc/gitlab/gitlab-secrets.json`
- `/etc/gitlab/gitlab.rb`
For installation from source:
- `/home/git/gitlab/config/secrets.yml`
- `/home/git/gitlab/config/gitlab.yml`
NOTE! Since we are switching from Omnibus TO a source installation (The Cloudron Gitlab app is a source installation) we will need to convert the `gitlab-secrets.json` to `secrets.yml`.
Also in the converted `secrets.yml` you will need to change `gitlab_rails:` to `production:` - otherwise gitlab will generate new secrets for rails.
### Create a backup of your running Gitlab
!!! note "[Gitlab Documentation - Backup and Restore](https://docs.gitlab.com/ee/raketasks/backup_restore.html)"
> GitLab 12.2 or later:
>
> ```bash
> sudo gitlab-backup create
> ```
>
> GitLab 12.1 and earlier:
>
> ```bash
> gitlab-rake gitlab:backup:create
> ```
>
> If you installed GitLab from source, use the following command: (This is how to do it in Cloudron)
>
> ```bash
> sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
> ```
>
> For more examples please visit the official [Gitlab Documentation - Backup and Restore](https://docs.gitlab.com/ee/raketasks/backup_restore.html)
Save the generated file I.e. `1632462433_2021_09_24_14.2.4_gitlab_backup.tar` on your local computer.
### Change the database owner in the created backup
In the Omnibus version the default user for the database was `gitlab` in my case.
You need to change this into the PostgreSQL user provided by Cloudron.
Go into the [Web terminal](/apps#web-terminal) of your Cloudron Gitlab app to get the username:
```bash
# echoing the single variable
echo $CLOUDRON_POSTGRESQL_USERNAME
userd5499e3cf81b43d093724d69fa223688
# getting all Postgresql variables
printenv | grep -i POSTGRES
CLOUDRON_POSTGRESQL_URL=postgres://userd5499e3cf81b43d093724d69fa223688:ab1569471419f341ed83f18538b275c09c1389fdb248398640d48fdc8847275858aeca488021da55edb460051a2a0595f226602afc7828becd1c17d91f55eee2@postgresql/dbd5499e3cf81b43d093724d69fa223688
CLOUDRON_POSTGRESQL_DATABASE=dbd5499e3cf81b43d093724d69fa223688
CLOUDRON_POSTGRESQL_PASSWORD=ab1569471419f341ed83f18538b275c09c1389fdb248398640d48fdc8847275858aeca488021da55edb460051a2a0595f226602afc7828becd1c17d91f55eee2
CLOUDRON_POSTGRESQL_USERNAME=userd5499e3cf81b43d093724d69fa223688
CLOUDRON_POSTGRESQL_HOST=postgresql
CLOUDRON_POSTGRESQL_PORT=5432
```
The content of the backup looks like this:
```tree
1632462433_2021_09_24_14.2.4_gitlab_backup/
├── artifacts.tar.gz
├── backup_information.yml
├── builds.tar.gz
├── db
│   └── database.sql.gz
├── lfs.tar.gz
├── pages.tar.gz
├── repositories
│   └── @hashed
└── uploads.tar.gz
```
Extract the `database.sql.gz` to edit the `database.sql`.
We will need to replace all `OWNER TO gitlab;` strings to `OWNER TO userd5499e3cf81b43d093724d69fa223688;`.
Save the `database.sql` and `gzip` the file back into the `database.sql.gz`.
Put it back together into the `1632462433_2021_09_24_14.2.4_gitlab_backup.tar`.
Example all done in a terminal:
```bash
# Move the created backup into a seperate folder for extraction
# Extract the created tar
tar -xf 1632745419_2021_09_27_14.2.4_gitlab_backup.tar
# decompress the gziped database.sql.gz
gzip -d db/database.sql.gz
# replace all `OWNER TO gitlab;` with `OWNER TO OWNER TO userd5499e3cf81b43d093724d69fa223688;`
sed -e 's/OWNER TO gitlab;/OWNER TO userd5499e3cf81b43d093724d69fa223688;/' -i db/database.sql
# compress the `database.sql`
gzip db/database.sql
# Create the new `1632745419_2021_09_27_14.2.4_gitlab_backup.tar`
# You will get a warning since it wont tar it self
tar -cf 1632745419_2021_09_27_14.2.4_gitlab_backup.tar ./
tar: ./1632745419_2021_09_27_14.2.4_gitlab_backup.tar is the archive; not backed up.
```
### Restoring the Backup
* Upload the new tar to the Gitlab Cloudron app to `/app/data/backups/1632745419_2021_09_27_14.2.4_gitlab_backup.tar`.
* Upload the converted `secrets.yml` to `/app/data/secrets.yml`
* Create a snapshot of the running Cloudron Gitlab app (this way we can jump back if something does not work, and you won't need to re-upload the backup)
* Open the [Web terminal](/apps#web-terminal) of the Cloudron Gitlab app and run the restore
```bash
sudo -u git -H GITLAB_ASSUME_YES=1 bundle exec rake --trace gitlab:backup:restore RAILS_ENV=production
```
Now the restore should start looking something like this:
```log
`/home/git` is not writable.
Bundler will use `/tmp/bundler20210927-435-134v1je435' as your home directory temporarily.
. . .
2021-09-24 06:22:36 +0000 -- done
2021-09-24 06:22:36 +0000 -- Restoring uploads ...
2021-09-24 06:22:36 +0000 -- done
2021-09-24 06:22:36 +0000 -- Restoring builds ...
2021-09-24 06:22:36 +0000 -- done
2021-09-24 06:22:36 +0000 -- Restoring artifacts ...
2021-09-24 06:22:36 +0000 -- done
2021-09-24 06:22:36 +0000 -- Restoring pages ...
2021-09-24 06:22:36 +0000 -- done
2021-09-24 06:22:36 +0000 -- Restoring lfs objects ...
2021-09-24 06:22:36 +0000 -- done
```
Now migrate your custom settings from the `gitlab.rb` settings into `/app/data/gitlab.yml` file.
Restart the Cloudron Gitlab app.
Now everything should work as intended.
### Migration of Gitlab Users to Cloudron LDAP Users
You might want to link old Gitlab users to the new Cloudron LDAP Users.
This is rather simple, just make sure the username of the user is the same as in Cloudron.
Example:
Gitlab username is `tina.testing` so the Cloudron username should also be `tina.testing`

Loading…
Cancel
Save