DEV Community

Naimul Karim
Naimul Karim

Posted on

Simple steps to build a CI/CD pipeline with ASP.Net Core, GitHub Actions, Docker and a Linux server

The Pipeline

Build is run automatically at each commit to GutHub.
A docker container is created and pushed to docker hub.
Finally the container is deployed to a Linux Server.

Build the Application

Create a docker file with the following codes and put it in the same folder as the sln file of your application.

The docker file contains metadata for two images. First one contains a .net sdk to build the application. The second one only contains the ASP.NET Core runtime and application binaries to be used for production deployment.

Run the docker container locally

Run the following commands to see your docker container is created and running in your machine.

docker build . -t cicddemo

docker run -p 5000:80 -it cicddemo

This will create a container from the image. Check your webpage from http://localhost:5000

Also can check from docker desktop if the containers are running.

Commit and push to GitHub

If the page is loading, commit all changes and push everything to GitHub.

Build the container with GitHub Actions and push it to Docker Hub

1.Set Secrets for your docker hub username and password.

  1. Create the directory “.github/workflows” in the root of your git repository. Inside this folder, add a file called “cicddemo.yaml”. My cicddemo.yaml contains the following :

3.Save this file to “.github/workflows/CICD.yaml” , commit all changes and push them to GitHub.

  1. Now if you look into your GitHub account, you should see the workflow under the “Actions” tab. And if you click you will find your jobs running.

  1. After it is completed login to your docker hub account and you will find the image under your repository.

No alt text provided for this image
You are done !

Top comments (0)