Skip to content

Commit 9100f9b

Browse files
committed
Add docker-compose for use with testing and Sonar analysis.
1 parent 4a319f8 commit 9100f9b

File tree

5 files changed

+96
-28
lines changed

5 files changed

+96
-28
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
build
55
out
66
gradle-local.properties
7+
docker
78

89
bin
9-
.vscode
10+
.vscode
1011
*.class
1112

1213
.classpath

CONTRIBUTING.md

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
This guide describes how to develop and contribute pull requests to this connector. The focus is currently on how to
22
develop and test the connector, either via a local install of Confluent Platform or of the regular Kafka distribution.
33

4-
Before beginning, you will need to install Java (either version 8, 11, or 17) and also have a MarkLogic instance
5-
available. It is recommended to use 11 or 17, as Confluent has deprecated Java 8 support in Confluent 7.x and is
6-
removing it in Confluent 8.x. See [the Confluent compatibility matrix](https://docs.confluent.io/platform/current/installation/versions-interoperability.html#java)
4+
Before beginning, you will need to install Java (either version 8, 11, or 17) and also have a MarkLogic instance
5+
available. It is recommended to use 11 or 17, as Confluent has deprecated Java 8 support in Confluent 7.x and is
6+
removing it in Confluent 8.x. Additionally, Sonar requires the use of Java 11 or 17.
7+
See [the Confluent compatibility matrix](https://docs.confluent.io/platform/current/installation/versions-interoperability.html#java)
78
for more information. After installing your desired version of Java, ensure that the `JAVA_HOME` environment variable
89
points to your Java installation.
910

1011

1112
# Running the test suite
1213

1314
The test suite for the MarkLogic Kafka connector, found at `src/test/resources`, requires that an application first be
14-
deployed to a MarkLogic instance. This application is deployed via
15-
[ml-gradle](https://github.com/marklogic-community/ml-gradle).
15+
deployed to a MarkLogic instance. This application is deployed via Docker and [ml-gradle](https://github.com/marklogic-community/ml-gradle).
1616

1717
Note that you do not need to install [Gradle](https://gradle.org/) - the `gradlew` program used below will install the
1818
appropriate version of Gradle if you do not have it installed already.
1919

20-
Before deploying, first create `gradle-local.properties`
21-
if it does not yet exist in the root directory of this project and configure `mlPassword` for your `admin` user - e.g.
22-
23-
mlPassword=changeme
24-
25-
Then deploy the application:
20+
Then deploy the application to a MarkLogic Docker container built using a docker-compose file:
2621

22+
docker-compose up -d --build
23+
<Wait 20 to 30 seconds and verify that <http://localhost:8001> shows the MarkLogic admin screen before proceeding.>
2724
./gradlew -i mlDeploy
2825

2926
The application deploys a single REST API app server listening on port 8019; please ensure you have this port available
@@ -38,20 +35,40 @@ Alternatively, you can import this project into an IDE such as IntelliJ and run
3835

3936
# Running Sonar code analysis
4037

41-
An effort has been started to analyze the codebase with Sonar; this will ideally be done by Jenkins in the near future.
38+
In order to use SonarQube, you must have used Docker to run this project's `docker-compose.yml` file, and you must
39+
have those services running.
40+
41+
To configure the SonarQube service, perform the following steps:
42+
43+
1. Go to http://localhost:9000 .
44+
2. Login as admin/admin. SonarQube will ask you to change this password; you can choose whatever you want ("password" works).
45+
3. Click on "Create project manually".
46+
4. Enter "marklogic-kafka-connector" for the Project Display Name; use that as the Project Key as well.
47+
5. Enter "master" as the main branch name.
48+
6. Click on "Next".
49+
8. Click on "Use the global setting" and then "Create project".
50+
8. On the "Analysis Method" page, click on "Locally".
51+
9. In the "Provide a token" panel, click on "Generate". Copy the token.
52+
10. Update `systemProp.sonar.token=<Replace With Your Sonar Token>` in `gradle.properties` in the root of your project.
53+
54+
To run SonarQube, run the following Gradle tasks, which will run all the tests with code coverage and then generate
55+
a quality report with SonarQube:
56+
57+
./gradlew test sonar
58+
59+
If you do not update `systemProp.sonar.token` in your `gradle.properties` file, you can specify the token via the
60+
following:
61+
62+
./gradlew test sonar -Dsonar.token=paste your token here
63+
64+
When that completes, you can find the results at http://localhost:9000/dashboard?id=marklogic-kafka-connector
4265

43-
You can run Sonar code analysis locally by doing the following:
66+
Click on that link. If it's the first time you've run the report, you'll see all issues. If you've run the report
67+
before, then SonarQube will show "New Code" by default. That's handy, as you can use that to quickly see any issues
68+
you've introduced on the feature branch you're working on. You can then click on "Overall Code" to see all issues.
4469

45-
1. [Install the latest sonarqube](https://www.sonarsource.com/products/sonarqube/downloads/), either via the zip file
46-
or via Docker.
47-
2. If you install sonarqube via a zip file, you'll need to adjust its default config as both it and our kafka-junit tests
48-
try to use the same port (and we haven't figured out yet how to make kafka-junit use a different port). To do so,
49-
edit the `./conf/sonar.properties` file in the directory where you unzipped the zip file. Uncomment the
50-
`sonar.embeddedDatabase.port` property and change the port from 9092 to 9093.
51-
3. Follow the sonarqube docs for starting sonarqube up, logging in, and setting up a "manual" project in your local
52-
clone of this repository; make sure you generate a token, which can be set to never expire
53-
4. Configure `systemProp.sonar.login` in your gradle-local.properties (creating that file in the root of this project if necessary)
54-
5. Run `./gradlew sonar` or `./gradlew test sonar` if you want code coverage to be reported
70+
Note that if you only need results on code smells and vulnerabilities, you can repeatedly run `./gradlew sonar`
71+
without having to re-run the tests.
5572

5673
For more assistance with Sonar and Gradle, see the [Sonar Gradle plugin docs](https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/).
5774

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
// Only used for testing
88
id 'com.marklogic.ml-gradle' version '4.6.0'
99
id 'jacoco'
10-
id "org.sonarqube" version "3.5.0.2730"
10+
id "org.sonarqube" version "4.4.1.3373"
1111

1212
// Used to generate Avro classes. This will write classes to build/generated-test-avro-java and also add that folder
1313
// as a source root. Since this is commented out by default, the generated Avro test class has been added to

docker-compose.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: '3.8'
2+
name: marklogic-kafka
3+
4+
services:
5+
6+
marklogic:
7+
image: "marklogicdb/marklogic-db:11.1.0-centos-1.1.0"
8+
platform: linux/amd64
9+
environment:
10+
- INSTALL_CONVERTERS=true
11+
- MARKLOGIC_INIT=true
12+
- MARKLOGIC_ADMIN_USERNAME=admin
13+
- MARKLOGIC_ADMIN_PASSWORD=admin
14+
volumes:
15+
- ./docker/marklogic/logs:/var/opt/MarkLogic/Logs
16+
ports:
17+
- "8000-8002:8000-8002"
18+
- "8018-8019:8018-8019"
19+
20+
# Copied from https://docs.sonarsource.com/sonarqube/latest/setup-and-upgrade/install-the-server/#example-docker-compose-configuration .
21+
sonarqube:
22+
image: sonarqube:10.3.0-community
23+
depends_on:
24+
- postgres
25+
environment:
26+
SONAR_JDBC_URL: jdbc:postgresql://postgres:5432/sonar
27+
SONAR_JDBC_USERNAME: sonar
28+
SONAR_JDBC_PASSWORD: sonar
29+
volumes:
30+
- sonarqube_data:/opt/sonarqube/data
31+
- sonarqube_extensions:/opt/sonarqube/extensions
32+
- sonarqube_logs:/opt/sonarqube/logs
33+
ports:
34+
- "9000:9000"
35+
36+
postgres:
37+
image: postgres:15-alpine
38+
environment:
39+
POSTGRES_USER: sonar
40+
POSTGRES_PASSWORD: sonar
41+
volumes:
42+
- postgresql:/var/lib/postgresql
43+
- postgresql_data:/var/lib/postgresql/data
44+
45+
volumes:
46+
sonarqube_data:
47+
sonarqube_extensions:
48+
sonarqube_logs:
49+
postgresql:
50+
postgresql_data:

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mlRestPort=8018
1919
mlTestRestPort=8019
2020
mlAppName=kafka-test
2121
mlUsername=admin
22-
mlPassword=changeme-in-gradle-local.properties
22+
mlPassword=admin
2323
mlContentForestsPerHost=2
2424

2525
# For inserting new authors during manual testing; set this to a comma-delimited string of numbers
@@ -28,5 +28,5 @@ authorIds=
2828

2929
# For Sonar analysis; set systemProp.sonar.login in gradle-local.properties or via -D when running gradlew
3030
systemProp.sonar.host.url=http://localhost:9000
31-
systemProp.sonar.projectKey=marklogic-kafka
32-
systemProp.sonar.login=
31+
systemProp.sonar.token=<Replace With Your Sonar Token>
32+
systemProp.sonar.projectKey=marklogic-kafka-connector

0 commit comments

Comments
 (0)