Skip to content

Commit 28347e1

Browse files
authored
Merge pull request #1325 from okorach:release-sonar-migration
Release-sonar-migration
2 parents 40c8f74 + 7820d4b commit 28347e1

File tree

4 files changed

+218
-10
lines changed

4 files changed

+218
-10
lines changed

deploy-migration.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
# sonar-tools
4-
# Copyright (C) 2019-2024 Olivier Korach
4+
# Copyright (C) 2024 Olivier Korach
55
# mailto:olivier.korach AT gmail DOT com
66
#
77
# This program is free software; you can redistribute it and/or
@@ -19,21 +19,20 @@
1919
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020
#
2121

22-
build_docs=1
2322
build_image=1
2423
release=0
2524

2625
while [ $# -ne 0 ]; do
2726
case $1 in
28-
nodoc)
29-
build_docs=0
30-
;;
3127
nodocker)
3228
build_image=0
3329
;;
3430
pypi)
3531
release=1
3632
;;
33+
dockerhub)
34+
release_docker=1
35+
;;
3736
*)
3837
;;
3938
esac
@@ -51,16 +50,15 @@ if [ "$build_image" == "1" ]; then
5150
docker build -t sonar-migration:latest -f migration.Dockerfile .
5251
fi
5352

54-
if [ "$build_docs" == "1" ]; then
55-
rm -rf api-doc/build
56-
sphinx-build -b html api-doc/source api-doc/build
57-
fi
58-
5953
# Deploy on pypi.org once released
6054
if [ "$release" = "1" ]; then
6155
echo "Confirm release [y/n] ?"
6256
read -r confirm
6357
if [ "$confirm" = "y" ]; then
6458
python3 -m twine upload dist/sonar_migration-*-py3-*.whl
6559
fi
60+
fi
61+
62+
if [ "$release_docker" = "1" ]; then
63+
docker buildx build --push --platform linux/amd64,linux/arm64 -t olivierkorach/sonar-migration:0.1 -t olivierkorach/sonar-migration:latest -f migration-release.Dockerfile .
6664
fi

doc/README.sonar-migration.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# sonar-migration
2+
Command line tool to collect SonarQube data to prepare eventual migration to SonarCloud.
3+
4+
![Downloads](https://img.shields.io/pypi/dm/sonar-migration?color=informational)
5+
![Python-Versions](https://img.shields.io/pypi/pyversions/sonar-migration)
6+
![License](https://img.shields.io/pypi/l/sonar-migration?color=informational)
7+
![Issues](https://img.shields.io/github/issues/okorach/sonar-tools)
8+
![Stars](https://img.shields.io/github/stars/okorach/sonar-tools?style=social)
9+
10+
[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=okorach_sonar-tools)](https://sonarcloud.io/dashboard?id=okorach_sonar-tools)
11+
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=okorach_sonar-tools&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=okorach_sonar-tools)
12+
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=okorach_sonar-tools&metric=bugs)](https://sonarcloud.io/dashboard?id=okorach_sonar-tools)
13+
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=okorach_sonar-tools&metric=ncloc)](https://sonarcloud.io/dashboard?id=okorach_sonar-tools)
14+
15+
**DISCLAIMER**: This software is community software.
16+
17+
18+
# Requirements and Installation
19+
- `sonar-migration` requires python 3.8 or higher
20+
- Installation is based on [pip](https://pypi.org/project/pip/).
21+
- Online installation.
22+
- Run: `python3 -m pip install sonar-migration` (or `python3 -m pip upgrade sonar-migration`)
23+
If install does not behave as expected you can try the **pip** `--force-reinstall` option (see **pip** documentation)
24+
- `sonar-migration` is also available as a docker image. See [Using sonar-migration in Docker](#docker)
25+
26+
27+
# Common command line parameters
28+
29+
All tools accept the following common parameters:
30+
- `-h` : Displays a help and exits
31+
- `-u` : URL of the SonarQube server. The default is environment variable `$SONAR_HOST_URL`
32+
or `http://localhost:9000` by default if the environment variable is not set
33+
- `-t` : Admin user token to invoke the SonarQube APIs, like `squ_83356c9b2db891d45da2a119a29cdc4d03fe654e`.
34+
The default is environment variable `$SONAR_TOKEN`.
35+
Using login/password is not possible.
36+
The user corresponding to the token must have sufficiently elevated permissions to achieve the tool tasks
37+
- `-f`: Define the output file, if not specified, `migration.<SERVER_ID>.json` is generated
38+
- `-o` : Organization, for SonarCloud - Ignored if running against a SonarQube instance
39+
- `-v` : Logging verbosity level (`WARN`, `ÌNFO` or `DEBUG`). The default is `INFO`.
40+
`ERROR` and above is always active.
41+
- `-c` or `--clientCert` : Allows to specify an optional client certificate file (as .pem file)
42+
- `--httpTimeout` : Sets the timeout for HTTP(S) requests to the SonarQube platform
43+
- `--skipVersionCheck` : `sonar-migration` occasionnally checks on pypi.org if there is a new version of **sonar-migration** available, and output a warning log if that is the case. You can skip this check with this option.
44+
- `-l <logFile>` : Send logs to **<logFile>**, stdout by default
45+
46+
See common [error exit codes](#exit-codes) at the bottom of this page
47+
48+
## Required Permissions
49+
50+
To export data, `sonar-migration` needs elevated permissions
51+
52+
## Examples
53+
```
54+
export SONAR_HOST_URL=https://sonar.acme-corp.com
55+
export SONAR_TOKEN=squ_83356c9b2db891d45da2a119a29cdc4d03fe654e
56+
57+
# Exports all platform migration data from https://sonar.acme-corp.com in default output file migration.<SERVER_ID>.json
58+
sonar-migration
59+
60+
# Exports all platform migration data from https://sonar.acme-corp.com in file data.json
61+
sonar-migration -f data.json
62+
63+
64+
```
65+
66+
For more about what is exported and imported by `sonar-config` please see the [sonar-config complete documentation](https://github.com/okorach/sonar-tools/blob/master/doc/sonar-config.md)
67+
68+
# <a name="docker"></a>Using sonar-migration in Docker
69+
70+
`sonar-migration` is available as a docker image. Here is how to use the docker version:
71+
```
72+
docker pull olivierkorach/sonar-migration:latest
73+
74+
docker run --rm -w `pwd` -v `pwd`:`pwd` sonar-migration -t $SONAR_TOKEN -u https://sonar.acme.com
75+
# After the command the file migratiob.<SERVER_ID>.json should be in the local (pwd) directory
76+
77+
# Alternatively you can pass the SonarQube URL and token as environment variables
78+
docker run --rm -w `pwd` -v `pwd`:`pwd` -e SONAR_TOKEN=<YOUR_SONAR_TOKEN> -e SONAR_HOST_URL=<YOUR_SONAR_URL> sonar-migration
79+
80+
# If you run sonar-migration on same machine as SonarQube, to help, the URL fragment http://localhost is automatically transformed in http://host.docker.internal,
81+
# For instance the 2 commands below have same outcome
82+
docker run --rm -w `pwd` -v `pwd`:`pwd` sonar-migration -t $SONAR_TOKEN -u http://host.docker.internal:9000
83+
docker run --rm -w `pwd` -v `pwd`:`pwd` sonar-migration -t $SONAR_TOKEN -u http://localhost:9000
84+
```
85+
86+
# <a name="exit-codes"></a>Exit codes
87+
88+
When sonar-migration complete successfully they return exit code 0. En case of fatal error the following exit codes may be returned:
89+
- Code 1: Authentication error (Incorrect token provided)
90+
- Code 2: Authorization error (provided token has insufficient permissions)
91+
- Code 3: Other general Sonar API HTTP error
92+
- Code 4: No token provided
93+
- Code 5: Non existing project key provided
94+
- Code 6: -
95+
- Code 7: Unsupported operation requested (because of SonarQube edition or configuration)
96+
- Code 8: -
97+
- Code 9: -
98+
- Code 10: Incorrect command line arguments
99+
- Code 11: Global analysis or project analysis token provided (user token needed for sonar-tools)
100+
- Code 12: HTTP request time-out using the SonarQube API
101+
- Code 13: -
102+
- Code 14: Sonar connection error
103+
- Code 15: Miscellaneous OS errors
104+
105+
106+
# What's New - Release notes
107+
108+
# Version 0.1
109+
110+
- First beta release
111+
112+
# License
113+
114+
Copyright (C) 2024 Olivier Korach
115+
mailto:olivier.korach AT gmail DOT com
116+
117+
This program is free software; you can redistribute it and/or
118+
modify it under the terms of the GNU Lesser General Public
119+
License as published by the Free Software Foundation; either
120+
version 3 of the License, or (at your option) any later version.
121+
122+
This program is distributed in the hope that it will be useful,
123+
but WITHOUT ANY WARRANTY; without even the implied warranty of
124+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
125+
Lesser General Public License for more details.
126+
127+
You should have received a copy of the GNU Lesser General Public License
128+
along with this program; if not, write to the Free Software Foundation,
129+
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

migration-release.Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 sonar-migration==0.1 --force-reinstall
35+
36+
USER ${USERNAME}
37+
WORKDIR /home/${USERNAME}
38+
39+
ENTRYPOINT ["sonar-migration"]

migration-snapshot.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"]

0 commit comments

Comments
 (0)