diff --git a/test/env/README.md b/test/env/README.md new file mode 100644 index 0000000..91be055 --- /dev/null +++ b/test/env/README.md @@ -0,0 +1,37 @@ +how to use test gitlab env + this env is dangerous. Because pass or token is public, So don't enter credential data in this test gitlab env. + +start test gitlab enviroment + docker compose up -d +backup gitlab DATA in dump + docker exec env-web-1 bash /etc/dump/backup.sh +restore gitlab DATA from dump + docker exec env-web-1 bash /etc/dump/restore.sh + +gitlab test users and pass + root avaefacaweaef + test_admin avaefacaweaef + test_developer avaefacaweaef + test_user avaefacaweaef + +set up test repo in your local + git init -b main + git config user.name test_admin + git config user.email test_admin@example.com + git remote add origin git@localhost:test_group/test_project.git + git remote set-url origin http://test_admin:gitlab-pat@localhost:8080/test_group/test_project.git + git pull origin main + docker build --platform=linux/arm64 -t iwakitakuma/gitlab-mcp . + docker stop gitlab-mcp + docker rm gitlab-mcp + docker run -id \ + --name gitlab-mcp \ + -e GITLAB_PERSONAL_ACCESS_TOKEN=gitlab-pat \ + -e GITLAB_API_URL="http://host.docker.internal:8080/api/v4"\ + -e USE_GITLAB_WIKI=true \ + -e GITLAB_IS_OLD=true \ + -e USE_MILESTONE=true \ + -e USE_PIPELINE=true \ + -e SSE=true \ + -p 3333:3002 \ + iwakitakuma/gitlab-mcp diff --git a/test/env/docker-compose.yml b/test/env/docker-compose.yml new file mode 100644 index 0000000..5c1efd0 --- /dev/null +++ b/test/env/docker-compose.yml @@ -0,0 +1,44 @@ +version: '3.8' + +services: + web: + image: 'gitlab/gitlab-ce:18.1.2-ce.0' + hostname: 'gitlab.example.com' + environment: + GITLAB_OMNIBUS_CONFIG: | + external_url 'http://localhost:8080' + postgresql['enable'] = false + gitlab_rails['initial_root_password'] = 'avaefacaweaef' + gitlab_rails['db_adapter'] = 'postgresql' + gitlab_rails['db_encoding'] = 'unicode' + gitlab_rails['db_host'] = 'postgresql' + gitlab_rails['db_port'] = 5432 + gitlab_rails['db_username'] = 'gitlab' + gitlab_rails['db_password'] = 'gitlabpassword' + gitlab_rails['db_database'] = 'gitlab' + puma['worker_processes'] = 1 + nginx['listen_port'] = 8081 + nginx['listen_https'] = false + ports: + - '8080:8081' + shm_size: '256m' + mem_limit: 6g + depends_on: + - postgresql + - redis + volumes: + - ./dump:/etc/dump + + postgresql: + image: postgres:16 + hostname: 'postgresql' + environment: + POSTGRES_DB: 'gitlab' + POSTGRES_USER: 'gitlab' + POSTGRES_PASSWORD: 'gitlabpassword' + restart: always + + redis: + image: 'redis:7-alpine' + hostname: 'redis' + restart: always diff --git a/test/env/dump/backup.sh b/test/env/dump/backup.sh new file mode 100644 index 0000000..76fcae0 --- /dev/null +++ b/test/env/dump/backup.sh @@ -0,0 +1,5 @@ +#!/bin/bash +gitlab-backup create +tar zcvf gitlab_config.tgz /etc/gitlab +cp "$(ls -t /var/opt/gitlab/backups/*.tar | head -n 1)" /etc/dump/custom_gitlab_backup.tar +cp gitlab_config.tgz /etc/dump diff --git a/test/env/dump/custom_gitlab_backup.tar b/test/env/dump/custom_gitlab_backup.tar new file mode 100644 index 0000000..5aaa0fc Binary files /dev/null and b/test/env/dump/custom_gitlab_backup.tar differ diff --git a/test/env/dump/gitlab_config.tgz b/test/env/dump/gitlab_config.tgz new file mode 100644 index 0000000..fa31322 Binary files /dev/null and b/test/env/dump/gitlab_config.tgz differ diff --git a/test/env/dump/restore-gitlab.sh b/test/env/dump/restore-gitlab.sh new file mode 100644 index 0000000..c759008 --- /dev/null +++ b/test/env/dump/restore-gitlab.sh @@ -0,0 +1,52 @@ +#!/bin/bash +set -e + +SOURCE_DUMP_PATH="/etc/dump" +BACKUP_FILE="${SOURCE_DUMP_PATH}/custom_gitlab_backup.tar" +CONFIG_TAR_FILE="${SOURCE_DUMP_PATH}/gitlab_config.tgz" +GITLAB_BACKUPS_DIR="/var/opt/gitlab/backups" +GITLAB_CONFIG_DIR="/etc/gitlab" + +echo "Starting GitLab restore process..." + +TMP_WORK_DIR="/tmp/gitlab_restore_work" +mkdir -p "$TMP_WORK_DIR" +cp "$CONFIG_TAR_FILE" "$TMP_WORK_DIR/" + +echo "Extracting GitLab configuration..." +tar zxvf "${TMP_WORK_DIR}/$(basename "$CONFIG_TAR_FILE")" -C "$TMP_WORK_DIR" +cp "$TMP_WORK_DIR/etc/gitlab/gitlab.rb" "$GITLAB_CONFIG_DIR/gitlab.rb" +cp "$TMP_WORK_DIR/etc/gitlab/gitlab-secrets.json" "$GITLAB_CONFIG_DIR/gitlab-secrets.json" +chown root:root "$GITLAB_CONFIG_DIR/gitlab.rb" "$GITLAB_CONFIG_DIR/gitlab-secrets.json" +chmod 600 "$GITLAB_CONFIG_DIR/gitlab.rb" "$GITLAB_CONFIG_DIR/gitlab-secrets.json" + +rm -rf "$TMP_WORK_DIR" + +# ここに gitlab-ctl reconfigure を追加します +echo "Running initial gitlab-ctl reconfigure to generate necessary files..." +gitlab-ctl reconfigure + +echo "Stopping GitLab services for restore..." +gitlab-ctl stop puma +gitlab-ctl stop sidekiq + +mkdir -p "$GITLAB_BACKUPS_DIR" + +echo "Copying backup file..." +cp "$BACKUP_FILE" "$GITLAB_BACKUPS_DIR/" +chown git:git "$GITLAB_BACKUPS_DIR/$(basename "$BACKUP_FILE")" + +echo "Restoring GitLab backup..." +gitlab-backup restore BACKUP=custom force=yes + +echo "Reconfiguring GitLab after restore..." +gitlab-ctl reconfigure + +echo "Starting GitLab services..." +gitlab-ctl start + +echo "Checking GitLab status..." +gitlab-ctl status + +echo "Running GitLab check..." +gitlab-rake gitlab:check SANITIZE=true diff --git a/test/env/dump/restore.sh b/test/env/dump/restore.sh new file mode 100644 index 0000000..f5357a8 --- /dev/null +++ b/test/env/dump/restore.sh @@ -0,0 +1,25 @@ +#!/bin/bash +apt update && apt install -y curl + +URL="http://localhost:8081/users/sign_in" +KEYWORD="Username or primary email" +MAX_RETRIES=10 +SLEEP_SECONDS=60 + +for ((i=1; i<=MAX_RETRIES; i++)); do + echo "Try #$i: curl $URL" + + response=$(curl -s "$URL") + + if echo "$response" | grep -q "$KEYWORD"; then + echo "✅ Keyword found: '$KEYWORD'" + bash /etc/dump/restore-gitlab.sh + exit 0 + else + echo "❌ Keyword not found. Waiting $SLEEP_SECONDS seconds..." + sleep $SLEEP_SECONDS + fi +done + +echo "⏰ Timeout: '$KEYWORD' not found in $MAX_RETRIES tries." +exit 1