Skip to content

Commit c907401

Browse files
iwakitakuma33iwakitakuma
authored andcommitted
TEST
1 parent ee16a17 commit c907401

File tree

7 files changed

+163
-0
lines changed

7 files changed

+163
-0
lines changed

test/env/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
how to use test gitlab env
2+
this env is dangerous. Because pass or token is public, So don't enter credential data in this test gitlab env.
3+
4+
start test gitlab enviroment
5+
docker compose up -d
6+
backup gitlab DATA in dump
7+
docker exec env-web-1 bash /etc/dump/backup.sh
8+
restore gitlab DATA from dump
9+
docker exec env-web-1 bash /etc/dump/restore.sh
10+
11+
gitlab test users and pass
12+
root avaefacaweaef
13+
test_admin avaefacaweaef
14+
test_developer avaefacaweaef
15+
test_user avaefacaweaef
16+
17+
set up test repo in your local
18+
git init -b main
19+
git config user.name test_admin
20+
git config user.email [email protected]
21+
git remote add origin git@localhost:test_group/test_project.git
22+
git remote set-url origin http://test_admin:gitlab-pat@localhost:8080/test_group/test_project.git
23+
git pull origin main
24+
docker build --platform=linux/arm64 -t iwakitakuma/gitlab-mcp .
25+
docker stop gitlab-mcp
26+
docker rm gitlab-mcp
27+
docker run -id \
28+
--name gitlab-mcp \
29+
-e GITLAB_PERSONAL_ACCESS_TOKEN=gitlab-pat \
30+
-e GITLAB_API_URL="http://host.docker.internal:8080/api/v4"\
31+
-e USE_GITLAB_WIKI=true \
32+
-e GITLAB_IS_OLD=true \
33+
-e USE_MILESTONE=true \
34+
-e USE_PIPELINE=true \
35+
-e SSE=true \
36+
-p 3333:3002 \
37+
iwakitakuma/gitlab-mcp

test/env/docker-compose.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: '3.8'
2+
3+
services:
4+
web:
5+
image: 'gitlab/gitlab-ce:18.1.2-ce.0'
6+
hostname: 'gitlab.example.com'
7+
environment:
8+
GITLAB_OMNIBUS_CONFIG: |
9+
external_url 'http://localhost:8080'
10+
postgresql['enable'] = false
11+
gitlab_rails['initial_root_password'] = 'avaefacaweaef'
12+
gitlab_rails['db_adapter'] = 'postgresql'
13+
gitlab_rails['db_encoding'] = 'unicode'
14+
gitlab_rails['db_host'] = 'postgresql'
15+
gitlab_rails['db_port'] = 5432
16+
gitlab_rails['db_username'] = 'gitlab'
17+
gitlab_rails['db_password'] = 'gitlabpassword'
18+
gitlab_rails['db_database'] = 'gitlab'
19+
puma['worker_processes'] = 1
20+
nginx['listen_port'] = 8081
21+
nginx['listen_https'] = false
22+
ports:
23+
- '8080:8081'
24+
shm_size: '256m'
25+
mem_limit: 6g
26+
depends_on:
27+
- postgresql
28+
- redis
29+
volumes:
30+
- ./dump:/etc/dump
31+
32+
postgresql:
33+
image: postgres:16
34+
hostname: 'postgresql'
35+
environment:
36+
POSTGRES_DB: 'gitlab'
37+
POSTGRES_USER: 'gitlab'
38+
POSTGRES_PASSWORD: 'gitlabpassword'
39+
restart: always
40+
41+
redis:
42+
image: 'redis:7-alpine'
43+
hostname: 'redis'
44+
restart: always

test/env/dump/backup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
gitlab-backup create
3+
tar zcvf gitlab_config.tgz /etc/gitlab
4+
cp "$(ls -t /var/opt/gitlab/backups/*.tar | head -n 1)" /etc/dump/custom_gitlab_backup.tar
5+
cp gitlab_config.tgz /etc/dump
690 KB
Binary file not shown.

test/env/dump/gitlab_config.tgz

52.3 KB
Binary file not shown.

test/env/dump/restore-gitlab.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SOURCE_DUMP_PATH="/etc/dump"
5+
BACKUP_FILE="${SOURCE_DUMP_PATH}/custom_gitlab_backup.tar"
6+
CONFIG_TAR_FILE="${SOURCE_DUMP_PATH}/gitlab_config.tgz"
7+
GITLAB_BACKUPS_DIR="/var/opt/gitlab/backups"
8+
GITLAB_CONFIG_DIR="/etc/gitlab"
9+
10+
echo "Starting GitLab restore process..."
11+
12+
TMP_WORK_DIR="/tmp/gitlab_restore_work"
13+
mkdir -p "$TMP_WORK_DIR"
14+
cp "$CONFIG_TAR_FILE" "$TMP_WORK_DIR/"
15+
16+
echo "Extracting GitLab configuration..."
17+
tar zxvf "${TMP_WORK_DIR}/$(basename "$CONFIG_TAR_FILE")" -C "$TMP_WORK_DIR"
18+
cp "$TMP_WORK_DIR/etc/gitlab/gitlab.rb" "$GITLAB_CONFIG_DIR/gitlab.rb"
19+
cp "$TMP_WORK_DIR/etc/gitlab/gitlab-secrets.json" "$GITLAB_CONFIG_DIR/gitlab-secrets.json"
20+
chown root:root "$GITLAB_CONFIG_DIR/gitlab.rb" "$GITLAB_CONFIG_DIR/gitlab-secrets.json"
21+
chmod 600 "$GITLAB_CONFIG_DIR/gitlab.rb" "$GITLAB_CONFIG_DIR/gitlab-secrets.json"
22+
23+
rm -rf "$TMP_WORK_DIR"
24+
25+
# ここに gitlab-ctl reconfigure を追加します
26+
echo "Running initial gitlab-ctl reconfigure to generate necessary files..."
27+
gitlab-ctl reconfigure
28+
29+
echo "Stopping GitLab services for restore..."
30+
gitlab-ctl stop puma
31+
gitlab-ctl stop sidekiq
32+
33+
mkdir -p "$GITLAB_BACKUPS_DIR"
34+
35+
echo "Copying backup file..."
36+
cp "$BACKUP_FILE" "$GITLAB_BACKUPS_DIR/"
37+
chown git:git "$GITLAB_BACKUPS_DIR/$(basename "$BACKUP_FILE")"
38+
39+
echo "Restoring GitLab backup..."
40+
gitlab-backup restore BACKUP=custom force=yes
41+
42+
echo "Reconfiguring GitLab after restore..."
43+
gitlab-ctl reconfigure
44+
45+
echo "Starting GitLab services..."
46+
gitlab-ctl start
47+
48+
echo "Checking GitLab status..."
49+
gitlab-ctl status
50+
51+
echo "Running GitLab check..."
52+
gitlab-rake gitlab:check SANITIZE=true

test/env/dump/restore.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
apt update && apt install -y curl
3+
4+
URL="http://localhost:8081/users/sign_in"
5+
KEYWORD="Username or primary email"
6+
MAX_RETRIES=10
7+
SLEEP_SECONDS=60
8+
9+
for ((i=1; i<=MAX_RETRIES; i++)); do
10+
echo "Try #$i: curl $URL"
11+
12+
response=$(curl -s "$URL")
13+
14+
if echo "$response" | grep -q "$KEYWORD"; then
15+
echo "✅ Keyword found: '$KEYWORD'"
16+
bash /etc/dump/restore-gitlab.sh
17+
exit 0
18+
else
19+
echo "❌ Keyword not found. Waiting $SLEEP_SECONDS seconds..."
20+
sleep $SLEEP_SECONDS
21+
fi
22+
done
23+
24+
echo "⏰ Timeout: '$KEYWORD' not found in $MAX_RETRIES tries."
25+
exit 1

0 commit comments

Comments
 (0)