Files
loc_az_hci/infrastructure/gitops/gitlab-deploy.sh
defiQUG c39465c2bd
Some checks failed
Test / test (push) Has been cancelled
Initial commit: loc_az_hci (smom-dbis-138 excluded via .gitignore)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 09:04:46 -08:00

149 lines
4.1 KiB
Bash
Executable File

#!/bin/bash
# GitLab CE Deployment Script
# Deploys GitLab Community Edition using Docker Compose
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Configuration
GITLAB_DOMAIN="${GITLAB_DOMAIN:-gitlab.local}"
GITLAB_PORT="${GITLAB_PORT:-8080}"
SSH_PORT="${SSH_PORT:-2222}"
COMPOSE_FILE="${COMPOSE_FILE:-$(dirname "$0")/../../docker-compose/gitlab.yml}"
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_docker() {
if ! command -v docker &> /dev/null; then
log_error "Docker not found. Please install Docker first."
exit 1
fi
if ! docker ps &>/dev/null; then
log_error "Docker daemon not running. Please start Docker."
exit 1
fi
if ! command -v docker-compose &> /dev/null && ! docker compose version &>/dev/null; then
log_error "Docker Compose not found. Please install Docker Compose."
exit 1
fi
}
check_resources() {
log_info "Checking system resources..."
TOTAL_MEM=$(free -g | awk '/^Mem:/{print $2}')
if [ "$TOTAL_MEM" -lt 8 ]; then
log_warn "GitLab requires at least 8GB RAM. You have ${TOTAL_MEM}GB."
log_warn "GitLab may not run optimally with less than 8GB."
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
}
update_compose_file() {
log_info "Updating Docker Compose configuration..."
if [ -f "$COMPOSE_FILE" ]; then
sed -i "s/gitlab.local/$GITLAB_DOMAIN/g" "$COMPOSE_FILE" || true
log_info "Docker Compose file configured"
fi
}
deploy_gitlab() {
log_info "Deploying GitLab CE using Docker Compose..."
log_warn "GitLab requires significant resources and may take 5-10 minutes to start"
# Determine compose command
if docker compose version &>/dev/null; then
COMPOSE_CMD="docker compose"
else
COMPOSE_CMD="docker-compose"
fi
# Deploy
cd "$(dirname "$COMPOSE_FILE")"
$COMPOSE_CMD -f "$(basename "$COMPOSE_FILE")" up -d
log_info "Waiting for GitLab to initialize (this may take several minutes)..."
log_info "You can monitor progress with: docker logs -f gitlab"
# Wait for service to be healthy
MAX_WAIT=600 # 10 minutes
ELAPSED=0
while [ $ELAPSED -lt $MAX_WAIT ]; do
if curl -s "http://localhost:$GITLAB_PORT" &>/dev/null; then
log_info "GitLab is ready!"
return 0
fi
log_info "Waiting for GitLab to start... ($ELAPSED/$MAX_WAIT seconds)"
sleep 10
ELAPSED=$((ELAPSED + 10))
done
log_warn "GitLab may still be initializing. Check logs with:"
log_info " docker logs gitlab"
}
get_initial_password() {
log_info "Retrieving initial root password..."
if docker exec gitlab grep 'Password:' /etc/gitlab/initial_root_password &>/dev/null; then
INITIAL_PASSWORD=$(docker exec gitlab grep 'Password:' /etc/gitlab/initial_root_password | awk '{print $2}')
log_info "Initial root password: $INITIAL_PASSWORD"
log_warn "Change this password on first login!"
else
log_warn "Initial password file not found. Password may have been changed."
fi
}
show_info() {
log_info "GitLab deployment completed!"
log_info ""
log_info "Access GitLab at:"
log_info " Web UI: http://$GITLAB_DOMAIN:$GITLAB_PORT"
log_info " SSH: ssh://git@$GITLAB_DOMAIN:$SSH_PORT"
log_info ""
log_info "Default credentials:"
log_info " Username: root"
get_initial_password
log_info ""
log_info "Useful commands:"
log_info " View logs: docker logs gitlab"
log_info " Stop: docker-compose -f $COMPOSE_FILE down"
log_info " Restart: docker-compose -f $COMPOSE_FILE restart"
log_info " Check status: docker exec gitlab gitlab-ctl status"
}
main() {
log_info "Starting GitLab CE deployment..."
check_docker
check_resources
update_compose_file
deploy_gitlab
show_info
}
main "$@"