commit c5eca7f43d087c3a3765876ca421762b51eb1ced Author: Dmitry Afanasyev Date: Fri Dec 24 10:27:43 2021 +0300 sonnar scanner 1.0.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8a04dd --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Pycharm +.idea/ + +# Projects work files +logs/* +*.log +.scannerwork/ + + +# Apple +.DS_Store +.AppleDouble +.LSOverride +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes diff --git a/Dockerfile.sonarscanner b/Dockerfile.sonarscanner new file mode 100644 index 0000000..5343036 --- /dev/null +++ b/Dockerfile.sonarscanner @@ -0,0 +1,47 @@ +FROM openjdk:12-jdk-alpine + +# BEGIN alpine-specific +RUN apk add --no-cache curl grep sed unzip bash nano +RUN TERM=xterm +# END alpine-specific + +# non-root user +ENV USER=sonarscanner +ENV UID=12345 +ENV GID=23456 +RUN addgroup --gid $GID sonarscanner +RUN adduser \ + --disabled-password \ + --gecos "" \ + --ingroup "$USER" \ + --no-create-home \ + --uid "$UID" \ + "$USER" + +# Set timezone to CST +ENV TZ=Europe/Moscow +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +WORKDIR /usr/src + +ARG SCANNER_VERSION=4.5.0.2216 +ENV SCANNER_FILE=sonar-scanner-cli-${SCANNER_VERSION}-linux.zip +ENV SCANNER_EXPANDED_DIR=sonar-scanner-${SCANNER_VERSION}-linux +RUN curl --insecure -o ${SCANNER_FILE} \ + -L https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/${SCANNER_FILE} && \ + unzip -q ${SCANNER_FILE} && \ + rm ${SCANNER_FILE} && \ + mv ${SCANNER_EXPANDED_DIR} /usr/lib/sonar-scanner && \ + ln -s /usr/lib/sonar-scanner/bin/sonar-scanner /usr/local/bin/sonar-scanner + +ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner + +COPY sonar-scanner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.properties + +# ensure Sonar uses the provided Java for musl instead of a borked glibc one +RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner + +# Separating ENTRYPOINT and CMD operations allows for core execution variables to +# be easily overridden by passing them in as part of the `docker run` command. +# This allows the default /usr/src base dir to be overridden by users as-needed. +#CMD ["sonar-scanner", "-Dsonar.projectBaseDir=/usr/src"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a77067 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# HOW TO RUN + +MOVE your python project ./code directory + + docker-compose up + +# Results + +Visit [http://localhost:9000/issues](http://localhost:9000/issues) + + login: admin + password: password + +# Logs + +Sonar logs can be found at log folder + +# Run properties + +Run properties can be changed in docker-compose command line +or something else + + -Dsonar.host.url=http://sonarqube:9000 \ + -Dsonar.jdbc.url=jdbc:h2:tcp://sonarqube/sonar \ + -Dsonar.projectKey=MyProjectKey \ + -Dsonar.projectName="My Project Name" \ + -Dsonar.projectVersion=1 \ + -Dsonar.projectBaseDir=/usr/src \ + -Dsonar.sources=. \ No newline at end of file diff --git a/code/.gitkeep b/code/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2a3ab70 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,68 @@ +version: "3" + +volumes: + sonarqube_data: + sonarqube_extensions: + sonarqube_logs: + pg_db: + pg_data: + elastic: + +networks: + sonarnet: + +services: + sonarqube: + image: sonarqube:9.2.4-community + container_name: sonarqube + hostname: sonarqube + ports: + - "9000:9000" + environment: + - sonar.jdbc.username=sonar + - sonar.jdbc.password=sonar + - sonar.search.javaAdditionalOpts=-Dbootstrap.system_call_filter=false + volumes: + - sonarqube_data:/opt/sonarqube/data + - sonarqube_extensions:/opt/sonarqube/extensions + - ./logs:/opt/sonarqube/logs + networks: + - sonarnet + + sonar_db: + image: postgres:12.9 + container_name: sonar_db + hostname: db + environment: + - POSTGRES_USER=sonar + - POSTGRES_PASSWORD=sonar + volumes: + - pg_db:/var/lib/postgresql + - pg_data:/var/lib/postgresql/data + ulimits: + nofile: + soft: 65536 + hard: 65536 + networks: + - sonarnet + + sonar_scanner: + image: "sonar-scanner" + container_name: sonar_scanner + build: + context: . + dockerfile: Dockerfile.sonarscanner + restart: on-failure + command: > + bash -c "echo 'start sleeping 30 sec' && sleep 30 + && echo 'Changing default passwords on sonar webpage' + && curl -u admin:admin -X POST 'http://sonarqube:9000/api/users/change_password?login=admin&previousPassword=admin&password=password' + && echo 'start sleeping 3 sec' && sleep 3 + && sonar-scanner -Dsonar.projectBaseDir=/usr/src" + depends_on: + - sonarqube + - sonar_db + networks: + - sonarnet + volumes: + - ./:/usr/src diff --git a/sonar-scanner.properties b/sonar-scanner.properties new file mode 100644 index 0000000..99bfe5e --- /dev/null +++ b/sonar-scanner.properties @@ -0,0 +1,37 @@ +# must be unique in a given SonarQube instance +sonar.projectKey=write_your_access_key_here +sonar.login=admin +sonar.password=password + +#----- Default SonarQube server +sonar.host.url=http://sonarqube:9000 + +# --- optional properties --- + +# defaults to project key +sonar.projectName=My project +# defaults to 'not provided' +sonar.projectVersion=1.0 + +# Path is relative to the sonar-project.properties file. Defaults to . +sonar.sources=./code + +# Encoding of the source code. Default is default system encoding +sonar.sourceEncoding=UTF-8 + +#----- PostgreSQL +sonar.jdbc.url=jdbc:postgresql://sonar_db/sonar + +#----- MySQL +#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 + +#----- Oracle +#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE + +#----- Microsoft SQLServer +#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor + +# H2 database from Docker Sonar container +#sonar.jdbc.url=jdbc:h2:tcp://sonarqube/sonar + +sonar.projectBaseDir=/usr/src diff --git a/sonarqube-init.sh b/sonarqube-init.sh new file mode 100644 index 0000000..7de2e6a --- /dev/null +++ b/sonarqube-init.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# per https://hub.docker.com/_/sonarqube +# to be executed before launching the app + +sysctl -w vm.max_map_count=262144 +sysctl -w fs.file-max=65536 +ulimit -n 65536 +ulimit -u 4096 \ No newline at end of file