diff --git a/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md b/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md
index e666aba66..5d708946e 100644
--- a/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md
+++ b/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md
@@ -53,14 +53,17 @@ This example is based on the
+To use .oci config for testing locally replace the contents of Dockerfile with the contents from Dockerfile.local_oci. Then copy your ~/.oci -directory under the project root and build the Function with Fn:
+
+
+fn --verbose deploy --app hellofunction --local +fn invoke hellofunction helloaifunc ++ +Note! Do not distribute this container since it contains your OCI credentials. Use this only for local testing purposes. + +
+ Testing with curl (or copy-pasting the API Gateway deployment url to a browser):
diff --git a/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/Dockerfile.local_oci b/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/Dockerfile.local_oci new file mode 100644 index 000000000..b27deb210 --- /dev/null +++ b/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/Dockerfile.local_oci @@ -0,0 +1,21 @@ +FROM fnproject/fn-java-fdk-build:jdk17-1.0-latest as build-stage +WORKDIR /function +ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository +ADD pom.xml /function/pom.xml +RUN ["mvn", "package", "dependency:copy-dependencies", "-DincludeScope=runtime", "-DskipTests=true", "-Dmdep.prependGroupId=true", "-DoutputDirectory=target", "--fail-never"] +ADD src /function/src +RUN ["mvn", "package"] +FROM fnproject/fn-java-fdk:jre17-1.0.187 +WORKDIR /function +COPY --from=build-stage /function/target/*.jar /function/app/ +RUN echo "**** WARNING ***" +RUN echo "**** THIS CONTAINER CONTAINS OCI CREDENTIALS - DO NOT DISTRIBUTE ***" +RUN echo "Copy your OCI CLI .oci dir under this dir before running this Dockerfile " +RUN echo "OCI API KEYFILE is expected to be without any path in the config e.g. key_file = oci_api_key.pem" +ADD .oci/config / +ADD .oci/oci_api_key.pem / +RUN chmod 777 /config +RUN chmod 777 /oci_api_key.pem +RUN sed -i '/^key_file/d' /config +RUN echo "key_file = /oci_api_key.pem" >> /config +CMD ["com.example.HelloAIFunction::handleRequest"] \ No newline at end of file diff --git a/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java b/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java index 46b2a4ece..fc84313f5 100644 --- a/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java +++ b/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/files/src/main/java/com/example/HelloAIFunction.java @@ -101,21 +101,31 @@ public String handleRequest(String input) { } catch (Exception e) { try { - AuthenticationDetailsProvider authenticationDetailsProvider = - SimpleAuthenticationDetailsProvider.builder() - .tenantId(TENANCY_ID) - .userId(USER_ID) - .fingerprint(FINGERPRINT) - .privateKeySupplier(new StringPrivateKeySupplier(PRIVATEKEY)) - .passPhrase(PASSPHRASE) - .build(); + ConfigFileAuthenticationDetailsProvider configFileAuthenticationDetailsProvider = + new ConfigFileAuthenticationDetailsProvider("/config", "DEFAULT"); generativeAiInferenceClient = GenerativeAiInferenceClient.builder() .region(REGION) .endpoint(ENDPOINT) - .build(authenticationDetailsProvider); + .build(configFileAuthenticationDetailsProvider); } catch (Exception ee) { - answer = answer + "\n" + ee.getMessage(); + try { + AuthenticationDetailsProvider authenticationDetailsProvider = + SimpleAuthenticationDetailsProvider.builder() + .tenantId(TENANCY_ID) + .userId(USER_ID) + .fingerprint(FINGERPRINT) + .privateKeySupplier(new StringPrivateKeySupplier(PRIVATEKEY)) + .passPhrase(PASSPHRASE) + .build(); + generativeAiInferenceClient = + GenerativeAiInferenceClient.builder() + .region(REGION) + .endpoint(ENDPOINT) + .build(authenticationDetailsProvider); + } catch (Exception eee) { + answer = answer + "\n" + eee.getMessage(); + } } } @@ -156,5 +166,4 @@ public String handleRequest(String input) { } return answer; } - } \ No newline at end of file