Skip to content

Commit 82da3eb

Browse files
committed
Added WoT agent with helm chart for testing.
1 parent 3476f82 commit 82da3eb

File tree

14 files changed

+588
-0
lines changed

14 files changed

+588
-0
lines changed

build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,31 @@ subprojects {
1818
testImplementation("io.mockk:mockk:1.13.13")
1919
}
2020

21+
22+
23+
tasks.register<Jar>("sourcesJar") {
24+
archiveClassifier.set("sources")
25+
from(sourceSets.main.get().allSource)
26+
dependsOn("classes")
27+
}
28+
29+
tasks.register<Jar>("javadocJar") {
30+
archiveClassifier.set("javadoc")
31+
from(tasks.javadoc)
32+
dependsOn("javadoc")
33+
}
34+
35+
artifacts {
36+
add("archives", tasks["sourcesJar"])
37+
add("archives", tasks["javadocJar"])
38+
}
39+
2140
publishing {
2241
publications {
2342
create<MavenPublication>("mavenKotlin") {
2443
from(components["java"])
44+
artifact(tasks["sourcesJar"])
45+
artifact(tasks["javadocJar"])
2546
artifactId = project.name
2647
}
2748
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
2+
import org.springframework.boot.gradle.tasks.bundling.BootJar
3+
4+
plugins {
5+
kotlin("plugin.spring") version "1.9.10"
6+
id("org.springframework.boot") version "3.1.5" // Use the latest compatible version
7+
id("io.spring.dependency-management") version "1.1.3"
8+
id("com.citi.helm") version "2.2.0"
9+
id("com.citi.helm-publish") version "2.2.0"
10+
}
11+
12+
dependencies {
13+
api(project(":kotlin-wot-binding-http"))
14+
api(project(":kotlin-wot-binding-websocket"))
15+
api(project(":kotlin-wot-binding-mqtt"))
16+
api(project(":kotlin-wot-spring-boot-starter"))
17+
api(project(":kotlin-wot-lmos-protocol"))
18+
api("ai.ancf.lmos:arc-spring-boot-starter:0.111.0")
19+
implementation("ai.ancf.lmos:arc-azure-client:0.111.0")
20+
}
21+
22+
tasks.named<Test>("test") {
23+
enabled = false
24+
}
25+
26+
tasks.withType<BootJar> {
27+
mainClass.set("integration.AgentApplicationKt")
28+
}
29+
30+
tasks.named<BootBuildImage>("bootBuildImage") {
31+
if (project.hasProperty("REGISTRY_URL")) {
32+
val registryUrl = getProperty("REGISTRY_URL")
33+
val registryUsername = getProperty("REGISTRY_USERNAME")
34+
val registryPassword = getProperty("REGISTRY_PASSWORD")
35+
val registryNamespace = getProperty("REGISTRY_NAMESPACE")
36+
37+
imageName.set("$registryUrl/$registryNamespace/wot-agent:0.1.0-SNAPSHOT")
38+
publish = true
39+
docker {
40+
publishRegistry {
41+
url.set(registryUrl)
42+
username.set(registryUsername)
43+
password.set(registryPassword)
44+
}
45+
}
46+
} else {
47+
imageName.set("${rootProject.name}:${project.version}")
48+
publish = false
49+
}
50+
}
51+
52+
helm {
53+
charts {
54+
create("main") {
55+
chartName.set("${project.name}-chart")
56+
chartVersion.set("${project.version}")
57+
sourceDir.set(file("src/main/helm"))
58+
}
59+
}
60+
}
61+
62+
tasks.register("helmPush") {
63+
description = "Push Helm chart to OCI registry"
64+
group = "helm"
65+
dependsOn(tasks.named("helmPackageMainChart"))
66+
67+
doLast {
68+
val registryUrl = getProperty("REGISTRY_URL")
69+
val registryUsername = getProperty("REGISTRY_USERNAME")
70+
val registryPassword = getProperty("REGISTRY_PASSWORD")
71+
val registryNamespace = getProperty("REGISTRY_NAMESPACE")
72+
73+
helm.execHelm("registry", "login") {
74+
option("-u", registryUsername)
75+
option("-p", registryPassword)
76+
args(registryUrl)
77+
}
78+
79+
helm.execHelm("push") {
80+
args(tasks.named("helmPackageMainChart").get().outputs.files.singleFile.toString())
81+
args("oci://$registryUrl/$registryNamespace")
82+
}
83+
84+
helm.execHelm("registry", "logout") {
85+
args(registryUrl)
86+
}
87+
}
88+
}
89+
90+
fun getProperty(propertyName: String) = System.getenv(propertyName) ?: project.findProperty(propertyName) as String
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kotlin.code.style=official
2+
3+
chartName=wot-agent
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v2
2+
name: ${chartName}
3+
description: The WoT Sample Agent
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: ${chartVersion}
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: ${projectVersion}
25+
home: https://github.com/eclipse-lmos/lmos-wot-agents
26+
keywords:
27+
- lmos
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "wot-agent.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "wot-agent.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "wot-agent.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "wot-agent.labels" -}}
37+
helm.sh/chart: {{ include "wot-agent.chart" . }}
38+
{{ include "wot-agent.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "wot-agent.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "wot-agent.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "wot-agent.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "wot-agent.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
63+
64+
{{/*
65+
Create Docker secrets for pulling images from a private container registry.
66+
*/}}
67+
{{- define "imagePullSecret" }}
68+
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
69+
{{- end }}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "wot-agent.fullname" . }}
5+
labels:
6+
{{- include "wot-agent.labels" . | nindent 4 }}
7+
wot-agent: "true"
8+
spec:
9+
{{- if not .Values.autoscaling.enabled }}
10+
replicas: {{ .Values.replicaCount }}
11+
{{- end }}
12+
selector:
13+
matchLabels:
14+
{{- include "wot-agent.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
{{- with .Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "wot-agent.labels" . | nindent 8 }}
23+
app: {{ include "wot-agent.fullname" . }} # Adding app label for istio
24+
version: {{ .Chart.AppVersion | quote }} # Adding version label for istio
25+
{{- with .Values.podLabels }}
26+
{{- toYaml . | nindent 8 }}
27+
{{- end }}
28+
spec:
29+
{{- with .Values.imagePullSecrets }}
30+
imagePullSecrets:
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
33+
securityContext:
34+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
35+
containers:
36+
- name: {{ .Chart.Name }}
37+
securityContext:
38+
{{- toYaml .Values.securityContext | nindent 12 }}
39+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
40+
imagePullPolicy: Always
41+
ports:
42+
- name: http
43+
containerPort: {{ .Values.service.port }}
44+
protocol: TCP
45+
livenessProbe:
46+
{{- toYaml .Values.livenessProbe | nindent 12 }}
47+
readinessProbe:
48+
{{- toYaml .Values.readinessProbe | nindent 12 }}
49+
resources:
50+
{{- toYaml .Values.resources | nindent 12 }}
51+
{{- with .Values.volumeMounts }}
52+
volumeMounts:
53+
{{- toYaml . | nindent 12 }}
54+
{{- end }}
55+
{{- with .Values.volumes }}
56+
volumes:
57+
{{- toYaml . | nindent 8 }}
58+
{{- end }}
59+
{{- with .Values.nodeSelector }}
60+
nodeSelector:
61+
{{- toYaml . | nindent 8 }}
62+
{{- end }}
63+
{{- with .Values.affinity }}
64+
affinity:
65+
{{- toYaml . | nindent 8 }}
66+
{{- end }}
67+
{{- with .Values.tolerations }}
68+
tolerations:
69+
{{- toYaml . | nindent 8 }}
70+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "wot-agent.fullname" . }}
5+
labels:
6+
{{- include "wot-agent.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: {{ .Values.service.port }}
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "wot-agent.selectorLabels" . | nindent 4 }}

0 commit comments

Comments
 (0)