Skip to content

Commit

Permalink
Merge pull request #1 from penguineer/project-setup
Browse files Browse the repository at this point in the history
Set up the project
  • Loading branch information
penguineer authored Oct 29, 2024
2 parents 19215c9 + b87adb1 commit 63531df
Show file tree
Hide file tree
Showing 18 changed files with 981 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/mvnw text eol=lf
*.cmd text eol=crlf
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [penguineer]
ko_fi: penguineer
73 changes: 73 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Docker Build and Push

on:
push:
branches:
- main
tags:
- 'v*.*.*'

jobs:
build:
runs-on: ubuntu-latest

env:
IMAGE_NAME: hareairis

steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: github.event_name != 'pull_request'

- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
# Needed for correct Maven version detection
fetch-depth: 0

- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${ github.ref }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-m2-${ github.ref }}
${{ runner.os }}-m2-main
- name: Run Maven Build
run: mvn clean package

- name: Determine Docker tags
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
# 1.2.3
type=semver,pattern={{version}}
# disabled if major zero
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
# generate latest from default branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
dockerfile: ./Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
34 changes: 34 additions & 0 deletions .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Maven Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${ github.ref }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-m2-${ github.ref }}
${{ runner.os }}-m2-main
- name: Run tests
run: mvn --batch-mode --update-snapshots clean verify
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create Release

on:
push:
tags:
- 'v*.*.*'

jobs:
release:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
# Needed for correct Maven version detection
fetch-depth: 0

- name: "Generate release changelog"
id: generate-release-changelog
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
onlyLastTag: "true" # set to false if no tags exist (buggy with only one tag)
stripHeaders: "true"
stripGeneratorNotice: "true"

- name: Extract the VERSION name
id: get-version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: "Create GitHub release"
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: "${{ steps.get-version.outputs.VERSION }}"
body: "${{ steps.generate-release-changelog.outputs.changelog }}"
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

.env

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
7 changes: 7 additions & 0 deletions .mvn/wrapper/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>fr.brouillard.oss</groupId>
<artifactId>jgitver-maven-plugin</artifactId>
<version>1.9.0</version>
</extension>
</extensions>
5 changes: 5 additions & 0 deletions .mvn/wrapper/jgitver.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<configuration xmlns="http://jgitver.github.io/maven/configuration/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jgitver.github.io/maven/configuration/1.1.0 https://jgitver.github.io/maven/configuration/jgitver-configuration-v1_1_0.xsd">
<nonQualifierBranches>main</nonQualifierBranches>
</configuration>
19 changes: 19 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM eclipse-temurin:21 AS app-build

WORKDIR application

COPY target/*.jar application.jar

RUN java -Djarmode=layertools -jar application.jar extract


FROM eclipse-temurin:21

EXPOSE 8080
ENV PORT=8080

HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 CMD curl --fail http://localhost:8080/actuator/health || exit 1

WORKDIR application

COPY --from=app-build application/spring-boot-loader/ ./
COPY --from=app-build application/dependencies/ ./
COPY --from=app-build application/snapshot-dependencies/ ./
COPY --from=app-build application/application/ ./

ENTRYPOINT ["java", \
"--add-opens", "java.base/java.lang=ALL-UNNAMED", \
"--add-opens", "java.base/java.util=ALL-UNNAMED", \
"--add-opens", "java.base/sun.net=ALL-UNNAMED", \
"org.springframework.boot.loader.launch.JarLauncher"]
87 changes: 85 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,88 @@
# HareAIris

> HareAIris is a software bridge connecting RabbitMQ to the OpenAI API. It is designed to help developers integrate message-driven applications with advanced AI capabilities.
> HareAIris is a software bridge connecting RabbitMQ to the OpenAI API. It is designed to help developers integrate
> message-driven applications with advanced AI capabilities.
> The name "HareAIris" is a creative blend of "AI," "Iris," and "Hare." In mythology, Iris is the Greek goddess of the rainbow and a messenger of the gods, symbolizing communication and connection. The "Hare" element represents speed and agility, attributes often associated with rabbits. Together, "HareAIris" signifies a swift and efficient messenger that bridges the gap between RabbitMQ and OpenAI, embodying the project's core functionality.
The name "HareAIris" is a creative blend of "AI," "Iris," and "Hare." In mythology, Iris is the Greek goddess of the
rainbow and a messenger of the gods, symbolizing communication and connection. The "Hare" element represents speed and
agility, attributes often associated with rabbits. Together, "HareAIris" signifies a swift and efficient messenger that
bridges the gap between RabbitMQ and OpenAI, embodying the project's core functionality.

## Configuration

Configuration is done using environment variables:

* `PORT`: Port for the HTTP endpoint (default `8080`, only change when running locally!)
* `RMQ_HOST`: Host for RabbitMQ (default `localhost`)
* `RMQ_PORT`: Port for RabbitMQ (default `5672`)
* `RMQ_USER`: Username for RabbitMQ (default `guest`)
* `RMQ_PASSWORD`: Password for RabbitMQ (default `guest`)
* `OPENAI_API_KEY`: API key for accessing the OpenAI API
* `OPENAI_ENDPOINT`: Base URL for the OpenAI API (default `https://api.openai.com/v1`)

## Build

The build is split into two stages:

1. Packaging with [Maven](https://maven.apache.org/)
2. Building the Docker container

This means that the [Dockerfile](Dockerfile) expects one (and only one) JAR file in the target directory.
Build as follows:

```bash
mvn --batch-mode --update-snapshots clean package
docker build .
```

The whole process is coded in the [docker-publish workflow](.github/workflows/docker-build.yml) and only needs to be
executed manually for local builds.

## Run with Docker

With the configuration stored in a file `.env`, the service can be run as follows:

```bash
docker run --rm \
-p 8080:8080 \
--env-file .env \
mrtux/hareairis
```

The service does not store any state and therefore needs no mount points or other persistence.

Please make sure to pin the container to a specific version in a production environment.

## Development

Version numbers are determined with [jgitver](https://jgitver.github.io/).
If you encounter a project version `0` there is an issue with the jgitver generator.

For local execution the configuration can be provided in a `.env` file and made available using `dotenv`:

```bash
dotenv ./mvnw mn:run
```

Note that `.env` is part of the `.gitignore` and can be safely stored in the local working copy.

## Maintainers

* Stefan Haun ([@penguineer](https://github.com/penguineer))

If you like my work, please consider [sponsoring me](https://github.com/sponsors/penguineer), as this helps me to spend
more time on open source projects.

## Contributing

PRs are welcome!

If possible, please stick to the following guidelines:

* Keep PRs reasonably small and their scope limited to a feature or module within the code.
* If a large change is planned, it is best to open a feature request issue first, then link subsequent PRs to this
issue, so that the PRs move the code towards the intended feature.

## License

[MIT](LICENSE.txt) © 2024 Stefan Haun and contributors
Loading

0 comments on commit 63531df

Please sign in to comment.