Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dockerfile as a fixed runtime env #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ubuntu:20.04

ENV SOURCE_GITLAB=git.mycompany.com
ENV SOURCE_PATH="gitlab-migration-source"
ENV TARGET_GITLAB=gitlab.com
ENV TARGET_PATH="gitlab-migration-target"
# setting access token here will have precedence over .secrets file and considered insecure
#ENV TARGET_ACCESS_TOKEN=<target_gitlab_access_token>
#ENV SOURCE_ACCESS_TOKEN=<source_gitlab_access_token>

ENV ARCHIVE_AFTER_MIGRATION="no"
ENV ADD_DESCRIPTION="no"
ENV MIGRATE_ARCHIVED_PROJECTS="no"
ENV MIGRATE_GROUP_VARIABLES="no"
ENV MIGRATE_PROJECT_VARIABLES="no"
ENV MIGRATE_BADGES="no"
ENV MIGRATE_HOOKS="no"

RUN adduser migration

RUN apt-get update && \
apt-get install jq curl -y

COPY --chown=migration:migration .secrets /home/migration/
COPY --chown=migration:migration migrate.sh /home/migration/
RUN chmod +x /home/migration/migrate.sh

USER migration
WORKDIR /home/migration

ENTRYPOINT ["/bin/bash", "/home/migration/migrate.sh", "-D", "FOREGROUND"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ Script to migrate Gitlab groups and their projects from one Gitlab instance to a

## Requirements
* Bash (4.0 or newer)
* jq
* jq (1.6)
* curl (7.68.0 tested)

## Usage ##
* Create local file `.secrets` and add a [Personal Access Token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) for the source Gitlab instance in the first line and a Personal Access Token for the target Gitlab instance in the second line. Both tokens need the `api` scope. Example:
* Create local file `.secrets` and add a [Personal Access Token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) for the source Gitlab instance in the first line and a Personal Access Token for the target Gitlab instance in the second line. Also add a newline (LF) to the end. Both tokens need the `api` scope. Example:
```
$ cat .secrets
dskjfdskjfr7987dfkds
Expand All @@ -23,7 +24,7 @@ Script to migrate Gitlab groups and their projects from one Gitlab instance to a
```

## Limitations ##
* Tested with Gitlab 13.0
* Tested with Gitlab 13.0 / 14.0
* Currently only Community Edition features are supported. See [list of supported features](#supported-features) below for details. This doesn't limit the script to Community Edition Gitlab instances though. It can be used with any of Community, Enterprise or Gitlab.com SaaS instances as source and target.
* The target group path already has to exist
* Max. 100 Subgroups, Variables, Hooks, Badges per parent entity will be migrated as no API pagination is implemented
Expand Down
17 changes: 11 additions & 6 deletions migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ fi
#MIGRATE_PROJECT_VARIABLES="no"
#MIGRATE_BADGES="no"
#MIGRATE_HOOKS="no"
CURL_PARAMS=""

unset -v sourceGitlabPrivateAccessToken targetGitlabPrivateAccessToken
{ IFS=$'\n\r' read -r sourceGitlabPrivateAccessToken && IFS=$'\n\r' read -r targetGitlabPrivateAccessToken; } < .secrets
CURL_PARAMS="--raw"

# only read from .secrets if env vars not existing
if [ -z ${SOURCE_ACCESS_TOKEN+x} ] || [ -z ${TARGET_ACCESS_TOKEN+x} ]; then
echo "Reset GitLab access tokens, attempting to read from .secrets file"
unset -v SOURCE_ACCESS_TOKEN TARGET_ACCESS_TOKEN
# make sure you .secrets file has new line added at the end using LF only
{ IFS=$'\n' read -r SOURCE_ACCESS_TOKEN && IFS=$'\n' read -r TARGET_ACCESS_TOKEN; } < .secrets
fi

dryRun=false

baseUrlSourceGitlabApi="https://${SOURCE_GITLAB}/api/v4"
authHeaderSourceGitlab="PRIVATE-TOKEN: ${sourceGitlabPrivateAccessToken}"
authHeaderSourceGitlab="PRIVATE-TOKEN: ${SOURCE_ACCESS_TOKEN}"
baseUrlTargetGitlabApi="https://${TARGET_GITLAB}/api/v4"
baseUrlTargetGitlab="https://${TARGET_GITLAB}"
authHeaderTargetGitlab="PRIVATE-TOKEN: ${targetGitlabPrivateAccessToken}"
authHeaderTargetGitlab="PRIVATE-TOKEN: ${TARGET_ACCESS_TOKEN}"


function urlencode() {
Expand Down