⚠️ This article was automatically translated by OpenAI (gpt-4-turbo-preview). It may be edited eventually, but please be aware that it may contain incorrect information at this time.
Notes on using a Private Maven Repository when deploying Java apps with TAP. Intended for use as a cache or hosting internal libraries.
Reference document is here https://docs.vmware.com/en/VMware-Tanzu-Application-Platform/1.3/tap/GUID-tanzu-build-service-tbs-workload-config.html
Installing Maven Repository
Here, we use the lightweight https://github.com/jenkins-x/bucketrepo as the Private Maven Repository
Install using Helm Chart.
helm repo add jx3 https://jenkins-x-charts.github.io/repo
helm repo update
Generate manifest with helm template command
helm template bucketrepo jx3/bucketrepo -n bucketrepo --set secrets.adminUser.username=admin --set secrets.adminUser.password=changeme > bucketrepo.yaml
Deploy bucketrepo
kubectl create ns bucketrepo
kubectl apply -n bucketrepo -f bucketrepo.yaml
Check the Pod
$ kubectl get pod -n bucketrepo
NAME READY STATUS RESTARTS AGE
bucketrepo-bucketrepo-5f8fcd86f7-xxkgz 1/1 Running 0 32s
Check the Service
$ kubectl get svc -n bucketrepo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
bucketrepo ClusterIP 10.96.131.38 <none> 80/TCP 87s
Preparing settings.xml
Here, we describe the configuration to use bucketrepo as a mirror repository in settings.xml, and set it in a Secret in the following format.
cat <<EOF > settings-xml.yaml
apiVersion: v1
kind: Secret
metadata:
name: settings-xml
type: service.binding/maven
stringData:
type: maven
settings.xml: |
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>bucketrepo</id>
<username>admin</username>
<password>changeme</password>
</server>
</servers>
<mirrors>
<mirror>
<id>bucketrepo</id>
<name>bucketrepo</name>
<url>http://bucketrepo.bucketrepo.svc.cluster.local/bucketrepo</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
EOF
Create this Secret in the namespace where the Workload is created.
kubectl apply -f settings-xml.yaml -n demo
Creating Workload
Reference the Secret with settings.xml using the buildServiceBindings
param.
tanzu apps workload apply tanzu-java-web-app \
-n demo\
--git-repo https://github.com/vmware-tanzu/application-accelerator-samples \
--git-branch main \
--sub-path tanzu-java-web-app \
--type web \
--app tanzu-java-web-app \
--param-yaml buildServiceBindings='[{"name": "settings-xml", "kind": "Secret"}]' \
--annotation autoscaling.knative.dev/minScale=1 \
-y
The first time, it takes about the same time as a normal build without a mirror repository because there is no cache in bucketrepo.
$ kubectl logs -n demo tanzu-java-web-app-build-1-build-pod -c build | grep 'BUILD SUCCESS' -B 1 -A 4
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:17 min
[INFO] Finished at: 2022-12-14T04:00:19Z
[INFO] ------------------------------------------------------------------------
Delete the Workload once to clear the cache by Build Service.
tanzu apps workload delete -n demo tanzu-java-web-app -y
Create the Workload again
tanzu apps workload apply tanzu-java-web-app \
-n demo\
--git-repo https://github.com/vmware-tanzu/application-accelerator-samples \
--git-branch main \
--sub-path tanzu-java-web-app \
--type web \
--app tanzu-java-web-app \
--param-yaml buildServiceBindings='[{"name": "settings-xml", "kind": "Secret"}]' \
--annotation autoscaling.knative.dev/minScale=1 \
-y
Even without the cache by Build Service, the build completes in 10 seconds. Fast!
$ kubectl logs -n demo tanzu-java-web-app-build-1-build-pod -c build | grep 'BUILD SUCCESS' -B 1 -A 4
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.674 s
[INFO] Finished at: 2022-12-14T04:09:05Z
[INFO] ------------------------------------------------------------------------
To use this settings.xml for testing, separate configuration on the Tekton (Pipeline) side is required.
Like this
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: maven-test-pipeline
labels:
apps.tanzu.vmware.com/pipeline: test
apps.tanzu.vmware.com/language: java
spec:
params:
- name: source-url
- name: source-revision
tasks:
- name: test
params:
- name: source-url
value: $(params.source-url)
- name: source-revision
value: $(params.source-revision)
taskSpec:
volumes:
- name: settings-xml
secret:
secretName: settings-xml
params:
- name: source-url
- name: source-revision
steps:
- name: test
image: eclipse-temurin:17
volumeMounts:
- mountPath: /opt/maven
name: settings-xml
readOnly: true
script: |-
set -ex
cd `mktemp -d`
curl -s $(params.source-url) | tar -m -xzvf -
./mvnw clean test -V -s /opt/maven/settings.xml