|
| 1 | +# gitlab-sync |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +(golang) CLI tool to synchronize GitLab projects and groups between two GitLab instances. |
| 6 | +It is designed to be used in a CI/CD pipeline to automate the process of keeping two GitLab instances in sync. |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +- Synchronize projects / groups between two GitLab instances |
| 11 | +- Enable Pull Mirroring for projects (requires GitLab Premium) |
| 12 | +- Can add projects to CI/CD catalog |
| 13 | +- Full copy of the project (description, icon, topics,...). Can also copy issues |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +### Docker |
| 18 | + |
| 19 | +You can run the CLI using Docker. It is available on GitHub Container Registry. |
| 20 | + |
| 21 | +1. Pull the Docker image: `docker pull ghcr.io/boxboxjason/gitlab-sync:latest` |
| 22 | +2. Run the Docker container with the required command line arguments / env variables (don't forget to mount the JSON file): |
| 23 | +```bash |
| 24 | +docker run --rm \ |
| 25 | + -e SOURCE_GITLAB_URL=<source_gitlab_url> \ |
| 26 | + -e SOURCE_GITLAB_TOKEN=<source_gitlab_token> \ |
| 27 | + -e DESTINATION_GITLAB_URL=<destination_gitlab_url> \ |
| 28 | + -e DESTINATION_GITLAB_TOKEN=<destination_gitlab_token> \ |
| 29 | + -e MIRROR_MAPPING=/home/gitlab-sync/mirror.json \ |
| 30 | + -v <my_mapping_json_file>:/home/gitlab-sync/mirror.json:ro,Z \ |
| 31 | + ghcr.io/boxboxjason/gitlab-sync:latest |
| 32 | +``` |
| 33 | + |
| 34 | +### Compile from source |
| 35 | + |
| 36 | +To compile the CLI from source, you need to have Go installed on your machine. |
| 37 | + |
| 38 | +1. Clone the repository: `git clone https://github.com/boxboxjason/gitlab-sync.git` |
| 39 | +2. Change to the project directory: `cd gitlab-sync` |
| 40 | +3. Build the CLI: `go build -o bin/gitlab-sync cmd/main.go` |
| 41 | +4. The binary will be created in the `bin` directory. |
| 42 | +5. Make sure the binary is executable: `chmod +x bin/gitlab-sync` |
| 43 | +6. You can run the CLI from the `bin` directory: `./bin/gitlab-sync` |
| 44 | +7. Optionally, you can move the binary to a directory in your `PATH` for easier access: `mv bin/gitlab-sync /usr/local/bin/` |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +The CLI requires no dependencies and can be run directly. It is available as a single binary executable. |
| 49 | + |
| 50 | +The mirroring configuration can be passed by either command line arguments or environment variables. |
| 51 | +If mandatory arguments are not provided, the program will prompt for them. |
| 52 | + |
| 53 | +| Argument | Environment Variable equivalent | Mandatory | Description | |
| 54 | +|----------|-------------------------------|-----------|-------------| |
| 55 | +| `--help` or `-h` | N/A | No | Show help message and exit | |
| 56 | +| `--version` or `-V` | N/A | No | Show version information and exit | |
| 57 | +| `--verbose` or `-v` | N/A | No | Enable verbose output | |
| 58 | +| `--dry-run` | N/A | No | Perform a dry run without making any changes | |
| 59 | +| `--source-url` | `SOURCE_GITLAB_URL` | Yes | URL of the source GitLab instance | |
| 60 | +| `--source-token` | `SOURCE_GITLAB_TOKEN` | No | Access token for the source GitLab instance | |
| 61 | +| `--destination-url` | `DESTINATION_GITLAB_URL` | Yes | URL of the destination GitLab instance | |
| 62 | +| `--destination-token` | `DESTINATION_GITLAB_TOKEN` | Yes | Access token for the destination GitLab instance | |
| 63 | +| `--mirror-mapping` | `MIRROR_MAPPING` | Yes | Path to a JSON file containing the mirror mapping | |
| 64 | + |
| 65 | +## Example |
| 66 | + |
| 67 | +```bash |
| 68 | +gitlab-sync \ |
| 69 | + --source-url https://gitlab.example.com \ |
| 70 | + --source-token <source_gitlab_token> \ |
| 71 | + --destination-url https://mycompany.example.com \ |
| 72 | + --destination-token <destination_gitlab_token> \ |
| 73 | + --mirror-mapping /path/to/mirror.json |
| 74 | +``` |
0 commit comments