dzirkler / dotnetcorehelloworld

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET Core Hello World CodeFresh Demo

Codefresh build status

This was set up as a proof-of-concept to perform a CodeFresh build for a .NET Core app. The app can be found in the /hwapp folder, and is simply the result of a dotnet new console -o hwapp command, as documented on the .NET Core Getting Started page.

I wanted to be able to use CodeFresh to enable Continuous Integration for .NET Core apps. Microsoft provides both runtime and sdk builds for .NET Core. Unforutnately, to build a .NET Core app from source code, you need to use the SDK. Once you have the files built, you can use the built files in the runtime container. This enables us to have a smaller container, and only contain the minimum to run our application (which also enhances security by not including the sdk). Additionally, we do not need to include our source code in the container!

The way this works, is we fire up a container with the SDK and perform a build on a mounted volume. Then, we use the output folder from the build (/out) to create a new image. The same paradigm works in CodeFresh and locally.

Build locally for testing:

  1. From the project directory (where this readme is located), build the app:
    docker run -it --rm -v "$(pwd):/src" --workdir /src microsoft/dotnet:1.1.1-sdk /bin/bash /src/build.sh
  2. Build the docker image:
    docker build . --tag organization/repo:tag
    • Use your own org and repo names here.
  3. Run the new image:
    docker run organization/repo:tag
    • You should see "Hello World!" written in your console.

Build using CI in CodeFresh

  1. Fork Repo to your own GitHub Org
  2. Update codefresh.yml with your docker hub repo and image name.
  3. Configure a new repo in CodeFresh to build from your new forked repo
    • Be sure you use the codefresh.yml option
  4. Marvel at the awesomeness of your own .NET Core app auto build!

Thanks

The general approach was borrowed from Steve Lasker's Blog

About


Languages

Language:C# 63.9%Language:Shell 36.1%