Skip to content

Commit 0f59c1d

Browse files
authored
Merge pull request #1318 from okorach:fine-tuning-and-versioning
Fine-tuning-and-versioning
2 parents 447edb3 + c05596a commit 0f59c1d

File tree

9 files changed

+65
-13
lines changed

9 files changed

+65
-13
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FROM alpine:3.20.3
22
LABEL maintainer="[email protected]"
3+
ENV IN_DOCKER="Yes"
34

45
ARG USERNAME=sonar
56
ARG USER_UID=1000
@@ -33,7 +34,7 @@ RUN pip install --upgrade pip \
3334
&& pip install --no-cache-dir -r requirements.txt \
3435
&& pip install --no-cache-dir --upgrade pip setuptools wheel \
3536
&& python setup.py bdist_wheel \
36-
&& pip install dist/*-py3-*.whl --force-reinstall
37+
&& pip install dist/sonar_tools-*-py3-*.whl --force-reinstall
3738

3839
USER ${USERNAME}
3940
WORKDIR /home/${USERNAME}

cli/migration.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
Exports SonarQube platform configuration as JSON
2323
"""
2424
import sys
25-
import json
26-
import yaml
2725

2826
from cli import options
2927
from sonar import exceptions, errcodes, utilities
@@ -84,7 +82,7 @@ def __parse_args(desc):
8482
f"By default the export will show the value as '{utilities.DEFAULT}' "
8583
"and the setting will not be imported at import time",
8684
)
87-
args = options.parse_and_check(parser=parser, logger_name="sonar-migration")
85+
args = options.parse_and_check(parser=parser, logger_name="sonar-migration", is_migration=True)
8886
return args
8987

9088

cli/options.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __check_file_writeable(file: str) -> None:
176176
os.remove(file)
177177

178178

179-
def parse_and_check(parser: ArgumentParser, logger_name: str = None, verify_token: bool = True) -> ArgumentParser:
179+
def parse_and_check(parser: ArgumentParser, logger_name: str = None, verify_token: bool = True, is_migration: bool = False) -> ArgumentParser:
180180
"""Parses arguments, applies default settings and perform common environment checks"""
181181
try:
182182
args = parser.parse_args()
@@ -187,7 +187,12 @@ def parse_and_check(parser: ArgumentParser, logger_name: str = None, verify_toke
187187
log.set_logger(filename=kwargs[LOGFILE], logger_name=logger_name)
188188
log.set_debug_level(kwargs[VERBOSE])
189189
del kwargs[VERBOSE]
190-
log.info("sonar-tools version %s", version.PACKAGE_VERSION)
190+
if is_migration:
191+
log.info("sonar-migration version %s", version.MIGRATION_TOOL_VERSION)
192+
else:
193+
log.info("sonar-tools version %s", version.PACKAGE_VERSION)
194+
if os.getenv("IN_DOCKER", "No") == "Yes":
195+
kwargs[URL] = kwargs[URL].replace("http://localhost", "http://host.docker.internal")
191196
if log.get_level() == log.DEBUG:
192197
sanitized_args = kwargs.copy()
193198
sanitized_args[TOKEN] = utilities.redacted_token(sanitized_args[TOKEN])

deploy-migration.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ python3 setup_migration.py bdist_wheel
4848
pip install --upgrade --force-reinstall dist/sonar_migration-*-py3-*.whl
4949

5050
if [ "$build_image" == "1" ]; then
51-
docker build -t sonar-migration:latest .
51+
docker build -t sonar-migration:latest -f migration.Dockerfile .
5252
fi
5353

5454
if [ "$build_docs" == "1" ]; then

migration.Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM alpine:3.20.3
2+
LABEL maintainer="[email protected]"
3+
ENV IN_DOCKER="Yes"
4+
5+
ARG USERNAME=sonar
6+
ARG USER_UID=1000
7+
ARG GROUPNAME=sonar
8+
9+
# Create the user
10+
RUN addgroup -S ${GROUPNAME} && adduser -u ${USER_UID} -S ${USERNAME} -G ${GROUPNAME}
11+
12+
# Install python/pip
13+
ENV PYTHONUNBUFFERED=1
14+
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
15+
16+
# create a virtual environment and add it to PATH so that it is
17+
# applied for all future RUN and CMD calls
18+
ENV VIRTUAL_ENV=/opt/venv
19+
RUN python3 -m venv ${VIRTUAL_ENV}
20+
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
21+
22+
WORKDIR /opt/sonar-migration
23+
24+
COPY ./sonar sonar
25+
COPY ./requirements.txt .
26+
COPY ./cli cli
27+
COPY ./setup_migration.py .
28+
COPY ./sonar_migration .
29+
COPY ./README.md .
30+
COPY ./LICENSE .
31+
COPY ./sonar/audit sonar/audit
32+
33+
RUN pip install --upgrade pip \
34+
&& pip install --no-cache-dir -r requirements.txt \
35+
&& pip install --no-cache-dir --upgrade pip setuptools wheel \
36+
&& python setup_migration.py bdist_wheel \
37+
&& pip install dist/sonar_migration-py3-*.whl --force-reinstall
38+
39+
USER ${USERNAME}
40+
WORKDIR /home/${USERNAME}
41+
42+
ENTRYPOINT ["sonar-migration"]

setup_migration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@
2626
import setuptools
2727
from sonar import version
2828

29-
3029
with open("README.md", "r", encoding="utf-8") as fh:
3130
long_description = fh.read()
3231
setuptools.setup(
3332
name="sonar-migration",
34-
version=version.PACKAGE_VERSION,
33+
version=version.MIGRATION_TOOL_VERSION,
3534
scripts=["sonar_migration"],
3635
author="Olivier Korach",
3736
author_email="[email protected]",
38-
description="A collection of utility scripts for SonarQube and SonarCloud",
37+
description="A SonarQube collection tool to use in the context of SonarQube to SonarCloud migration",
3938
long_description=long_description,
4039
long_description_content_type="text/markdown",
4140
url="https://github.com/okorach/sonar-tools",

sonar/issues.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import sonar.platform as pf
3535
from sonar.util.types import ApiParams, ApiPayload, ObjectJsonRepr, ConfigSettings
3636

37-
from sonar import users, syncer, sqobject, findings, changelog, projects
37+
from sonar import users, sqobject, findings, changelog, projects
3838
import sonar.utilities as util
3939

4040
API_SET_TAGS = "issues/set_tags"
@@ -430,6 +430,8 @@ def accept(self) -> bool:
430430
return self.do_transition("accept")
431431

432432
def __apply_event(self, event: str, settings: ConfigSettings) -> bool:
433+
from sonar import syncer
434+
433435
log.debug("Applying event %s", str(event))
434436
# origin = f"originally by *{event['userName']}* on original branch"
435437
(event_type, data) = event.changelog_type()
@@ -491,6 +493,8 @@ def apply_changelog(self, source_issue: Issue, settings: ConfigSettings) -> bool
491493
"""
492494
:meta private:
493495
"""
496+
from sonar import syncer
497+
494498
events = source_issue.changelog()
495499
if events is None or not events:
496500
log.debug("Sibling %s has no changelog, no action taken", source_issue.key)

sonar/projects.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from sonar.util import types
4343

4444
from sonar import exceptions, errcodes
45-
from sonar import sqobject, components, qualitygates, qualityprofiles, rules, tasks, settings, webhooks, devops, syncer
45+
from sonar import sqobject, components, qualitygates, qualityprofiles, tasks, settings, webhooks, devops
4646
import sonar.permissions.permissions as perms
4747
from sonar import pull_requests, branches
4848
import sonar.utilities as util
@@ -799,6 +799,8 @@ def count_third_party_issues(self, filters: dict[str, str] = None) -> dict[str,
799799

800800
def __sync_community(self, another_project: object, sync_settings: types.ConfigSettings) -> tuple[list[dict[str, str]], dict[str, int]]:
801801
"""Syncs 2 projects findings on a community edition"""
802+
from sonar import syncer
803+
802804
report, counters = [], {}
803805
log.info("Syncing %s and %s issues", str(self), str(another_project))
804806
(report, counters) = syncer.sync_lists(
@@ -993,7 +995,7 @@ def export(self, export_settings: types.ConfigSettings, settings_list: dict[str,
993995
"taskHistory": [t._json for t in self.task_history()],
994996
}
995997
json_data["thirdPartyIssues"] = self.count_third_party_issues()
996-
log.info("%s has %d 3rd party issues", str(self), sum(v for v in json_data["thirdPartyIssues"].values()))
998+
log.debug("%s has %d 3rd party issues", str(self), sum(v for v in json_data["thirdPartyIssues"].values()))
997999

9981000
settings_dict = settings.get_bulk(endpoint=self.endpoint, component=self, settings_list=settings_list, include_not_set=False)
9991001
# json_data.update({s.to_json() for s in settings_dict.values() if include_inherited or not s.inherited})

sonar/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
"""
2626

2727
PACKAGE_VERSION = "3.4"
28+
MIGRATION_TOOL_VERSION = "0.1"

0 commit comments

Comments
 (0)