Help:Toolforge/My first Buildpack .NET tool

From Wikitech
Jump to navigation Jump to search

.NET is a free and open-source, managed computer software framework for Windows, Linux, and macOS operating systems.

This stub webservice is designed to get a sample .NET application installed onto Toolforge using the new build service, as quickly as possible.

The guide will teach you how to:

  • Create a new tool
  • Run a .NET 8 webservice on Kubernetes

Getting started

Prerequisites

Skills

Accounts

Step-by-step guide

Step 1: Create a new tool account

  1. Follow the Toolforge quickstart guide to create a Toolforge tool and SSH into Toolforge.
    • For the examples in this tutorial, sample-dotnet-buildpack-app is used to indicate places where your unique tool name is used in another command.
  2. Make sure to create a git repository for the tool, you can get one like this:
    1. Log into the toolforge admin page
    2. Select your tool
    3. On the left side panel, under Git repositories click create repository
    4. Copy the url in the Clone section
      1. There's a private url, that we will use to clone it locally, starting with "git": git@gitlab.wikimedia.org:toolforge-repos/sample-dotnet-buildpack-app.git
      2. And a public one, that we will use to build the app in toolforge, starting with "https": https://gitlab.wikimedia.org/toolforge-repos/sample-dotnet-buildpack-app.git

Step 2: Create a basic .NET webservice

Clone your tool git repository

You will have to clone the tool repository to be able to add code to it, on your local computer (with git installed) you can run:

laptop:~$ git clone git@gitlab.wikimedia.org:toolforge-repos/sample-dotnet-buildpack-app.git
laptop:~$ cd sample-dotnet-buildpack-app

That will create a folder called sample-dotnet-buildpack-app. We are going to put the code in that folder.

Generate the .NET web app
We are going to use the project generator that comes with the dotnet SDK to bootstrap the project, feel free to use anything else you prefer
laptop:~sample-dotnet-buildpack-app$ dotnet new web --name SampleDotnetWebservice

This creates a sample application with everything you need, that will reply with Hello world! when it gets an http request.

Code on Toolforge must always be licensed under an Open Source Initiative (OSI) approved license. See the Right to fork policy for more information on this Toolforge policy.

Create the Procfile

The Procfile is based on heroku's procfile, though we don't support all it's features, for now we only use the web entry point to get the command your server will be start:

laptop:~sample-dotnet-buildpack-app$ cat > Procfile << EOF
web: env ASPNETCORE_URLS=http://0.0.0.0:$PORT/ heroku_output/SampleDotnetWebservice
EOF

There's two specific things to note:

  • The binary is under the directory heroku_output
  • We have to specify the ip and port to listen on, making sure to use $PORT for the port, and 0.0.0.0 as ip instead of the common 127.0.0.1.
Commit your changes and push
laptop:~sample-dotnet-buildpack-app$ git add .
laptop:~sample-dotnet-buildpack-app$ git commit -m "First commit"
laptop:~sample-dotnet-buildpack-app$ git push origin main
EOF


Build the image

Now we have to ssh to login.toolforge.org and start the build for the image:

laptop:~sample-dotnet-buildpack-app$ ssh login.toolforge.org  # or the equivalent with PuTTY
dcaro@tools-sgebastion-10$ become sample-dotnet-buildpack-app
tools.sample-dotnet-buildpack-app@tools-sgebastion-10$ toolforge build start https://gitlab.wikimedia.org/toolforge-repos/sample-dotnet-buildpack-app.git
You have to pass the public url of the git repository (for gitlab, you can get it from), otherwise it will not be able to clone it.
Wait for the build to finish

It will automatically show you and follow the build logs, but if you lose or break the command, you can check the status of the build like this:

tools.sample-dotnet-buildpack-app@tools-sgebastion-10:~$ toolforge build show

You have to wait for the status to be ok(Succeeded).

Start the webservice
tools.sample-dotnet-buildpack-app@tools-sgebastion-10$ toolforge webservice buildservice start --mount=none 
Starting webservice.

Once the webservice is started, navigate to https://sample-dotnet-buildpack-app.toolforge.org in your web browser, and see a 'Hello World!' message. It might take a few minutes until it is reachable.

Notes

You can see the code used in this example here: https://gitlab.wikimedia.org/toolforge-repos/sample-dotnet-buildpack-app

Troubleshooting

See Help:Toolforge/Build_Service#Troubleshooting.

See also

Communication and support

Support and administration of the WMCS resources is provided by the Wikimedia Foundation Cloud Services team and Wikimedia movement volunteers. Please reach out with questions and join the conversation:

Discuss and receive general support
Stay aware of critical changes and plans
Track work tasks and report bugs

Use a subproject of the #Cloud-Services Phabricator project to track confirmed bug reports and feature requests about the Cloud Services infrastructure itself

Read stories and WMCS blog posts

Read the Cloud Services Blog (for the broader Wikimedia movement, see the Wikimedia Technical Blog)