add sonarqube to docker-compose (#2113)

* add sonarqube to docker-compose
* change volume dir
* add postgres init db
* add comment for sonarqube error
This commit is contained in:
xiagw 2019-05-08 18:10:22 +08:00 committed by Shao Yu-Lung (Allen)
parent f5c80cd251
commit cbbdb0a86b
6 changed files with 94 additions and 1 deletions

View File

@ -41,6 +41,8 @@ volumes:
driver: ${VOLUMES_DRIVER}
mosquitto:
driver: ${VOLUMES_DRIVER}
sonarqube:
driver: ${VOLUMES_DRIVER}
services:
@ -403,6 +405,10 @@ services:
- JUPYTERHUB_POSTGRES_USER=${JUPYTERHUB_POSTGRES_USER}
- JUPYTERHUB_POSTGRES_PASSWORD=${JUPYTERHUB_POSTGRES_PASSWORD}
- JUPYTERHUB_POSTGRES_DB=${JUPYTERHUB_POSTGRES_DB}
- SONARQUBE_POSTGRES_INIT=${SONARQUBE_POSTGRES_INIT}
- SONARQUBE_POSTGRES_DB=${SONARQUBE_POSTGRES_DB}
- SONARQUBE_POSTGRES_USER=${SONARQUBE_POSTGRES_USER}
- SONARQUBE_POSTGRES_PASSWORD=${SONARQUBE_POSTGRES_PASSWORD}
networks:
- backend
@ -1421,3 +1427,26 @@ services:
- "${MANTICORE_HTTP_PORT}:9308"
networks:
- backend
### SONARQUBE ################################################
sonarqube:
build:
context: ./sonarqube
hostname: "${SONARQUBE_HOSTNAME}"
volumes:
- ${DATA_PATH_HOST}/sonarqube/conf:/opt/sonarqube/conf
- ${DATA_PATH_HOST}/sonarqube/data:/opt/sonarqube/data
- ${DATA_PATH_HOST}/sonarqube/logs:/opt/sonarqube/logs
- ${DATA_PATH_HOST}/sonarqube/extensions:/opt/sonarqube/extensions
- ${DATA_PATH_HOST}/sonarqube/plugins:/opt/sonarqube/lib/bundled-plugins
ports:
- ${SONARQUBE_PORT}:9000
depends_on:
- postgres
environment:
- sonar.jdbc.username=${SONARQUBE_POSTGRES_USER}
- sonar.jdbc.password=${SONARQUBE_POSTGRES_PASSWORD}
- sonar.jdbc.url=jdbc:postgresql://${SONARQUBE_POSTGRES_HOST}:5432/${SONARQUBE_POSTGRES_DB}
networks:
- backend
- frontend

View File

@ -676,3 +676,19 @@ MANTICORE_HTTP_PORT=9308
PGADMIN_PORT=5050
PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org
PGADMIN_DEFAULT_PASSWORD=admin
### SONARQUBE ################################################
## docker-compose up -d sonarqube
## (If you encounter a database error)
## docker-compose exec --user=root postgres
## source docker-entrypoint-initdb.d/init_sonarqube_db.sh
## (If you encounter logs error)
## docker-compose run --user=root --rm sonarqube chown sonarqube:sonarqube /opt/sonarqube/logs
SONARQUBE_HOSTNAME=sonar.example.com
SONARQUBE_PORT=9000
SONARQUBE_POSTGRES_INIT=true
SONARQUBE_POSTGRES_HOST=postgres
SONARQUBE_POSTGRES_DB=sonar
SONARQUBE_POSTGRES_USER=sonar
SONARQUBE_POSTGRES_PASSWORD=sonarPass

View File

@ -1,3 +1,4 @@
*.sh
!init_gitlab_db.sh
!init_jupyterhub_db.sh
!init_sonarqube_db.sh

View File

@ -33,7 +33,7 @@
# EOSQL
#
### default database and user for jupyterhub ##############################################
if [ $JUPYTERHUB_POSTGRES_INIT == 'true' ]; then
if [ "$JUPYTERHUB_POSTGRES_INIT" == 'true' ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER $JUPYTERHUB_POSTGRES_USER WITH PASSWORD '$JUPYTERHUB_POSTGRES_PASSWORD';
CREATE DATABASE $JUPYTERHUB_POSTGRES_DB;

View File

@ -0,0 +1,44 @@
#!/bin/bash
#
# Copy createdb.sh.example to createdb.sh
# then uncomment then set database name and username to create you need databases
#
# example: .env POSTGRES_USER=appuser and need db name is myshop_db
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER myuser WITH PASSWORD 'mypassword';
# CREATE DATABASE myshop_db;
# GRANT ALL PRIVILEGES ON DATABASE myshop_db TO myuser;
# EOSQL
#
# this sh script will auto run when the postgres container starts and the $DATA_PATH_HOST/postgres not found.
#
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db1 WITH PASSWORD 'db1';
# CREATE DATABASE db1;
# GRANT ALL PRIVILEGES ON DATABASE db1 TO db1;
# EOSQL
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db2 WITH PASSWORD 'db2';
# CREATE DATABASE db2;
# GRANT ALL PRIVILEGES ON DATABASE db2 TO db2;
# EOSQL
#
# psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
# CREATE USER db3 WITH PASSWORD 'db3';
# CREATE DATABASE db3;
# GRANT ALL PRIVILEGES ON DATABASE db3 TO db3;
# EOSQL
#
### default database and user for gitlab ##############################################
if [ "$SONARQUBE_POSTGRES_INIT" == 'true' ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER $SONARQUBE_POSTGRES_USER WITH PASSWORD '$SONARQUBE_POSTGRES_PASSWORD';
CREATE DATABASE $SONARQUBE_POSTGRES_DB;
GRANT ALL PRIVILEGES ON DATABASE $SONARQUBE_POSTGRES_DB TO $SONARQUBE_POSTGRES_USER;
ALTER ROLE $SONARQUBE_POSTGRES_USER CREATEROLE SUPERUSER;
EOSQL
echo
fi

3
sonarqube/Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM sonarqube:latest
LABEL maintainer="xiagw <fxiaxiaoyu@gmail.com>"