Skip to content

Commit

Permalink
Merge pull request #1585 from oracle-devrel/oci-devops-genai-fix
Browse files Browse the repository at this point in the history
Oci devops genai fix
  • Loading branch information
martatolosa authored Feb 13, 2025
2 parents dc0bea4 + 5b46edc commit a856ae4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,21 @@ Clone this repo locally. In OCI Console click <code>Create Stack</code> under <c
<p>
OCI DevOps IAM Policies are not part of the stack, please refer to <a href="https://docs.oracle.com/en-us/iaas/Content/devops/using/devops_iampolicies.htm">docs</a> how to create them first.
<p>
Important! Before running the stack it is manadatory to create the OCI Registry repository for the OCI Function container and upload a dummy X86 architecture container to it. The <b>name</b> of the OCIR repo needs to match to the <code>image_name</code> of the Stack variables e.g. <b>helloworldai-java</b>. The image tag must be '<b>1</b>'.
<br>
The reason for this is that the Stack cannot create the Function without pointing to an image in OCIR.
<p>
This can be done by doing the following in OCI Cloud Shell (assuming the image name is 'helloworldai-java'):
<pre>
oci artifacts container repository create --display-name helloworldai-java --compartment-id ocid1.compartment.oc1.....gq
docker pull hello-world
docker tag hello-world fra.ocir.io/&lt;YOUR_TENANCY_NAMESPACE&gt;/helloworldai-java:1
docker push fra.ocir.io/&lt;YOUR_TENANCY_NAMESPACE&gt;/helloworldai-java:1
</pre>
Unless doing this the Stack will run into an error:
<pre>
Error: 400-InvalidParameter, Invalid Image fra.ocir.io/&lt;YOUR_TENANCY_NAMESPACE&gt;/&lt;image_name&gt:1 does not exist or you do not have access to use it
</pre>
After doing this the Stack can be run to create the OCI DevOps project. After the project creation the build pipelines can be run to build and deploy the OCI Function with real Function code like <a href="https://github.com/oracle-devrel/technology-engineering/blob/main/app-dev/devops-and-containers/functions/java-helloworld-AI-with-local-dev-and-oci-functions/README.md">this one</a> (the dummy hello-world image won't run properly).

### Stack settings

Before applying the Stack fill in the vars:

![Stack](./files/stack.jpg)

<ul>
<li><i>initial_image</i> that is used to create the OCI Function as target environment for the OCI DevOps deployment pipeline.
By default it is loaded from Dockerhub, but you can use any X86 arch image if want to replace this</li>
<li><i>docker_user</i> is your OCIR Docker user to push the initial image (above) to OCIR repo for the Function. Replace &lt;namespace&gt; with your <code>tenancy namespace</code>. <code>oracleidentitycloudservice</code> is only used for federated domains/users, not local</li>
<li><i>docker_password</i> is our OCIR Docker user password (your user profile auth token in OCI)</li>
</ul>

Run Stacks's Apply to create the OCI DevOps project.
<p>
The Stack creates only a <i>private subnet</i> in the VCN and hence the Function cannot be called outside the tenancy by default after the build and deploy.
<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

resource oci_artifacts_container_configuration export_container_configuration {
compartment_id = var.compartment_ocid
is_repository_created_on_first_push = "true"
is_repository_created_on_first_push = "false"
}

resource oci_artifacts_container_repository export_project {
compartment_id = oci_artifacts_container_configuration.export_container_configuration.compartment_id

display_name = "${var.project_name}-image"
display_name = "${var.image_name}"
freeform_tags = {
}
is_immutable = "false"
is_public = "false"
provisioner "local-exec" {
command = "docker login ${var.registry} -u '${var.docker_user}' -p '${var.docker_pwd}' && docker pull ${var.initial_image} && docker tag ${var.initial_image} ${var.registry}/${data.oci_objectstorage_namespace.tenancy_namespace.namespace}/${var.image_name}:1 && docker push ${var.registry}/${data.oci_objectstorage_namespace.tenancy_namespace.namespace}/${var.image_name}:1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ resource oci_functions_function export_project_2 {
trace_config {
is_enabled = "false"
}
depends_on = [oci_artifacts_container_repository.export_project]
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ variable region { default = "eu-frankfurt-1" }
variable registry { default = "fra.ocir.io" }
variable compartment_ocid { }
variable project_name {
default = "helloworldai-java-project"
default = "helloworldai-java"
description = "Name of the OCI DevOps project and related resources"
}
variable image_name {
default = "helloworldai-java"
description = "Name of the Docker image in OCIR. Important! Create/Push this into the OCIR repo for this before running this Stack, otherwise the stack will fail due to empty image in the function definition You can do this in OCI Cloud Shell using hello-world image from Docker Hub and then tagging and pushing it accordingly."
default = "helloworldai"
description = "Name of the image that is built by the pipelines and deployed in the target OCI Function"
}
variable docker_user {
description = "Your docker user to login OCIR to create the initial Function image"
}
variable docker_pwd {
description = "Your docker password (auth token) to login OCIR to create the initial Function image"
}
variable initial_image {
default = "docker.io/mikarinneoracle/hello-world-java-graalvm"
description = "Intial native X86 Hello-world public image that is used to deploy the initial OCI Function"
}

0 comments on commit a856ae4

Please sign in to comment.