Developing a .NET App in the Cloud with Acorn

Nov 3, 2023 by Sameer Kulkarni
Developing a .NET App in the Cloud with Acorn

Developing and deploying applications in Kubernetes has become an industry standard, but it's not without its challenges. For developers, these challenges can range from managing intricate configurations to optimizing resource allocation and navigating complex networking setups. Enter Acorn, it offers an all-in-one solution to build, package and deploy your applications on the Acorn cloud platform, or on any Kubernetes cluster. With Acorn, there is no infrastructure or container orchestration required when building or depliying an application. You use familiar development and deployment workflow similar to Docker Compose without having to deal with provisioning or configuring cloud resources.

Acorn is a lightweight deployment framework that makes developers productive and efficient by encapsulating both the application and its associated dependencies, including cloud services, within a singular Acornfile. In this tutorial, we will deploy a sample .NET application from the official Microsoft Tutorial Documentation on the Acorn cloud platform. This sample app uses a search form to browse GitHub repositories by name.

If you want to skip to the end, just click Run in Acorn to launch the app immediately in a free sandbox environment. All you need to join is a GitHub ID to create an account.

Pre-requisites

  • Acorn CLI
  • GitHub account to sign up for the Acorn Platform

Acorn Login

Login to the Acorn platform using the GitHub sign-In option with your GitHub user credentials.

acorn-login-screen

After the installation of Acorn CLI for your OS, you can also login using CLI to the Acorn Cloud Platform.

acorn-cli-login

Create the .NET Application

The sample application we’re going to see here is a GitHub repository browser. It lets you search Microsoft, Azure and Acorn organizations’ GitHub accounts to list their public repositories.

In the Acorn platform, there are two ways you can try this sample application.

  1. Using Acorn platform dashboard.
  2. Using CLI

The First way is the easiest one where, in just a few clicks you can deploy the sample application to the platform and start using it. However, if you want to customize the application or want to understand how you can run your own .Net applications using Acorn, use the second option.

Running the application using Dashboard

We can run our application from an existing image from the Acorn Cloud Platform UI by clicking on the ”Create Acorns” button.

Choose the source for deploying your Acorns. create-acorn-options-screen

On the “Create Acorns” page, provide a name such as

Dot Net Sample Acorn
and keeping Project's default Region, type in the below Pre-built Acorn image address or your own Acorn Image and choose Create.

ghcr.io/infracloudio/dotnet-core-acorn:v#.#.#-#


dotnet-select-image-acorn-platform
Now the sample App is provisioned on Acorn Platform and is available for 2hrs. Upgrade to Pro account to keep it running longer.
dotnet-on-acorn-platform
Once the Acorn is running, you can access it by clicking the Endpoint or the redirect link. Running the application using CLI As mentioned previously, running the acorn application using CLI lets you understand the Acornfile. With the CLI option, you can customize the sample app to your requirement or use your Acorn knowledge to run your own .Net application.

Clone the GitHub directory to download the codebase.

$ git clone https://github.com/infracloudio/dotnet-core-acorn.git

Here’s an overview of the application folder structure. dotnet-folder-structure

Acornfile

The Acornfile describes the containers, arguments, secrets and volumes to deploy the application. During the Acorn build all of the Docker containers will be built or pulled from a registry and packaged into the Acorn image. dotnet-acornfile

Here’s a concise description of the above Acornfile. For complete description of each component pls visit the Acorn documentation.

  • containers
    section: describes the set of containers your Acorn app consists of.
  • web
    - Our .NET core application container
  • build
    : build from source using the given context.
  • env
    : environment variables, referencing a secret or referencing an Acorn argument
  • ports
    : using the publish type, we expose the app outside the cluster using an auto-generated ingress resource

Deploy your Application

We will now deploy our application to the Acorn Platform. The following command will build and run in a single step. Since we’ve already logged in to the platform in the previous step, this command will talk to the platform to build and deploy your application. For production deployments you will want to build the image and push it to a registry.
From the same folder as your Acornfile, run:

$ acorn run -n search-app


Once the application is running successfully, it will output a URL for the application endpoint. dotnet-acorn-run-details

Using the application

Once you follow one of the above methods you’ll get a link in the Acorn dashboard to open your application. Open the application endpoint URL to access the same. dotnet-search-app-home-page Now you can search the repos by entering the name of any organization dotnet-search-output

Acorn Dashboard

The Acorn Dashboard is integrated with multiple features such as Events, Logs, Details and accessing the Shell of the Application. Details include the CPU, Memory, Network, Latency, Requests and Errors for the Application.

Explore various available options by clicking the Menu option on your Acorn App. Access the Acorn Dashboard here - https://acorn.io

dotnet-dashboard-1 dotnet-dashboard-2

You can find more information on using this dashboard in Acorn docs here.

Development Mode

In development mode, Acorn will watch the local directory for changes and synchronize them to the running Acorn app. In general, changes to the Acornfile are directly synchronized, e.g. adding environment variables, etc. Depending on the change, the deployed containers will be recreated. You can also install the VSCode plugin to work directly from your IDE.

$ acorn dev -n sample-app

We can now package the application and push it to a registry.

Push an artifact to a registry

The application is working as expected and is ready to be built and packaged to a registry. We will use GitHub Container Registry in this example. Once published, you can use the acorn image to deploy it directly in the Acorn platform using the dashboard, as described previously.

Log in to the registry

Log in to the registry with the command below and follow the prompts.

$ acorn login ghcr.io

Build and push the image

Build and push the image with the below command.

$ acorn build -t ghcr.io/infracloudio/dotnetcore-acorn:v0.0.1 --push

What's Next?

  1. The App is provisioned on Acorn Platform and is available for 2hrs for free in the Sandbox, though you can start it as often as you like. Upgrade to a Pro account to pay for resources as you go. Acorn resources run on AWS, and advanced options such as the Acorn Teams and Acorn Enterprise accounts allow you to use your AWS credentials to directly provision Acorn resources onto your own infrastructure. With the Acorn Runtime open source project, you can also deploy Acorns on any Kubernetes cluster running the Acorn Runtime operator.
  2. After deploying you can edit the Acorn application or remove it if no longer needed. Click the Edit option to edit your Acorn's Image. Toggle the Advanced Options switch for additional edit options.
  3. Remove the Acorn by selecting the Remove option from your Acorn dashboard.

Conclusion

In this tutorial, we have deployed a .NET application on Acorn Platform using Acornfiles. It provides a holistic solution for developers to seamlessly manage and deploy applications. Then we explored the Acorn Platform Dashboard to gain useful insights of your application.

Learn more about the Acorn Platform with the Acorn Documentation, or join an upcoming training to get a hands-on introduction to developing apps in Acorn.