Skip to content

Commit

Permalink
Update to Spring Boot 3.2.3
Browse files Browse the repository at this point in the history
Http Interface Clients, Spring Java Code Formatter, Maven wrapper, Readme.md, docker-compose, GitHub Actions, new Buildpack BaseImage (patched), and Virtual Threads
  • Loading branch information
patbaumgartner committed Mar 17, 2024
1 parent 88624a0 commit 96a596f
Show file tree
Hide file tree
Showing 22 changed files with 802 additions and 778 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven-docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ jobs:
uses: docker/[email protected]
with:
push: true
tags: patbaumgartner/run:base-cnb
tags: patbaumgartner/builder-jammy-base:latest
file: Dockerfile.base-cnb

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: maven

Expand All @@ -66,7 +66,7 @@ jobs:
mvn spring-boot:build-image \
--batch-mode --no-transfer-progress \
-Dspring-boot.build-image.imageName=${{ steps.meta.outputs.tags }} \
-Dspring-boot.build-image.runImage=patbaumgartner/run:base-cnb \
-Dspring-boot.build-image.runImage=patbaumgartner/builder-jammy-base:latest \
-Dspring-boot.build-image.publish=true \
-DCI_REGISTRY=https://index.docker.io/v1/ \
-DCI_REGISTRY_USER=${{ secrets.DOCKER_USERNAME }} \
Expand Down
Binary file modified .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
20 changes: 2 additions & 18 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
# 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
#
# https://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.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Empty file removed .springjavaformatconfig
Empty file.
12 changes: 6 additions & 6 deletions Dockerfile.base-cnb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
FROM paketobuildpacks/run:base-cnb
FROM paketobuildpacks/run-jammy-base:latest

USER root

## Idea from: https://blog.adoptopenjdk.net/2021/01/prerequisites-for-font-support-in-adoptopenjdk/
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
wget \
fontconfig \
wget \
fontconfig \
&& rm -rf /var/lib/apt/lists/*

# Install Noto Emoji Manually
RUN mkdir -p /usr/share/fonts/truetype/noto \
&& cd /usr/share/fonts/truetype/noto \
&& wget https://github.com/googlefonts/noto-emoji/raw/9a5261d871451f9b5183c93483cbd68ed916b1e9/fonts/NotoEmoji-Regular.ttf \
&& fc-cache -fv
&& cd /usr/share/fonts/truetype/noto \
&& wget https://github.com/googlefonts/noto-emoji/raw/9a5261d871451f9b5183c93483cbd68ed916b1e9/fonts/NotoEmoji-Regular.ttf \
&& fc-cache -fv

USER cnb
8 changes: 4 additions & 4 deletions HELP.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Getting Started

### Reference Documentation
## Reference Documentation

For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/html/#build-image)

* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.2.3/maven-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.2.3/maven-plugin/reference/html/#build-image)
44 changes: 14 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

# Lovebox Telegram Sender

The app allows sending messages via Telegram Bot to a single Lovebox instance. Text messages and photos with captions
are supported. Other message types (e.g. Stickers, Audio, etc.) will lead to a default message.
The app allows you to send messages to a single instance of Lovebox via Telegram Bot. Text messages and captioned photos are supported. Other message types (e.g. stickers, audio, etc.) will result in a standard message.

## Application Setup

To set up the app, a few IDs and values need to be retrieved from the Lovebox API. The following curl commands help to find
the needed data on an existing account. Make sure you have set up your account via the Android or iOS app already.
To set up the application, you will need to retrieve some IDs and values from the Lovebox API. The following curl commands will help you to on an existing account. Make sure you have already set up your account using the Android or iOS app.

### Login with Password

Log in with a password to retrieve the authorization token for the following request.
Log in with a password to retrieve the authorisation token for the following request.

```bash
curl --location --request POST 'https://app-api.loveboxlove.com/v1/auth/loginWithPassword' \
Expand All @@ -36,7 +34,7 @@ curl --location --request POST 'https://app-api.loveboxlove.com/v1/auth/loginWit

### Me Request with the Authorization Token

Use the token above to make the "Me Request" to find the configuration needed details.
Use the token above to make a 'Me Request' to find the configuration details you need.

```bash
curl --location --request POST 'https://app-api.loveboxlove.com/v1/graphql' \
Expand Down Expand Up @@ -137,16 +135,13 @@ curl --location --request POST 'https://app-api.loveboxlove.com/v1/graphql' \

### Setting up a Telegram Bot

To create a chatbot on Telegram, you need to contact the [@BotFather](https://telegram.me/BotFather), which is a bot
used to create other bots.
To create a chatbot on Telegram, you need to contact the [@BotFather](https://telegram.me/BotFather), who is a bot which is used to create other bots.

The command you need is `/newbot` which leads to the next steps to create your bot. Follow the instructions and get the
bot `username`, and `token`.
The command you need is `/newbot`, which will take you through the next steps to create your bot. Follow the instructions and get the bot `username` and `token`.

### Adjusting SpringBoot's application.properties

Running the app from the source needs adjustments according to your settings. Adjusting the `application.properties` in
the sources or passing them as Java options or CLI arguments to the app.
Running the application from source requires customisation according to your settings. Adjust the `application.properties' in the sources or pass it as Java options or CLI arguments to the application.

```properties
# Lovebox Login
Expand All @@ -164,8 +159,7 @@ bot.token=4072971853:ABEojZ42uNA6YYn_c7DF8RH0UOorqXuveSQ

### Setting Environment Variables e.g. for Docker

The following snippet can be passed as `.env` and read by the `docker-compose.yml` or used to be passed directly to
the `docker run` command.
The following snippet can be passed as `.env` and read by `docker-compose.yml`, or used to pass directly to the the `docker run` command.

```bash
# Lovebox Login
Expand Down Expand Up @@ -208,39 +202,29 @@ mvn spring-boot:build-image \

### Fixing Known Issues with Missing Fonts

Since the app uses fonts, we need to make sure that fonts are part of the docker container. The containers produced
above throw an exception when using
them `java.lang.NullPointerException: Cannot load from short array because "sun.awt.FontConfiguration.head" is null`
Since the application uses fonts, we need to make sure that fonts are part of the Docker container. The containers created above will throw an exception if they are `java.lang.NullPointerException`: Cannot load from short array because `sun.awt.FontConfiguration.head` is null.

[Andreas Ahlensdorf](https://github.com/aahlenst) describes nicely the font problem in his blog post [Prerequisites for
Font Support in AdoptOpenJDK](https://blog.adoptopenjdk.net/2021/01/prerequisites-for-font-support-in-adoptopenjdk/).
[Andreas Ahlensdorf](https://github.com/aahlenst) describes nicely the font problem in his blog post [Prerequisites for Font Support in AdoptOpenJDK](https://blog.adoptopenjdk.net/2021/01/prerequisites-for-font-support-in-adoptopenjdk/).

After more research, it seems that the only solution to add fonts to the build pack base image is to create an OCI run
image by extending the base one. See the `Dockerfile.`base-cnb` file and how a patch with the additional font packages
might look like.
After further research, it seems that the only way to add fonts to the build pack base image is to create an OCI run image by extending the base image. See the `Dockerfile.base-cnb` file and what a patch with the additional font packages might look like.

Build the `runImage` locally with the following command.

```bash
docker build --no-cache -f Dockerfile.base-cnb -t patbaumgartner/run:base-cnb .
```

Since we run the pull policy in the `mvn spring-boot:build-image` command with IF_NOT_PRESENT, we need to make sure that
the newest version of the builder is locally available. Finally, pass to the `spring-boot-maven-plugin` the `runImage`
to build the docker container containing the fonts.
Since we are running the pull policy with `IF_NOT_PRESENT` in the `mvn spring-boot:build-image` command, we need to make sure that the latest version of the builder is available locally. Finally, pass the `runImage` to the `spring-boot-maven-plugin` to create the docker container containing the fonts.

```bash
mvn spring-boot:build-image \
--batch-mode \
--no-transfer-progress \
-Dspring-boot.build-image.imageName='patbaumgartner/${project.artifactId}:${project.version}' \
-Dspring-boot.build-image.runImage=patbaumgartner/run:base-cnb \
-Dspring-boot.build-image.runImage=patbaumgartner/builder-jammy-base:latest \
-Dspring-boot.build-image.pullPolicy=IF_NOT_PRESENT
```

## Credits

Reverse engineering (unpinning certificates) was done with [APKLab](https://github.com/APKLab/APKLab) and the
[Lovebox APK](https://www.apkmonk.com/app/love.lovebox.loveboxapp/) provided by [apkmonk](https://www.apkmonk.com). Postman
was used to capture the REST calls from the mobile app. The article [Capturing Http Requests](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/)
covers everything needed. After a Postman update, [new certs](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/#troubleshooting-certificate-issues) need to be installed.
Reverse engineering (unpinning certificates) was done using [APKLab](https://github.com/APKLab/APKLab) and the [Lovebox APK](https://www.apkmonk.com/app/love.lovebox.loveboxapp/) provided by [apkmonk](https://www.apkmonk.com). Postman was used to capture the REST calls from the mobile application. The article [Capturing Http Requests](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/) covers everything you need to know. After updating Postman, [new certs](https://learning.postman.com/docs/sending-requests/capturing-request-data/capturing-http-requests/#troubleshooting-certificate-issues) need to be installed.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.8"

services:
lovebox-telegram-sender:
image: patbaumgartner/lovebox-telegram-sender:0.0.1-SNAPSHOT
image: lovebox-telegram-sender:0.1.0-SNAPSHOT
container_name: lovebox-telegram-sender
env_file:
- ./.env
- ./.env
Loading

0 comments on commit 96a596f

Please sign in to comment.