Tuesday, December 28, 2021

Create Service Account in Windows 10

Follow the below steps to create windows service account in Windows 10 Machine,


1. Go to Computer Management screen.


2. Go to Local Users and Groups-->Users. And right click on right pane and seclect "New User".


3. Provide user name , password for the new account and de-select all other check box except "Password never expire". Click on Create butto.


4. You new account should be now showing in right Pane.


5. Now serach for "Local Security Policy" in start menu and click to open it.


6. Go to "Local Policies"-->User Rights Management--> Log on as a service". Double click to open it.


7.Click on add user button.


8. In the search screen search the user with the newly created account name and add it.


Now you can user this account along with any other application which need some service account like Jenkins installation.

Friday, December 24, 2021

.NET Full Framework app deployment to docker container

+



Today I am going to share how you can deploy a .NET application (web application) in docker. The benefit of using containerization of application is build once and deploy any for any environment. As we know most of the modern application are configuration file driven where as base code remain almost across the environment(DEV, UAT and PROD). So while deploying the code container if you can replace the config file then you are good to deploy in any environment by build once. Usually code are build in dev environment and build artifact got promoted to higher environment. What docker do, it virtually segregate at Operating system level and allow you to multiple container(think as a small virtual machine) and allow to deploy code. Any point of the application life cycle you can create and destroy container. In this article mostly I will be showing how to get a base windows images from cloud docker repository and deploy to AWS ECS.


What you need

  1. Windows 10 machine with Hyper V enabled.

  2. Visual Studio installed in your machine --> Just to create any web application.

  3. Docker demon installed in you local machine-> Just to push the build artifact to docker and run.
    You can use Docker desktop to run docker container.

Following are the URL to download the software

https://visualstudio.microsoft.com/downloads/
https://docs.docker.com/desktop/windows/install/

How do you Containerize a .NET application?


Step-1 : Create a .NET Full Framework application and publish it.
Step-2 : You need have base image in which you are going to deploy your code. The base image contains all the necessary run time and required base dlls to run your application. Base image can be pulled from public repository or private repository. Mostly Organization keep the docker base images in their ow private repository.
Step-3 : Create docker file which tells the docker demon how to deploy your code in to the base images.
Step-4 : run the docker container.

Docker file Sample

##### Sample Docker file for dotnet core app-linux container deployment #########


FROM <URL-TO-YOUR-DOCKER-BASE-IMAGE-REPOSITORY>
WORKDIR App
COPY <SOURCE-PATH-TO-LOCAL-MACHINE> <DESTINATIN-PATH-IN-DOCKER>
COPY ["appsettings.json","."]
ENV ASPNETCORE_URLS http://*:8090
EXPOSE 8090
ENV ASPNETCORE_ENVIRONMENT "Development"
ENTRYPOINT ["dotnet" ,"dotnet-core-dll-name.dll"]

########### Sample Docker file for .NET Full Framework app- windows container #####

FROM <URL-TO-YOUR-DOCKER-BASE-IMAGE-REPOSITORY>
RUN MKDIR <website-dir-name-in-container>
COPY ["source-directory-path","<C:\website-dir-name-in-container>"]
COPY ["Web.config","<C:\website-dir-name-in-container>"]
RUN COPY-ITEM <C:\\website-dir-name-in-container> -Destination c:\\inetpub\wwwroot\\<website-dir-name-in-container> -Recurse
RUN New-WebSite - TestWebsite -Port 80 -PhysicalPath c:\\inetpub\wwwroot\\<website-dir-name-in-container>
RUN New-WebBinding -Name "TestBinding" -IP "*"; -Post 443 Protocol https;$domaname='*.cert-domain-name';$sitename='TestWebSite';$dnsname=$domainname;$newCert=New-SelfSignedCertificate -DnsName $dnsname - CertStoreLocation cert:\LocalMachine\My;$binding=Get-WebBinding -Name $sitename -Protocol "https";$binding.AddSSlCertificate($newCert.GetCertHashString(),My);
EXPOSE 80
EXPOSE 443

Few Basic Docker command to push the application to container and run it,

1. docker pull <url-to-repository>:<docker-image-name> , to pull base docker image from repository.


2. docker build -t <name-of-modified-image> -f <path-to-docker-file> to build the container image using above base image.


3. docker run --name <container-name> -d-rm -it -p 8000:80 <name-of-modified-image> to run the container from image


How docker container push work with Jenkins?

1. Docker cli has to be configured at the windows or Linux node based upon your preferred build node.
2. From pipeline script or groovy script run the above command as bat or sh.

Friday, December 17, 2021

.NET Full framework code build using Jenkins pipeline aka Continuous Integration (CI)


 

Today I am going share how to build .NET full Framework application using Jenkins. I am not going to show all the steps but explain you at high level how you can achieve that. I have a plan to make detail steps on how to setup Jenkins pipeline, Build environment in future.

What I need

Now to building code using any automation tool is very normal. Here I will explain how to build code using Jenkins for .NET full framework application. You need to have Jenkins installed and having admin privilege to configure the tool in Jenkins. Also MSBuild installed in your machine and path is set in Jenkins.


Following are URL to get these software,



Audience : 

  • You are aware of command line MSBuild.
  • Some idea on Jenkins and Groovy script.


How I can run the MSbuild using Jenkins pipeline

  1. Make sure specific .NET MS build tool is available in Jenkins for e.g. MSBuild14, MSBuild15, MSBuild16 etc. As name suggested lower build versions is having support up to specific .NET full framework.

  2. Jenkins is able to Checkout the code from any Source Control like Git, TFS etc and that is setup already done in Jenkins before build the code.

  3. You can use standard pipeline steps(no coding required) or groovy script to build the code

Build using Freestyle pipeline

Open your Jenkins console and select Freestyle project and create it with a name.


FreeStyle Project





Once it is created, Under Build section, you will find the Msbuild option

Jenkins MSBuild Option
MsBuild Option







Then select appropriate msbuild version for your build


List of MSbuild tools configured in Jenkins





Using Groovy DSL (This gives you more flexibility from standard pipeline creation)


    1. Make sure The MSBuild is configured in Jenkins(admin has privilege to setup this)

  1. in the groovy code get the path of msbuild.exe. Make sure path of msbbuild.exe is same across the all windows node.

  2. Construct the MSBuild command in your code.

  3. Run the command using bat command. For example

    Msbuild.exe /p:Configuration=DEV /p:DeployOnBuild=True /p:PublishProfile=PubProfile.pubxml.

đŸ“”Point to Remember


  1. Note that the Msbuild switch may differ based upon type of application you are going to build like web application, Console/Windows application.

  2. Try to use nugget package reference instade of using direct dll reference from project file.