Skip to content

Commit a672b22

Browse files
SonarQube (#8256)
Co-authored-by: push-app-to-main[bot] <203845782+push-app-to-main[bot]@users.noreply.github.com> Co-authored-by: CanbiZ <[email protected]>
1 parent 3f02934 commit a672b22

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed

ct/headers/sonarqube

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_____ ____ __
2+
/ ___/____ ____ ____ ______/ __ \__ __/ /_ ___
3+
\__ \/ __ \/ __ \/ __ `/ ___/ / / / / / / __ \/ _ \
4+
___/ / /_/ / / / / /_/ / / / /_/ / /_/ / /_/ / __/
5+
/____/\____/_/ /_/\__,_/_/ \___\_\__,_/_.___/\___/
6+

ct/sonarqube.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: prop4n
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+
# Source: https://docs.sonarsource.com/sonarqube-server
7+
8+
APP="SonarQube"
9+
var_tags="${var_tags:-automation}"
10+
var_cpu="${var_cpu:-4}"
11+
var_ram="${var_ram:-6144}"
12+
var_disk="${var_disk:-25}"
13+
var_os="${var_os:-debian}"
14+
var_version="${var_version:-13}"
15+
var_unprivileged="${var_unprivileged:-1}"
16+
17+
header_info "$APP"
18+
variables
19+
color
20+
catch_errors
21+
22+
function update_script() {
23+
header_info
24+
check_container_storage
25+
check_container_resources
26+
if [[ ! -d /opt/sonarqube ]]; then
27+
msg_error "No ${APP} Installation Found!"
28+
exit
29+
fi
30+
31+
if check_for_gh_release "sonarqube" "SonarSource/sonarqube"; then
32+
msg_info "Stopping Service"
33+
systemctl stop sonarqube
34+
msg_ok "Stopped Service"
35+
36+
msg_info "Creating backup"
37+
BACKUP_DIR="/opt/sonarqube-backup"
38+
mv /opt/sonarqube ${BACKUP_DIR}
39+
msg_ok "Backup created"
40+
41+
msg_info "Installing sonarqube"
42+
RELEASE=$(curl -fsSL https://api.github.com/repos/SonarSource/sonarqube/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
43+
curl -fsSL "https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${RELEASE}.zip" -o $temp_file
44+
unzip -q "$temp_file" -d /opt
45+
mv /opt/sonarqube-* /opt/sonarqube
46+
msg_ok "Installed sonarqube"
47+
48+
msg_info "Restoring backup"
49+
cp -rp ${BACKUP_DIR}/data/ /opt/sonarqube/data/
50+
cp -rp ${BACKUP_DIR}/extensions/ /opt/sonarqube/extensions/
51+
cp -p ${BACKUP_DIR}/conf/sonar.properties /opt/sonarqube/conf/sonar.properties
52+
rm -rf ${BACKUP_DIR}
53+
chown -R sonarqube:sonarqube /opt/sonarqube
54+
msg_ok "Backup restored"
55+
56+
msg_info "Starting Service"
57+
systemctl start sonarqube
58+
msg_ok "Service started"
59+
msg_ok "Updated Successfully!"
60+
fi
61+
exit
62+
}
63+
64+
start
65+
build_container
66+
description
67+
68+
msg_ok "Completed Successfully!\n"
69+
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
70+
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
71+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:9000${CL}"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "sonarqube",
3+
"slug": "sonarqube",
4+
"categories": [
5+
20,
6+
19
7+
],
8+
"date_created": "2025-09-30",
9+
"type": "ct",
10+
"updateable": true,
11+
"privileged": false,
12+
"interface_port": 9000,
13+
"documentation": "https://docs.sonarsource.com/sonarqube-server",
14+
"config_path": "/opt/sonarqube/conf/sonar.properties",
15+
"website": "https://www.sonarsource.com/products/sonarqube/",
16+
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/sonarqube.webp",
17+
"description": "SonarQube Server automates code quality and security reviews and provides actionable code intelligence so developers can focus on building better, faster.",
18+
"install_methods": [
19+
{
20+
"type": "default",
21+
"script": "ct/sonarqube.sh",
22+
"resources": {
23+
"cpu": 4,
24+
"ram": 6144,
25+
"hdd": 25,
26+
"os": "Debian",
27+
"version": "13"
28+
}
29+
}
30+
],
31+
"default_credentials": {
32+
"username": "admin",
33+
"password": "admin"
34+
},
35+
"notes": []
36+
}

install/sonarqube-install.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2021-2025 community-scripts ORG
3+
# Author: prop4n
4+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
5+
# Source: https://docs.sonarsource.com/sonarqube-server
6+
7+
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
8+
color
9+
verb_ip6
10+
catch_errors
11+
setting_up_container
12+
network_check
13+
update_os
14+
15+
JAVA_VERSION="21" setup_java
16+
PG_VERSION="17" setup_postgresql
17+
18+
msg_info "Installing Postgresql"
19+
DB_NAME="sonarqube"
20+
DB_USER="sonarqube"
21+
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
22+
$STD sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';"
23+
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;"
24+
{
25+
echo "Application Credentials"
26+
echo "DB_NAME: $DB_NAME"
27+
echo "DB_USER: $DB_USER"
28+
echo "DB_PASS: $DB_PASS"
29+
} >>~/sonarqube.creds
30+
msg_ok "Installed PostgreSQL"
31+
32+
msg_info "Configuring SonarQube"
33+
temp_file=$(mktemp)
34+
RELEASE=$(curl -fsSL https://api.github.com/repos/SonarSource/sonarqube/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
35+
curl -fsSL "https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${RELEASE}.zip" -o $temp_file
36+
unzip -q "$temp_file" -d /opt
37+
mv /opt/sonarqube-* /opt/sonarqube
38+
$STD useradd -r -m -U -d /opt/sonarqube -s /bin/bash sonarqube
39+
chown -R sonarqube:sonarqube /opt/sonarqube
40+
chmod -R 755 /opt/sonarqube
41+
mkdir -p /opt/sonarqube/conf
42+
cat <<EOF >/opt/sonarqube/conf/sonar.properties
43+
sonar.jdbc.username=${DB_USER}
44+
sonar.jdbc.password=${DB_PASS}
45+
sonar.jdbc.url=jdbc:postgresql://localhost/${DB_NAME}
46+
sonar.web.host=0.0.0.0
47+
sonar.web.port=9000
48+
EOF
49+
chmod +x /opt/sonarqube/bin/linux-x86-64/sonar.sh
50+
echo ${RELEASE} >>~/.sonarqube
51+
msg_ok "Configured SonarQube"
52+
53+
msg_info "Creating Service"
54+
cat <<EOF >/etc/systemd/system/sonarqube.service
55+
[Unit]
56+
Description=SonarQube service
57+
After=postgresql.service
58+
59+
[Service]
60+
Type=forking
61+
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
62+
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
63+
User=sonarqube
64+
Group=sonarqube
65+
Restart=on-failure
66+
LimitNOFILE=131072
67+
LimitNPROC=8192
68+
69+
[Install]
70+
WantedBy=multi-user.target
71+
EOF
72+
systemctl enable -q --now sonarqube
73+
msg_ok "Service Created"
74+
75+
motd_ssh
76+
customize
77+
78+
msg_info "Cleaning up"
79+
$STD apt -y autoremove
80+
$STD apt -y autoclean
81+
$STD apt -y clean
82+
msg_ok "Cleaned"

0 commit comments

Comments
 (0)