Skip to content

Commit

Permalink
Solr package for Splainer. (#97)
Browse files Browse the repository at this point in the history
The Splainer webapp wrapped up as a Solr package.   There are still some manual steps on the release process to be worked out.
  • Loading branch information
epugh authored Aug 7, 2023
1 parent 46cded0 commit 17cc4d1
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ deploy.sh
*.swp

docker-compose.override.yml

solr-splainer-package/target
solr-splainer-package/repo/*.jar
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Version numbers correspond to `package.json` version. Follows the _major.minor.bugfix_ naming pattern.

# 2.20.1 (2023-08-07)
- Introduce versioning to the Splainer project. The http://splainer.io website has been around for years, and we've just pushed changes as they arrive. We are now introducing a changelog process, and labeling the current state as "2.20.1" to match the commit https://github.com/o19s/splainer/commit/46cded05908e5d06ebee03f2cccaf836c60f9438#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519.
- Splainer.io can NOW be deployed into your Solr environment using [Solr Packages](https://solr.apache.org/guide/solr/latest/configuration-guide/package-manager.html). See the package [README.md](./solr-splainer-package/README.md) for more details. https://github.com/o19s/splainer/pull/97.
88 changes: 88 additions & 0 deletions solr-splainer-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Splainer Solr Plugin

This project lets you install Splainer into your Solr as a plugin.
You can access it via http://localhost:8983/v2/splainer and avoids common CORS and other network problems that you might encounter using the hosted http://splainer.io site.


## Building and installation

This plugin requires a manual custom step added after you run the main `grunt dist` process in the Splainer application that builds a complete webapp in the `../dist` directory. _This should be automated someday ;-( _.

1. Copy the following Javascript and paste it at the bottom of `/dist/scripts/app.js`:

```
/* Override default config values for talking to Solr
* JSONP->GET
* */
angular.module('o19s.splainer-search')
.value('defaultSolrConfig', {
sanitize: true,
highlight: true,
debug: true,
numberOfRows: 10,
escapeQuery: true,
apiMethod: 'GET'
});
```

1. Export the private key:

```
export SOLR_PACKAGE_SIGNING_PRIVATE_KEY_PATH=~/ssh/solr-private-key.pem
```

1. Build the package:

```
mvn package
```

1. Now for testing, host the solr-splainer-package/repo locally:

First copy the generated jar into the repo directory:

```
cp target/solr-splainer-package* repo/
```

```
python -m http.server
```

1. In a Run Solr and install the package:

tar -xf solr-9.3.0.tgz; cd solr-9.3.0/
bin/solr start -c -e films -Denable.packages=true
bin/solr package add-repo splainer-dev "http://localhost:8000/repo/"
bin/solr package list-available
bin/solr package install solr-splainer
bin/solr package deploy solr-splainer -y -cluster

1. Navigate to http://localhost:8983/v2/splainer on the browser.

## Changes to make it work in Solr Admin UI

See [diff from main project](https://github.com/o19s/splainer/compare/main...softwaredoug:solr-splainer:main#diff-18e01ac6a833fb1b20ffbad54f0ad8834a765e766f72cccda1e56cb942864d25R30)

* Changes communication with Solr to use GET instead af JSONP, same way the Admin UI communicates with Solr










## Who?

Based on Another Hack by [Doug Turnbull](http://softwaredoug.com) https://github.com/softwaredoug/solr-splainer. This works if you can't use Solr Packages in your environment.

Created by [OpenSource Connections](http://opensourceconnections.com).

Thanks to all the [community contributors](https://github.com/o19s/splainer/graphs/contributors) for finding bugs and sharing fixes!.

## License

Released under [Apache 2](LICENSE.txt)
112 changes: 112 additions & 0 deletions solr-splainer-package/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.o19s.splainer</groupId>
<artifactId>solr-splainer-package</artifactId>

<version>2.20.1</version>

<url>https://github.com/o19s/splainer/solr-splainer-package</url>

<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>9.3.0</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>utf-8</encoding>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<targetPath>${basedir}/target/classes</targetPath>
<directory>../dist</directory>
</resource>
<resource>
<targetPath>${basedir}/target/classes</targetPath>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<configuration>
<executable>python</executable>
<workingDirectory>.</workingDirectory>
<arguments>
<argument>release.py</argument>
<argument>${project.artifactId}</argument>
<argument>${project.version}</argument>
</arguments>

</configuration>
<id>python-build</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
53 changes: 53 additions & 0 deletions solr-splainer-package/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import sys
import os
import json
import datetime

artifact_name = sys.argv[1]
version = sys.argv[2]
if os.getenv("SOLR_PACKAGE_SIGNING_PRIVATE_KEY_PATH") == None:
raise Exception("Please add an environment variable SOLR_PACKAGE_SIGNING_PRIVATE_KEY_PATH to point to your private key (.pem) file used for signing the package artifacts.")
sys.exit(1)

private_key_file = os.getenv("SOLR_PACKAGE_SIGNING_PRIVATE_KEY_PATH")

if (os.path.isfile(private_key_file) == False):
raise Exception("SOLR_PACKAGE_SIGNING_PRIVATE_KEY_PATH points to non-existent private key (.pem) file used for signing the package artifacts.")
sys.exit(1)

# Generate a publickey.der file
os.popen("openssl rsa -in "+private_key_file+" -outform DER -pubout -out repo/publickey.der")

print("Signing artifact : target/"+artifact_name+"-"+version+".jar")

# Sign the artifact using the private key
with os.popen("openssl dgst -sha1 -sign "+private_key_file+" target/"+artifact_name+"-"+version+".jar | openssl enc -base64") as f:
signature = "".join(f.readlines()).replace("\n", "")
print("Signed artifacts with: " + signature)

# Update the repo/repository.json with the released artifact
repository = json.load(open("repo/repository.json"))

# FORMAT:
# {
# "version": "1.0.0",
# "date": "2019-12-13",
# "artifacts": [
# {
# "url": "question-answering-1.0.jar",
# "sig": "Hau46QF4424qUDSMwRYa/sO/L4Hfbdr6jLQDEsbJpXJdR6jPmd9v92mAU8wSMO/riVk/Zc4oovCCu2PRWnz7sA=="
# }
# ]
# }

release = {}
release["version"] = version
release["date"] = str(datetime.date.today())
release["artifacts"] = [{"url": artifact_name + "-" + version + ".jar", "sig": signature}]

repository[0]["versions"].append(release)

json.dump(repository, open('repo/repository.json', 'w'), indent=2)

print(repository)
Binary file added solr-splainer-package/repo/publickey.der
Binary file not shown.
18 changes: 18 additions & 0 deletions solr-splainer-package/repo/repository.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "solr-splainer",
"description": "Splainer for Solr",
"versions": [
{
"version": "2.20.1",
"date": "2023-08-07",
"artifacts": [
{
"url": "solr-splainer-package-2.20.1.jar",
"sig": "fKkR6CciTnNpMNBhXbtAdZfYxlmNFc2UuE64ljJ4B9f/Hj3Of5U6LrTj7Y8PfrioO6QF8DqXyd773WmZ9ncnWw=="
}
]
}
]
}
]
Loading

0 comments on commit 17cc4d1

Please sign in to comment.