Skip to content

Commit e8b9376

Browse files
committed
chore(deploy): Better organize setup scripts
1 parent c2fb04f commit e8b9376

File tree

6 files changed

+225
-228
lines changed

6 files changed

+225
-228
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# shellcheck disable=SC1091
5+
source "$(dirname "${BASH_SOURCE[0]}")/_logging.sh"
6+
7+
install_git() {
8+
if command -v git &>/dev/null; then
9+
log "Git already installed"
10+
return
11+
fi
12+
13+
echo "Installing Git..."
14+
if command -v apt-get &>/dev/null; then
15+
log_cmd "apt-get update && apt-get install -y git"
16+
elif command -v dnf &>/dev/null; then
17+
log_cmd "dnf install -y git"
18+
elif command -v yum &>/dev/null; then
19+
log_cmd "yum install -y git"
20+
elif command -v apk &>/dev/null; then
21+
log_cmd "apk add git"
22+
elif command -v pacman &>/dev/null; then
23+
log_cmd "pacman -Sy --noconfirm git"
24+
else
25+
echo "⚠️ Unsupported package manager. Please install Git manually."
26+
exit 1
27+
fi
28+
}
29+
30+
install_docker() {
31+
echo "Installing Docker..."
32+
log_cmd "curl -fsSL https://get.docker.com | sh"
33+
log_cmd "systemctl enable --now docker"
34+
echo "Installing Docker Compose plugin..."
35+
mkdir -p ~/.docker/cli-plugins
36+
log_cmd "curl -SL https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o ~/.docker/cli-plugins/docker-compose"
37+
chmod +x ~/.docker/cli-plugins/docker-compose
38+
}
39+
40+
install_git
41+
install_docker
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# shellcheck disable=SC1091
5+
source "$(dirname "${BASH_SOURCE[0]}")/_logging.sh"
6+
7+
echo "Cloning Wikibase Release Pipeline repository..."
8+
cd "$WBS_DIR"
9+
log_cmd "git clone $REPO_URL"
10+
cd wikibase-release-pipeline
11+
log_cmd "git checkout deploy-setup-script"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# shellcheck disable=SC1091
5+
source "$(dirname "${BASH_SOURCE[0]}")/_logging.sh"
6+
7+
generate_cert() {
8+
log "Generating certificate for setup page..."
9+
mkdir -p "$SETUP_DIR/letsencrypt" "$SETUP_DIR/certs"
10+
log_cmd "docker pull certbot/certbot"
11+
12+
if log_cmd "docker run --rm \
13+
-v $SETUP_DIR/letsencrypt:/etc/letsencrypt \
14+
-v $SETUP_DIR/certs:/certs \
15+
-p 80:80 \
16+
certbot/certbot certonly \
17+
--standalone --non-interactive \
18+
--preferred-challenges http \
19+
--agree-tos \
20+
--email $CERT_EMAIL \
21+
-d $SETUP_HOST"; then
22+
23+
CERT_PATH="$SETUP_DIR/letsencrypt/live/$SETUP_HOST"
24+
cp "$CERT_PATH/fullchain.pem" "$SETUP_DIR/certs/cert.pem"
25+
cp "$CERT_PATH/privkey.pem" "$SETUP_DIR/certs/key.pem"
26+
else
27+
echo "Let's Encrypt challenge failed, falling back to self-signed certificate."
28+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
29+
-out "$SETUP_DIR/certs/cert.pem" \
30+
-keyout "$SETUP_DIR/certs/key.pem" \
31+
-subj "/CN=$SETUP_HOST"
32+
fi
33+
}
34+
35+
start_webserver() {
36+
BUILDX_DRIVER=$(docker buildx inspect | grep 'Driver:' | awk '{print $2}')
37+
[[ "$BUILDX_DRIVER" == "docker-container" ]] && LOAD_FLAG="--load" || LOAD_FLAG=""
38+
39+
log_cmd "docker build $LOAD_FLAG -t wikibase/deploy-setup-webserver ."
40+
log_cmd "docker run -d \
41+
-p $SETUP_PORT:443 \
42+
-v $DEPLOY_DIR:/app/deploy \
43+
-v $DEPLOY_DIR/setup/views:/app/views \
44+
-v $SETUP_DIR/certs:/app/certs \
45+
-v $LOG_PATH:/app/setup.log \
46+
wikibase/deploy-setup-webserver"
47+
48+
echo
49+
echo "To continue setup navigate to:"
50+
echo " https://$SETUP_HOST:$SETUP_PORT"
51+
echo
52+
}
53+
54+
log "Starting setup webserver..."
55+
cd "$SETUP_DIR"
56+
generate_cert
57+
start_webserver
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# shellcheck disable=SC1091
5+
source "$(dirname "${BASH_SOURCE[0]}")/_logging.sh"
6+
7+
wait_for_env() {
8+
until [ -f "$ENV_FILE_PATH" ]; do
9+
sleep 2
10+
done
11+
echo "Configuration saved."
12+
}
13+
14+
launch_wikibase() {
15+
echo "Launching Wikibase Suite Docker containers..."
16+
cd "$DEPLOY_DIR"
17+
log_cmd "docker compose up -d"
18+
}
19+
20+
final_message() {
21+
echo
22+
echo "Setup is Complete!"
23+
echo
24+
25+
if [[ -f "$ENV_FILE_PATH" ]]; then
26+
while IFS= read -r line; do
27+
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue
28+
eval "export $line"
29+
done < "$ENV_FILE_PATH"
30+
31+
if [[ -n "$WIKIBASE_PUBLIC_HOST" ]]; then
32+
echo "Access your MediaWiki / Wikibase instance at:"
33+
echo
34+
echo " https://$WIKIBASE_PUBLIC_HOST"
35+
else
36+
echo "⚠️ Could not determine WIKIBASE_PUBLIC_HOST from .env"
37+
fi
38+
39+
echo
40+
echo "The following configuration was generated during setup."
41+
echo "Please copy and save these credentials and settings securely:"
42+
echo
43+
sed 's/^/ /' "$ENV_FILE_PATH"
44+
echo
45+
else
46+
echo "⚠️ .env file not found at $ENV_FILE_PATH"
47+
echo
48+
fi
49+
}
50+
51+
exec >> "$LOG_PATH" 2>&1
52+
wait_for_env
53+
launch_wikibase
54+
final_message

deploy/setup/scripts/_logging.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# --- Shared logging functions ---
4+
5+
log() {
6+
if [[ "$VERBOSE" == "true" ]]; then
7+
echo "$@"
8+
fi
9+
}
10+
11+
log_cmd() {
12+
if [[ "$VERBOSE" == "true" ]]; then
13+
bash -c "$@"
14+
else
15+
bash -c "$@" &>/dev/null
16+
fi
17+
return $?
18+
}
19+
20+
# --- Ensure LOG_PATH exists if defined ---
21+
if [[ -n "$LOG_PATH" ]]; then
22+
mkdir -p "$(dirname "$LOG_PATH")"
23+
touch "$LOG_PATH"
24+
fi

0 commit comments

Comments
 (0)