Tech Junkie Blog: July 2016

Friday, July 29, 2016

One of the most common task you have to do as a Linux administrator is to add a new user.  Especially developers who always wants root access. Docker needs root access, however the person who is administering Docker is probably not the system administrator.  Most likely it will be the application developer. To accomplish this task you can use the useradd command in the Terminal session then add the new user to the Docker group.  Follow the steps below to add a new user to CentOS.

1.  Switch into the root user using su - command






In our previous blog we created a simple _Layout.cshtml file that does not have any markup just to make things simple.  In this blog we will use Bootstrap to make the layout look more professional and responsive, so that it can be viewed in any screen size.  The previous layout looks like screenshot below.
















Thursday, July 28, 2016

In our previous blog posts we ran containers with the Fedora and CentOS images.  In this blog we are going to run a command to see which containers are running in our host system.  To get a list of all the containers running on our host Ubuntu system we type in the command docker ps -a command.











Wednesday, July 27, 2016

The beauty of Docker is that you can run a very lightweight image of another Linux distro on your host system.  In this post we will be pulling the latest image of CentOS into our docker container on our Ubuntu server.

Step-by-Step:

1. Open the terminal in Ubuntu, then make sure docker is running by typing service docker status, you should see something a message like the image below







Tuesday, July 26, 2016

The beauty of Docker is that you can run a very lightweight image of another Linux distro on your host system.  In this post we will be pulling the latest image of Fedora into our docker container on our Ubuntu server.

Step-by-Step:

1. Open the terminal in Ubuntu, then make sure docker is running by typing service docker status, you should see something a message like the image below







Monday, July 25, 2016

One of the most common task you have to do as a Linux administrator is to add a new user.  Especially developers who always wants root access. Docker needs root access, however the person who is administering Docker is probably not the system administrator.  Most likely it will be the application developer. To accomplish this task you can use the useradd command in the Terminal session then add the new user to the Docker group.  Follow the steps below to add a new user to Ubuntu.

1.  Switch into the root user using sudo su - command




Friday, July 22, 2016

In ASP.NET MVC there is a default layout file that the application use when one exists.  If you look at the markup at the top of the "Index.cshtml" file you will see that there is a markup to specify the layout of the page in the code below.

@{
    Layout = null;
}

The code above tells ASP.NET MVC to not assign any layout to the page because it is being set to null. In this blog we will build on our existing NorthwindCafe.Web  project and add a default layout view to the project so that each page in the project will have a common layout.  This is similar what you would a master page for in web forms.

Step-By-Step Instructions:

1. Open the "NorthwindCafe.Web project in Visual Studio
2.  Right-click on the Views folder then select Add → New Item → .NET Core →  MVC View Start Page then click the "Add" button










Thursday, July 21, 2016

In the previous post we installed Docker on our Ubuntu server.  Now we are going to add the Docker repository to our local server so that we can get the latest version of Docker.

Step-By-Step Instructions:

  1. Open the terminal command line tool and switch to root user with the sudo su command








2. Now we have to add the Docker repo key to our local machine by typing the following command
wget -qO- https://get.docker.com/gpg | apt-key add -











Wednesday, July 20, 2016

Docker is the hottest infrastructure technology to hit the tech world in a long time.  The appeal of Docker is that it allows the infrastructure team to utilize the capacity of the servers to near full capacity.  Docker is a container.  A container is like a micro virtualization minus the operating system.  It only contains enough infrastructure to host an app, without the fat.  Hence the term container is used to describe it.

Here are the steps to install Docker on a CentOS Server:

1.  Open the CentOS terminal, then type the following command to switch to the super user:
     sudo su








Tuesday, July 19, 2016

Docker is the hottest infrastructure technology to hit the tech world in a long time.  The appeal of Docker is that it allows the infrastructure team to utilize the capacity of the servers to near full capacity.  Docker is a container.  A container is like a micro virtualization minus the operating system.  It only contains enough infrastructure to host an app, without the fat.  Hence the term container is used to describe it.

Here are the steps to install Docker on a Ubuntu Server:

1.  Open the Ubuntu terminal, then type the following command to switch to the super user:
     sudo su

Monday, July 18, 2016

In the previous post we have enabled MVC on our application.  Now we want to add our first MVC controller and view to test out verify that MVC is working.  We also have to tell ASP.NET Core what pattern to look for when looking for our controllers and views.


Step-By-Step Instructions:

1.  Add a folder call "Controllers" in the root of your application






Sunday, July 17, 2016

In the previous blog post we created an empty Blogger template with just the bar minimums.  In this post we are going to build on that and display our posts in just 32 lines of code. In your template type in the following code.


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html>
  <head>
    <title><data:blog.pageTitle/></title>
    <b:skin><![CDATA[/*]]></b:skin>
  </head>
  <body>
          <b:section class='main' id='main' name='Main' showaddelement='no'>
            <b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog' visible='true'>
              <b:includable id='post' var='post'>

    <a expr:name='data:post.id'/>
    <b:if cond='data:post.title'>
      <b:if cond='data:post.link or (data:post.url and data:blog.url != data:post.url)'>
        <a expr:href='data:post.link ? data:post.link : data:post.url'><data:post.title/></a>
      <b:else/>
        <data:post.title/>
      </b:if>
    </b:if>
 <data:post.body/>
    <b:if cond='data:post.hasJumpLink'>
      <div class='jump-link'>
        <a expr:href='data:post.url + &quot;#more&quot;' expr:title='data:post.title'><data:post.jumpText/></a>
      </div>
    </b:if>
</b:includable>
            </b:widget>
          </b:section>
      <b:section id='side-bar-left'/>
</body>
</html>

It could be frustrating to edit your blogger template with the overwhelming size of the code.  Talk about a single page application, not in a good way.  There are thousands of lines of code in the blogger Template. The tag help site is not very helpful Blogger Help. In this blog series we are going to edit the Blogger template the from scratch using the least amount of code possible and then use bootstrap to do the styling once we get the bare bones elements in place.  The first step is to get start with the least amount of code possible then start from there.  So I have a boilerplate for the least you can have for a Blogger template below.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html>
  <head>
    <title><data:blog.pageTitle/></title>
    <b:skin><![CDATA[/*]]></b:skin>
  </head>
  <body>
    <b:section id='main'/>
      <b:section id='side-bar-left'/>
</body>
</html>

Friday, July 15, 2016

In this post we will go over the process of enabling ASP.NET MVC in our application.  Just like static files, in order for us to use MVC in our application we have to tell ASP.NET Core to use Mvc in the Startup.cs file.  We will continue to use the application "NorthwindCafe" that we used in our previous blog.

Here are the steps to add MVC to your application:

1.  Open the Startup.cs file, then in "ConfigureServices" method type in the following to enable MVC

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

2. As with the static files, there will be a red underline on the .AddMvc() method that's because we haven't added the package to your project yet.  So click on the yellow light and select the first option to add Microsoft.AspNET.Mvc package to our project.


Thursday, July 14, 2016

As I have mentioned before ASP.NET Core decouples the application from the infrastructure as much as possible.  Therefore, you have to tell it exactly what you want in your project.  In this blog post we are going to tell ASP.NET that we want to serve static html files in our application.

Here are the steps to serve static files in our ASP.NET Core application.

1.  Open the "NorthwindCafe.Web" project, then click on the "Startup.cs" file in the project.  You will see the following markup in the Configure method

        public void Configure(IApplicationBuilder app)
        {
            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }

2.  Go into the Configure method, remove the existing code and type in the following code
        public void Configure(IApplicationBuilder app)
        {
            app.UseStaticFiles();
        }

Wednesday, July 13, 2016

In this blog post we are going to add the jQuery, AngularJS, and bootstrap libraries to our ASP.NET Core application.  Normally we will use NuGet to bring in these libraries but ASP.NET Core gives you the option to use bower to configure the dependencies that you will need on the client-side.

Here are the steps to import the client-side dependencies into our project:

1. First let's make bower.json part of the "NorthwindCafe.Web" project, click on the "Show All Files" icon in solution explorer, then right click on the bower.json file, and then choose "Show in Solution Explorer"

2.  Open the bower.json file the markup should look like this

{
 "name": "asp.net",
 "private": true,
 "dependencies": {
 }
}

Tuesday, July 12, 2016

Technology has moved at a breakneck speed, after working with ASP.NET Core for a while, I realized that my ASP.NET MVC blog articles have become outdated.  Don't get me wrong, MVC is still a very big part of ASP.NET Core, but that's the thing it's just a part of it.  ASP.NET Core has decoupled the infrastructure from the application.  You can deploy your web app on Docker imagine that!  No longer is IIS your primary means of hosting your ASP.NET application.

However, with this new freedom comes added complexity.  No longer can you just drag and drop components into your design surface.  Those days are long gone.  This post ist meant to ease your way into ASP.NET Core.  I will using the release candidate version two of ASP.NET Core for this post and other subsequent posts.  Don't be surprise if I update the version midstream because the product is still pre-release.  I will be using Visual Studio 2015 for my development.  You can use the command line interface and notepad to develop your ASP.NET Core application.  But, I think that borders on insanity.