Hello and welcome to this demo on creating a function from a custom Dockerfile. In this demo, you will create and deploy your code to the OCI functions as a custom Docker container using a node base image. You typically use a custom image when your functions require a specific language version or have a specific dependency or configuration that isn't provided by the built-in image. Sometimes, you also need to handle advanced use cases and must take complete control of the creation of your function container image. Let's build a simple custom function container image to become familiar with the key elements of the process. Let's get started. Alright, so I've logged in to the OCI console. The first thing that I'll be doing is creating a function application. Let's go to the developer service, go to the functions. Under Applications, I'll be creating an application where we will be deploying our custom function. Let's click on Create Application. But make sure that you are in the right compartment. In our case, the compartment that I have pre-created is functions_demo, where I'll be creating all my function resources. Let's select functions_demo, and click on Create Application. Let's give our application a suitable name. I've given it a name custom_demo. Let me go ahead and select the subnet. Let's select the public subnet, and let's click on Create. As you can see, the application has been created with the name custom_demo, and we get to see a few Getting Started Tips to begin with creating functions and deploying those function within this application. I'll be using Cloud Shell for the rest of the setup. Let me quickly launch the Cloud Shell by clicking on the launch Cloud Shell button. This will take some time before the Cloud Shell machine is created and we get the excess of the Shell. I have the excess of my Cloud Shell now, let me quickly maximize this Cloud Shell. In the interest of time, I've already created a folder structure where I have all the required files in place. Let me quickly show you the folder. Custom_nodejs is my folder where I have all the files. Let me get inside this directory. Let me show you the contents. As you can see, there are a few files within this directory. Let me quickly explain you each of them. This is a nodejs project. Let me quickly open up the function definition. Now if you see from the code, what this function does is it takes a binary image as its argument and writes it to a temporary file, and then uses the image Magic Software to obtain the width and the height of the image. Now since the function argument type is binary, we need to set the input mode property to buffer when we call the FDK's handle function. This is our function definition. Let me close this. Now let me show you the package.json file. Basically, this file contains all the nodejs dependencies. As you can see from the code, we have specified the list of dependencies that are required for successful run of this particular project. The dependencies include fnproject/fdk a temporary module, which is basically for your temporary file utilities. Again, Image Magic Software that would be used to determine the height and the width of the image. Let me close this file and move on to the next file. The next file that I'll be showing you is function.yawl file. Basically, this file contains the function metadata. Let me open the file. As you can see from the code, this basically contains the function metadata, basically the schema version, the name of the function, the version, the runtime. Now if you notice the runtime is not node over here, this ideally must be node as it's a Node project, since we are using a custom Dockerfile to create a custom Docker image for this project, we have changed our runtime to Docker. With that, since we have changed our runtime to Docker, we will also be needing a custom Dockerfile. Let me quickly close this file and show you the custom Dockerfile that we have written. Now this is a custom Dockerfile that we have written. I have purposely commented this line just to tell you that if we do not use a custom Dockerfile, the FN build would normally generate this particular Dockerfile in order to build a Node JS function container image. But since we're doing a custom Dockerfile and we know that we want to have ImageMagic installed in our base image. Now since we're doing a custom Dockerfile, we have this liberty to add libraries and new softwares within our image. What I'll be doing is I'll be uncommenting this line, and what this will do is it will run the image Magic Software in the FN project node runtime image. With that, we'll be able to make use of ImageMagic libraries. Let me close this file. As you can see, we also have a few sample jpg images which we'll be using to invoke our function. Now, as part of the next step, what I'll be doing is setting up the FN projects CLI contexts. First, let me check the list of contexts using the FN lists contexts command. As you can see, there are two contexts. One is the default and one is my region, which is AP-mumbai-1. Currently, the context selected is my current region, so I'll leave it to that. The next thing that I need to do is, is to configure the FN project context with the OCID of the current compartment which will own the deployed function. Let's fire the command FN update contexts oracle.compartment-ID and specify the compartment ID where my FN project resources are being built. The command is Fn update contexts oracle.compartment-id, and the compartment ID where you use to create your Fn resources. Let's hit Enter and the current contexts has been updated. The next thing that we need to configure is Fn project contexts with the OCIR, that is Oracle Cloud infrastructure Registry address in the current region and tendency that we want to use with Oracle functions. The command is Fn update contexts registry followed by the registry address. Let me quickly go ahead and hit Enter, and the contexts has been updated for registry. Remember, the registry address is basically the combination of your registry key ocir.io/ separated by your tendency namespace, and then you have to provide a repository name prefix. In my case, the repository name prefix is mahimehra. Let me clear the screen and now as part of the next step, I'll be logging into OCI Container Registry. The command for it is docker login minus u. You specify your username and the registry address. I'll go ahead and hit Enter, and in the form of password, you'll have to provide your authentication token. Let me go ahead and hit Enter. As you can see, I've successfully logged in into the OCI Container Registry. Now that I have configured the Fn C in my context and have logged in into the OCI Container Registry. The next step would be to build and deploy the function. Like I said, we have our custom Docker file ready. I'll quickly show you the list of files. Again, we can simply run the Fn build command to build a custom container image for our function. The command is Fn spaced minus v space build. Let me go ahead and hit Enter. As you can see from the command, it is using the custom Docker file that we provided in order to create a custom Docker image. As you can see, it's using the two-stage build process in order to create our custom Docker file. As you can see as part of Step 6, it's also installing the image Magic Software in our custom image, which is basically a run-time image , for the node project. As you can see, at the end we have our image built and the tag that's given to that image is 0.0.3. Now that the custom image has been built, the next step is to deploy this function into the application that we created earlier. Let me clear the screen. To deploy our function, the command is Fn -v deploy --app, and the name of the application that we created earlier, which is custom_demo. Let's go ahead and hit Enter. As you can see as the output of the deploy process, the custom image that we created is pushed into the OCIR, that is the OCI Container Registry, and the push operation has completed successfully, we can simply go to the OCI repository and see whether this image exists. Let me minimize this Cloud Shell and take you to the OCI Registry, which is available under Developer Services under Container Registry. The compartment is a root compartment, and if you see we have this new repository created with the name image DIMS. If I open this, you can see the image available under this repository. Now that we have our custom function image created, it's time to invoke this particular function. I'll also take you to the function application and show you that the function has been deployed within the application. Let's go to the Function Service , under Developer Service. Let's select the compartment which is function_demo. If you select the custom_demo application, you can see that there is a function is already created under the customer_demo application with the name image DIMS. It also has information like if you wish to invoke it using an endpoint or what is the image digest in order to check for the integrity of the image, et cetera. Now let's go back to the Cloud Shell and invoke this function using CLI. Let me clear the screen. Now in order to invoke this function, like I said, this is a custom function which takes as an input an image and returns the image's width and height, so will have to provide an image as an input. In our case, we have two sample images. One is image.jpg and other one is website.jpg. Both are of different dimensions, so let's quickly run each of them by this function and see what output we get to see. The command that I'm using to invoke this function imagedims, which is the image dimensions, is basically cat Image.jpg, where I'll be passing this image as an input to our application, which is customer_demo, which is hosting our function, imagedims. If I hit Enter, the output is the width and height. The width of the image is 553 and the height is 415. Now if I rerun the command again, it won't take as much time as it took earlier. Now let's run the same command with another image as input parameter. As you can see, the width and height that returned for the new image is different as compared to the earlier one. With this, we were able to create, deploy, and invoke an Oracle function using accustomed Docker file. I hope you like the demo. Thanks for watching.