Failure in deploying JAVA workload to TAP due to error of accessing external Maven repository
search cancel

Failure in deploying JAVA workload to TAP due to error of accessing external Maven repository

book

Article ID: 376178

calendar_today

Updated On:

Products

VMware Tanzu Application Platform

Issue/Introduction

When deploying JAVA workload to TAP, it might fail with accessing external Maven repository as illustrated below. 

$ tanzu -n tap-java apps workload get tanzu-java-web-app
......
💬 Messages
   Workload [HealthyConditionRule]:   condition status: False, message: Error: Build 'tanzu-java-web-app-build-1' in namespace 'tap-java' failed: Error:  Container build terminated with error ERROR: failed to build: exit status 1: For more info use `kubectl logs -n tap-java tanzu-java-web-app-build-1-build-pod -c build`
   Deliverable [HealthyConditionRule]:   Unable to resolve image with tag "my.registry.com/tap/tap-packages/tanzu-java-web-app-tap-java-bundle:2b3b61d2-2f90-46a0-a7e5-f75a147293d8" to a digest: HEAD https://my.registry.com/v2/tap/tap-packages/tanzu-java-web-app-tap-java-bundle/manifests/2b3b61d2-2f90-46a0-a7e5-f75a147293d8: unexpected status code 404 Not Found (HEAD responses have no body, use GET for details)

🛶 Pods
   NAME                                   READY   STATUS       RESTARTS   AGE
   tanzu-java-web-app-build-1-build-pod   0/1     Init:Error   0          27m

To see logs: "tanzu apps workload tail tanzu-java-web-app --timestamp --since 1h"


$ kubectl logs -n tap-java tanzu-java-web-app-build-1-build-pod -c build
Timer: Builder started at 2024-08-28T08:04:52Z

Tanzu Buildpack for CA Certificates 3.9.0
  https://github.com/pivotal-cf/tanzu-ca-certificates
  Launch Helper: Contributing to layer
    Creating /layers/tanzu-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
......
  Compiled Application: Contributing to layer
    Executing mvnw --batch-mode -Dmaven.test.skip=true --no-transfer-progress package
        % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                       Dload  Upload   Total   Spent    Left  Speed
100 59925  100 59925    0     0   165k      0 --:--:-- --:--:-- --:--:--  165k     0
      Exception in thread "main" java.net.UnknownHostException: repo.maven.apache.org
        at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:229)
        at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.base/java.net.Socket.connect(Socket.java:609)
......

Cause

The TAP environment is configured to access external resource via HTTP proxy. 

Resolution

Configure HTTP proxy via build environment variable MAVEN_OPTS in workload manifest in order to access external Maven repository. For example,

$ cat workload.yml
apiVersion: carto.run/v1alpha1
kind: Workload
metadata:
  name: tanzu-java-web-app
  namespace: tap-java
  labels:
    apps.tanzu.vmware.com/workload-type: web
    app.kubernetes.io/part-of: tanzu-java-web-app
    apps.tanzu.vmware.com/has-tests: "true"
spec:
  build:
    env:
      - name: BP_JVM_VERSION
	    value: "17"
      - name: MAVEN_OPTS
	    value: "-Dhttp.proxyHost=<HTTP PROXY SERVER HOST/IP> -Dhttp.proxyPort=<HTTP PROXY SERVER PORT> -Dhttps.proxyHost=<HTTPS PROXY SERVER HOST/IP> -Dhttps.proxyPort=<HTTPS PROXY SERVER PORT>"
......

NOTE: replace the following placeholders with their respective values for the specific TAP environment.

  • <HTTP PROXY SERVER HOST/IP>
  • <HTTP PROXY SERVER PORT>
  • <HTTPS PROXY SERVER HOST/IP>
  • <HTTPS PROXY SERVER PORT>

Additional Information

Reference for setting HTTP proxy properties for JAVA application:

https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html