Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ jobs:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v6
with:
java-version: 11
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v5
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v5
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
working-directory: launcher
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
128 changes: 128 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Build Docker image for new Java releases

on:
# Weekly check for new Temurin releases (every Monday at 04:17 UTC)
schedule:
- cron: "17 4 * * 1"

# Allow manual trigger
workflow_dispatch:
push:
branches:
- "main"

permissions:
contents: read
packages: write

env:
DOCKER_IMAGE: fathzer/db-backup

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7

# ------------------------------------------------------------
# 1. Set up JDK 21 and build the scanner
# ------------------------------------------------------------
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: 21
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v5
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build new-java-release-scanner
working-directory: new-java-release-scanner
run: mvn -B -q package

# ------------------------------------------------------------
# 2. Find the launcher version and target Java version on this branch
# ------------------------------------------------------------
- name: Get launcher version and Java version
id: app-version
run: |
APP_VERSION=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version -f launcher/pom.xml)
JAVA_VERSION=$(mvn -q -DforceStdout help:evaluate -Dexpression=maven.compiler.target -f launcher/pom.xml)
echo "version=$APP_VERSION" >> "$GITHUB_OUTPUT"
echo "javaVersion=$JAVA_VERSION" >> "$GITHUB_OUTPUT"
echo "Launcher version: $APP_VERSION"
echo "Target Java version: $JAVA_VERSION"

# ------------------------------------------------------------
# 3. Find the Java tag to build (or skip if already published)
# ------------------------------------------------------------
- name: Scan Docker Hub for new Java version
id: scan
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
run: |
set -euo pipefail
SCANNER_JAR="new-java-release-scanner/target/docker-java-version-scanner-1.0.0.jar"
RESULT=$(java -jar "$SCANNER_JAR" "${{ steps.app-version.outputs.version }}" "${{ steps.app-version.outputs.javaVersion }}" "${DOCKER_IMAGE}")
echo "$RESULT"
SHOULD_BUILD=$(echo "$RESULT" | jq -r '.shouldBuild')
echo "shouldBuild=$SHOULD_BUILD" >> "$GITHUB_OUTPUT"
if [ "$SHOULD_BUILD" = "true" ]; then
BASE_IMAGE=$(echo "$RESULT" | jq -r '.baseImage')
echo "baseImage=$BASE_IMAGE" >> "$GITHUB_OUTPUT"
{
echo "tags<<EOF"
echo "$RESULT" | jq -r '.tags[]' | sed "s|^|${DOCKER_IMAGE}:|"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi

# ------------------------------------------------------------
# 4. Download the launcher jar from Maven Central
# (fails if the version is not published yet)
# ------------------------------------------------------------
- name: Download jar from Maven Central
if: steps.scan.outputs.shouldBuild == 'true'
run: |
set -euo pipefail
VERSION="${{ steps.app-version.outputs.version }}"
JAR_URL="https://repo1.maven.org/maven2/com/fathzer/jdbbackup-docker/${VERSION}/jdbbackup-docker-${VERSION}.jar"
echo "Downloading $JAR_URL"
mkdir -p launcher/target
curl -fSL -o launcher/target/jdbbackup.jar "$JAR_URL"

# ------------------------------------------------------------
# 5. Build and push the Docker image
# ------------------------------------------------------------
- name: Login to Docker Hub
if: steps.scan.outputs.shouldBuild == 'true'
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Setup Buildx
if: steps.scan.outputs.shouldBuild == 'true'
uses: docker/setup-buildx-action@v4

- name: Build and push image
if: steps.scan.outputs.shouldBuild == 'true'
uses: docker/build-push-action@v7
with:
context: .
push: true
build-args: |
JAVA_BASE_IMAGE=${{ steps.scan.outputs.baseImage }}
JAR_FILE=launcher/target/jdbbackup.jar
tags: ${{ steps.scan.outputs.tags }}
labels: |
org.opencontainers.image.title=db-backup
org.opencontainers.image.version=${{ steps.app-version.outputs.version }}
org.opencontainers.image.base.name=${{ steps.scan.outputs.baseImage }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
target/
bin/
.settings/
dependency-reduced-pom.xml
/.classpath
/.project
.classpath
.project
.vscode/
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
FROM openjdk:11-jre
ARG JAVA_BASE_IMAGE=eclipse-temurin:25.0.4_7-jre
FROM ${JAVA_BASE_IMAGE}

RUN apt-get update && apt-get install -y default-mysql-client
RUN apt-get clean
RUN apt-get update && apt-get install -y default-mysql-client && apt-get clean

ENV RUN_USER jdbbackup
ENV RUN_GROUP jdbbackup
ENV RUN_USER=jdbbackup
ENV RUN_GROUP=jdbbackup
RUN groupadd -r ${RUN_GROUP} && useradd -g ${RUN_GROUP} -m -s /bin/bash ${RUN_USER}

WORKDIR /home/${RUN_USER}

COPY target/jdbbackup.jar .
ARG JAR_FILE
COPY ${JAR_FILE} jdbbackup.jar

RUN chown -R ${RUN_USER}:${RUN_USER} .
USER ${RUN_USER}
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ A ready to use docker container, based on [jdbbackup-core](https://github.com/jd
### Without Docker
This application requires Java11+.

The [artifact deployed in Maven central](https://repo1.maven.org/maven2/com/fathzer/jdbbackup-docker/1.0.0/jdbbackup-docker-1.0.0.jar) is a runnable jar.
Launch it with ```java -jar jdbbackup-docker-1.0.0.jar config.json``` where *config.json* is the configuration file ([see below](#configuration-file)) or set the environment variable *TASKS_PATH* to the path of the configuration file and launch it with ```java -jar jdbbackup-docker-1.0.0.jar```. You may also leave *TASKS_PATH* unset, its default value is *tasks.json*.
The [artifact deployed in Maven central](https://repo1.maven.org/maven2/com/fathzer/jdbbackup-docker/1.1.0/jdbbackup-docker-1.1.0.jar) is a runnable jar.
Launch it with ```java -jar jdbbackup-docker-1.1.0.jar config.json``` where *config.json* is the configuration file ([see below](#configuration-file)) or set the environment variable *TASKS_PATH* to the path of the configuration file and launch it with ```java -jar jdbbackup-docker-1.1.0.jar```. You may also leave *TASKS_PATH* unset, its default value is *tasks.json*.

If you want to include this application in a Java program, the main class is *com.fathzer.jdbbackup.cron.Main*.

Expand Down Expand Up @@ -96,6 +96,18 @@ The default configuration logs to the console, rejecting entries below *info* le
If you want to change logback configuration, please have a look at [the logback manual](https://logback.qos.ch/manual/configuration.html).

# Developer notes
- How to build the Docker image?: ```mvn package -Pdocker```
- Build the jar:
```bash
cd launcher
mvn package -DskipTests
```
- Build the Docker image (from the repository root):

```bash
docker build -t fathzer/db-backup:1.1.0-jre-25.0.4 --build-arg JAVA_BASE_IMAGE=eclipse-temurin:25.0.4_7-jre --build-arg JAR_FILE=launcher/target/jdbbackup.jar .
```
The `JAVA_BASE_IMAGE` build arg sets the base JRE image. The `JAR_FILE` build arg points to the jar relative to the repository root (the Docker context).

> **Warning**: do not push the built image to Docker Hub unless you're sure about the tag format; it may not follow the naming convention used by the official images.


59 changes: 26 additions & 33 deletions pom.xml → launcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
<parent>
<groupId>com.fathzer</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.8</version>
<version>1.1.0</version>
</parent>

<artifactId>jdbbackup-docker</artifactId>
<version>1.0.0</version>
<description>A simple java library to perform data source backup and store them in dropbox, sftp or local file</description>
<version>1.1.0</version>
<name>jdbbackup-docker</name>
<description>A launcher for jdbbackup that can be used in a docker container</description>
<scm>
<url>https://github.com/jdbbackup/jdbbackup-dropbox.git</url>
<connection>https://github.com/jdbbackup/jdbbackup-dropbox.git</connection>
<url>https://github.com/jdbbackup/jdbbackup-docker.git</url>
<connection>https://github.com/jdbbackup/jdbbackup-docker.git</connection>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.release>${maven.compiler.target}</maven.compiler.release>
<check-dependencies-java-version>${maven.compiler.target}</check-dependencies-java-version>
<sonar.organization>jdbbackup</sonar.organization>
<lombok.version>1.18.48</lombok.version>
</properties>

<profiles>
Expand All @@ -29,29 +33,6 @@
</activation>
<build>
<finalName>jdbbackup</finalName>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>fathzer/db-backup</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Expand All @@ -60,7 +41,7 @@
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>jdbbackup-core</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</dependency>
<!-- Overrides the plugin loader library defined in jdbbackup-core
It should be removed after jdbbackup-core will be updated
Expand All @@ -78,23 +59,23 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.5</version>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<version>5.14.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -110,6 +91,18 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.fathzer.jdbbackup.DestinationManager.URI_PATH_SEPARATOR;

/** This a copy of the jdbbackup-core non public com.fathzer.jdbbackup.Destination class.<br>
* //TODO Maybe it should be better to prevent this copy by maling it public in jdbbackup-core
* //TODO Maybe it should be better to prevent this copy by making it public in jdbbackup-core
*/
class Destination {
private String type;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading