I created a simple Spring Boot application using https://start.spring.io/. Now I want to use Paketo.io / Cloud Native Build Pack support of the spring-boot-maven-plugin
to build a container image and push it to the GitHub Container Registry using GitHub Actions.
My pom.xml
looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.jonashackt</groupId>
<artifactId>helloworld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>helloworld</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>15</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I successfully managed to create a Docker image using the mvn spring-boot:build-image
command inside my GitHub Actions workflow. I also successfully pushed it to the GitHub Container Registry (following this guide). Here's my build.yml
workflow:
name: publish
on: [push]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 15
uses: actions/setup-java@v1
with:
java-version: 15
- name: Build the hello-world Docker image
run: |
echo 'Login to GitHub Container Registry'
echo $CR_PAT | docker login ghcr.io -u jonashackt --password-stdin
echo 'Build a container image from our Spring Boot app using Paketo.io / Cloud Native Build Packs'
mvn spring-boot:build-image --batch-mode --no-transfer-progress
echo 'tag Paketo build image to have the right GitHub Container Registry coordinates'
docker tag helloworld:0.0.1-SNAPSHOT ghcr.io/jonashackt/helloworld:latest
docker push ghcr.io/jonashackt/helloworld:latest
env:
CR_PAT: ${{ secrets.CR_PAT }}
But the Container Registry image isn't linked to the GitHub repository. Since this has to be done with a specific OCI compliant LABEL
inside the Dockerfile
:
LABEL org.opencontainers.image.source="https://github.com/jonashackt/helloworld"
How could one configure this LABEL
using Cloud Native Build Packs / Paketo together with the spring-boot-maven-plugin
?