Skip to content

Commit

Permalink
Build a container image with GraalVM - profile "deepseek" is enabled …
Browse files Browse the repository at this point in the history
…by default
  • Loading branch information
alexandreroman committed Jan 31, 2025
1 parent 4f8580f commit 5740464
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 28 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Build and deploy

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

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

env:
JAVA_VERSION: 21

jobs:
test-app:
runs-on: ubuntu-24.04
outputs:
imageName: ${{ steps.image.outputs.name }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-java@v4
with:
distribution: liberica
java-version: ${{ env.JAVA_VERSION }}
cache: maven
- name: Test app
run: ./mvnw -B test
- name: Get image name
id: image
run: |
sudo apt-get install -y libxml2-utils
./mvnw -q -B help:effective-pom -Doutput=pom-effective.xml
CNB_IMAGE=`xmllint --xpath "//*[local-name()='execution']//*[local-name()='image']/*[local-name()='name']/text()" pom-effective.xml | head -1`
echo "name=$CNB_IMAGE" >> "$GITHUB_OUTPUT"
build-image:
needs:
- test-app
strategy:
matrix:
os:
- ubuntu-24.04
- ubuntu-24.04-arm
runs-on: ${{ matrix.os }}
steps:
- uses: buildpacks/github-actions/[email protected]
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-java@v4
with:
distribution: liberica
java-version: ${{ env.JAVA_VERSION }}
cache: maven
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
run: |
./mvnw -Pnative -DskipTests -B spring-boot:build-image
- name: Deploy image
run: |
CNB_TAG="linux-`dpkg --print-architecture`"
CNB_IMAGE=${{ needs.test-app.outputs.imageName }}
docker tag $CNB_IMAGE:latest $CNB_IMAGE:$CNB_TAG
docker push $CNB_IMAGE:$CNB_TAG
package-image:
needs:
- test-app
- build-image
runs-on: ubuntu-24.04
steps:
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Package multi-arch image
run: |
CNB_IMAGE=${{ needs.test-app.outputs.imageName }}
docker manifest create $CNB_IMAGE:latest --amend $CNB_IMAGE:linux-arm64 --amend $CNB_IMAGE:linux-amd64
docker manifest push $CNB_IMAGE:latest
trigger-gitops:
needs:
- package-image
runs-on: ubuntu-24.04
env:
GH_TOKEN: ${{ secrets.GITOPS_TOKEN }}
TARGET_OWNER: alexandreroman
TARGET_REPO: rpilab
TARGET_WORKFLOW: gitops.yaml
steps:
- name: trigger-gitops
run: |
curl -L -X POST -H "Accept: application/vnd.github+json" \
-H "Authorization: token $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$TARGET_OWNER/$TARGET_REPO/actions/workflows/$TARGET_WORKFLOW/dispatches \
-d '{"ref":"main"}'
28 changes: 0 additions & 28 deletions .github/workflows/build.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<configuration>
<!-- This is the profile we want to enable when building a native-image. -->
<!-- You still have to "activate" this profile at runtime with "SPRING_PROFILES_ACTIVE=x". -->
<profiles>deepseek</profiles>
</configuration>
</execution>
</executions>
<configuration>
<image>
<name>ghcr.io/alexandreroman/html-assistant</name>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/broadcom/tanzu/demos/htmlassistant/AIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package com.broadcom.tanzu.demos.htmlassistant;

import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -31,4 +34,12 @@ ChatClient chatClientOpenAI(ChatClient.Builder chatClientBuilder,
.defaultSystem(systemPrompt)
.build();
}

@Bean
CommandLineRunner onStart(ChatModel chatModel) {
return args -> {
final var logger = LoggerFactory.getLogger(AIConfig.class);
logger.atInfo().log("Using chat model: {}", chatModel);
};
}
}

0 comments on commit 5740464

Please sign in to comment.