From 3d003bcec9c1a65d80271ac09b6e38726769e338 Mon Sep 17 00:00:00 2001 From: jimfuqian Date: Wed, 29 May 2024 17:08:59 -0700 Subject: [PATCH 1/3] demo add tests coverage report. --- Dockerfile | 1 + Dockerfile.selenium | 34 +++++++++---------- ...insfile.cbc-run-multi-pr-checks-w-selenium | 3 +- docker-compose.yml | 9 +++++ docker-compose/run_integration_tests_local.sh | 3 +- docker-compose/run_selenium_tests_remote.sh | 2 +- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45708554b..a48150cfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,5 @@ ENV PATH="/tmp/venv/bin:${PATH}" RUN pip install --upgrade pip RUN pip install --upgrade pip-tools RUN pip install --upgrade setuptools +RUN pip install --upgrade coverage RUN pip install -r requirements/requirements.dev.txt --no-index --find-links ./vendor/ \ No newline at end of file diff --git a/Dockerfile.selenium b/Dockerfile.selenium index 5c645fb35..c3822589c 100755 --- a/Dockerfile.selenium +++ b/Dockerfile.selenium @@ -1,17 +1,17 @@ -FROM selenium/standalone-chrome - -ENV PYTHONUNBUFFERED 1 -USER root -RUN apt-get update ; apt-get install -yq git curl libpq-dev libffi-dev -RUN apt-get update ; apt-get install -yq python3 python3-venv -RUN ln -s /usr/bin/python3 /usr/local/bin/python -RUN useradd -m -s /bin/bash DEV -USER DEV -ADD . /code -WORKDIR /code -RUN python -m venv /tmp/venv -RUN . /tmp/venv/bin/activate -ENV PATH="/tmp/venv/bin:${PATH}" -RUN pip3 install --upgrade pip -RUN pip3 install selenium pytest jsonschema - +FROM seleniarm/standalone-chromium + +ENV PYTHONUNBUFFERED 1 +USER root +RUN apt-get update ; apt-get install -yq git curl libpq-dev libffi-dev +RUN apt-get update ; apt-get install -yq python3 python3-venv +RUN ln -s /usr/bin/python3 /usr/local/bin/python +RUN useradd -m -s /bin/bash DEV +USER DEV +ADD . /code +WORKDIR /code +RUN python -m venv /tmp/venv +RUN . /tmp/venv/bin/activate +ENV PATH="/tmp/venv/bin:${PATH}" +RUN pip3 install --upgrade pip +RUN pip3 install selenium pytest jsonschema + diff --git a/Jenkinsfiles/Jenkinsfile.cbc-run-multi-pr-checks-w-selenium b/Jenkinsfiles/Jenkinsfile.cbc-run-multi-pr-checks-w-selenium index 1b3b40618..7bb8ccedb 100755 --- a/Jenkinsfiles/Jenkinsfile.cbc-run-multi-pr-checks-w-selenium +++ b/Jenkinsfiles/Jenkinsfile.cbc-run-multi-pr-checks-w-selenium @@ -57,6 +57,7 @@ pipeline { . venv/bin/activate make reqs-download make reqs-install-dev + pip install --upgrade coverage """ } } @@ -74,7 +75,7 @@ pipeline { steps{ sh """ . venv/bin/activate - python runtests.py + coverage run runtests.py && coverage report -m """ } } diff --git a/docker-compose.yml b/docker-compose.yml index f78b131a4..2cebff9f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,3 +63,12 @@ services: - .:/code profiles: - tests + tests: + build: . + command: bash -c "coverage run runtests.py && coverage report -m" + env_file: + - docker-compose/unittests-env-vars.env + volumes: + - .:/code + profiles: + - coverage diff --git a/docker-compose/run_integration_tests_local.sh b/docker-compose/run_integration_tests_local.sh index 87bed3e15..bd212a53c 100755 --- a/docker-compose/run_integration_tests_local.sh +++ b/docker-compose/run_integration_tests_local.sh @@ -244,7 +244,8 @@ else pip install -r requirements/requirements.txt \ --no-index --find-links ./vendor/; \ pip install sqlparse; \ - python runtests.py --integration ${INTEGRATION_TESTS_LIST}" + coverage run runtests.py --integration ${INTEGRATION_TESTS_LIST}; \ + coverage report -m" fi fi diff --git a/docker-compose/run_selenium_tests_remote.sh b/docker-compose/run_selenium_tests_remote.sh index 611788a6d..f6dcbe7d2 100755 --- a/docker-compose/run_selenium_tests_remote.sh +++ b/docker-compose/run_selenium_tests_remote.sh @@ -102,7 +102,7 @@ SYSTEM=$(uname -s) echo "USE_NEW_PERM_SCREEN=" ${USE_NEW_PERM_SCREEN} echo "BB2 Server URL=" ${HOSTNAME_URL} -export USE_NEW_PERM_SCREEN +## export USE_NEW_PERM_SCREEN export USE_MSLSX=false # stop all before run selenium remote tests From 7479bc4b9adb27b18a59fe34fe0dacfa5f3a9aac Mon Sep 17 00:00:00 2001 From: jimfuqian Date: Mon, 3 Jun 2024 07:18:51 -0700 Subject: [PATCH 2/3] demo with a local sonarqube server + scanner. --- Dockerfile | 4 +++- docker-compose.yml | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index a48150cfd..2b2a18073 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,11 @@ RUN useradd -m -s /bin/bash DEV USER DEV ADD . /code WORKDIR /code +RUN wget -P /tmp https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip +RUN unzip /tmp/sonar-scanner-cli-5.0.1.3006-linux.zip -d /tmp RUN python -m venv /tmp/venv RUN . /tmp/venv/bin/activate -ENV PATH="/tmp/venv/bin:${PATH}" +ENV PATH="/tmp/sonar-scanner-5.0.1.3006-linux/bin:/tmp/venv/bin:${PATH}" RUN pip install --upgrade pip RUN pip install --upgrade pip-tools RUN pip install --upgrade setuptools diff --git a/docker-compose.yml b/docker-compose.yml index 2cebff9f9..1ed048c8c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,6 +52,14 @@ services: profiles: - mocksls platform: linux/amd64 + sonarqube: + image: sonarqube:community + volumes: + - sonarqube_data:/opt/sonarqube/data + - sonarqube_extensions:/opt/sonarqube/extensions + - sonarqube_logs:/opt/sonarqube/logs + ports: + - "9000:9000" unittests: build: . command: python3 -m debugpy --listen 0.0.0.0:6789 --wait-for-client runtests.py @@ -63,12 +71,24 @@ services: - .:/code profiles: - tests - tests: + coverage: build: . - command: bash -c "coverage run runtests.py && coverage report -m" + command: bash -c "coverage run runtests.py && coverage xml" env_file: - docker-compose/unittests-env-vars.env volumes: - .:/code profiles: - coverage + sonardemo: + build: . + command: bash -c "sonar-scanner -Dsonar.projectKey=BB2 -Dsonar.sources=. -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.host.url=http://sonarqube:9000 -Dsonar.token=sqp_9f1dcd7f83b3b12be28008a6e0a595352a852bec" + volumes: + - .:/code + profiles: + - sonardemo +volumes: + sonarqube_data: + sonarqube_extensions: + sonarqube_logs: + From 943fa85d5960a243aa97008bb3450a85f22e8825 Mon Sep 17 00:00:00 2001 From: jimfuqian Date: Tue, 4 Jun 2024 09:47:16 -0700 Subject: [PATCH 3/3] change sonar port to 9009 --- docker-compose.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1ed048c8c..71b7c0c79 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,12 +54,16 @@ services: platform: linux/amd64 sonarqube: image: sonarqube:community + environment: + - SONAR_WEB_PORT=9009 volumes: - sonarqube_data:/opt/sonarqube/data - sonarqube_extensions:/opt/sonarqube/extensions - sonarqube_logs:/opt/sonarqube/logs ports: - - "9000:9000" + - "9009:9009" + profiles: + - sonarserver unittests: build: . command: python3 -m debugpy --listen 0.0.0.0:6789 --wait-for-client runtests.py @@ -82,7 +86,7 @@ services: - coverage sonardemo: build: . - command: bash -c "sonar-scanner -Dsonar.projectKey=BB2 -Dsonar.sources=. -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.host.url=http://sonarqube:9000 -Dsonar.token=sqp_9f1dcd7f83b3b12be28008a6e0a595352a852bec" + command: bash -c "sonar-scanner -Dsonar.projectKey=BB2 -Dsonar.sources=. -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.host.url=http://sonarqube:9009 -Dsonar.token=sqp_9f1dcd7f83b3b12be28008a6e0a595352a852bec" volumes: - .:/code profiles: