lib: start & stop GitLab

The image is saved to disk and cached because it is over 1GB, to save bandwidthc.
This commit is contained in:
Twenty Panda 2024-06-23 00:22:19 +02:00
parent c2b7f36bc8
commit 76ac081fb9
3 changed files with 70 additions and 3 deletions

View file

@ -49,9 +49,9 @@ function dependencies() {
$SUDO chmod +x /usr/local/bin/forgejo-curl.sh
fi
if ! which make curl daemon git-lfs jq sqlite3 > /dev/null ; then
if ! which make curl daemon git-lfs jq sqlite3 skopeo > /dev/null ; then
$SUDO apt-get update -qq
$SUDO apt-get install -y -qq make curl daemon git-lfs jq sqlite3
$SUDO apt-get install -y -qq make curl daemon git-lfs jq sqlite3 skopeo
fi
if ! test -f /usr/local/bin/mc || ! test -f /usr/local/bin/minio ; then
@ -178,6 +178,57 @@ function clobber() {
rm -fr /tmp/forgejo-end-to-end
}
function start_gitlab_cache_load() {
local image=$1
local d=$DIR_BINARIES/gitlab
if test -d $d ; then
log_info "loading $image from $d"
skopeo copy dir:$d docker-daemon:$image
fi
}
function start_gitlab_cache_save() {
local image=$1
local d=$DIR_BINARIES/gitlab
if ! test -d $d ; then
log_info "saving $image to $d"
skopeo copy docker-daemon:$image dir:$d
fi
}
function start_gitlab() {
local image=$1
local config=$2
start_gitlab_cache_load $image
local GITLAB_OMNIBUS_CONFIG="nginx['listen_https'] = false ; nginx['listen_port'] = 8181 ; external_url 'http://0.0.0.0:8181'; gitlab_rails['gitlab_shell_ssh_port'] = 2221;"
docker run --name="test-gitlab" --shm-size=128M -d \
-e GITLAB_OMNIBUS_CONFIG="$GITLAB_OMNIBUS_CONFIG" \
-p 2221:22 -p 8181:8181 \
$image >& /dev/null < /dev/null
start_gitlab_cache_save $image
for i in $(seq 10) ; do
if test $(curl --silent http://0.0.0.0:8181 -o /dev/null -w "%{http_code}") = 302 ; then
docker exec test-gitlab gitlab-rails runner "user = User.find_by_username 'root'; user.password = 'Wrobyak4'; user.password_confirmation = 'Wrobyak4'; user.password_automatically_set = false ; user.save!"
docker exec test-gitlab$serial gitlab-rails runner "Gitlab::CurrentSettings.current_application_settings.update(default_vcs_type: 'git')"
log_info "GitLab is ready"
return
fi
log_info "waiting for GitLab to come up $i"
sleep 30
done
log_info "GitLab did not come up"
docker logs test-gitlab
false
}
function stop_gitlab() {
docker rm -f test-gitlab
}
function stop_forgejo() {
local config=$1
@ -386,6 +437,10 @@ function stop() {
}
function show_logs() {
if ! test -d $DIR ; then
log_info "$DIR does not exist, no logs to display"
return
fi
(
cd $DIR
set +e