Skip to content
Draft

TEST #171

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
37 changes: 37 additions & 0 deletions test/env/README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]
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
44 changes: 44 additions & 0 deletions test/env/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/env/dump/backup.sh
Original file line number Diff line number Diff line change
@@ -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
Binary file added test/env/dump/custom_gitlab_backup.tar
Binary file not shown.
Binary file added test/env/dump/gitlab_config.tgz
Binary file not shown.
52 changes: 52 additions & 0 deletions test/env/dump/restore-gitlab.sh
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions test/env/dump/restore.sh
Original file line number Diff line number Diff line change
@@ -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