Sitefinity Multisite With IIS Express

        1. on the current solution folder look for the .vs\SitefinityWebApp\config folder and the applicationhost.config file
        2. open the applicationhost.config file in a text editor and look for a similar string site name='SitefinityWebApp' id='2'
        3. comment out the existing binding entry add new bindings entries :
          carbon

          xip.io is a dynamic DNS server which points to whatever IP address you embed into the hostname. It prevents you from messing around the hosts file

        4. Open Visual Studio with Run as Admistrator , open the solution and on the Sitefinity webapp project , right click for properties
        5. On the Web tab, Servers section, Project Url property type the address
          http://somedns.127.0.0.1.xip.io:
        6. On the Sitefinity Multisite Management page edit the properties of the site and on the domain property type the
          somedns.127.0.0.1.xip.io:

          and on the other site

          otherdns.127.0.0.1.xip.io:

Cheers,

Posted in Tools, Visual Studio | Leave a comment

My first Take on Terraform – Part 02

On my previous blog post, I started looking at Terraform and AWS. I’ve learned how to write a *.tf file, how to pass values to it, some core AWS concepts and I was able to provision an EC2 instance with NGINX and to obtain its public DNS, but I’ve struggled with the security part of it, it was necessary to manually set some rules in the default security group.

In this blog post, I hope to overcome that issue.

The starting point is the *.ts file from part one and you can get it here.

To provision our EC2 instance into a new security group with our rules configured we need to add these items

So let’s add these “sections” to our *.ts file

# VARIABLES
...
variable "network_address_space" {
default="10.1.0.0/16"
}
variable "subnet1_address_space" {
  default = "10.1.0.0/24"
}
...
# DATA
data "aws_availability_zones" "available" }

# RESOURCES
resource "aws_vpc" "vpc" {
  cidr_block = "${var.network_address_space}"
  enable_dns_hostnames = "true"
}
resource "aws_internet_gateway" "igw" {
  vpc_id = "${aws_vpc.vpc.id}"
}
resource "aws_subnet" "subnet1" {
  cidr_block        = "${var.subnet1_address_space}"
  vpc_id            = "${aws_vpc.vpc.id}"
  map_public_ip_on_launch = "true"
  availability_zone = "${data.aws_availability_zones.available.names[0]}"

}
resource "aws_route_table" "rtb" {
  vpc_id = "${aws_vpc.vpc.id}"

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = "${aws_internet_gateway.igw.id}"
  }
}

resource "aws_route_table_association" "rta-subnet1" {
  subnet_id      = "${aws_subnet.subnet1.id}"
  route_table_id = "${aws_route_table.rtb.id}"
}

resource "aws_security_group" "nginx-sg" {
  name        = "nginx_sg"
  vpc_id      = "${aws_vpc.vpc.id}"

  # SSH access from anywhere
  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"] # not ready for production, should be your IP address
  }

  # HTTP access from anywhere
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  # outbound internet access
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "nginx1" {
  ami           = "ami-c58c1dd3"
  instance_type = "t2.micro"
  subnet_id     = "${aws_subnet.subnet1.id}"
  vpc_security_group_ids = ["${aws_security_group.nginx-sg.id}"]
  key_name        = "${var.key_name}"
...

A brief explanation …
Two new variables network_address_space and subnet1_address_space. A new DATA section to query aws for availability zones and some new resources : aws_vpc ( a new vpc to hold our new instances); aws_internet_gateway (for instances within our vpc to be able to communicate to the outside world) ; aws_subnet (placed in [0] availability zone for the region); aws_route_table & aws_route_table_association (to tell the vpc what to do with traffic ); aws_security_group ( with the rules for ingress and egress we want to define );
You can find the full file on GitHub
We can now do
terraform apply -var-file=terraform.tfvars
And there you go… EC2 Instance created in a custom security group.
and to remove the prompt
terraform apply -var-file=terraform.tfvars -auto-approve

Hope you find it useful … here is the GitHub repo

 

Cheers!

Posted in continuous delivery, devops, Tools | Leave a comment

My first take on terraform

On my previous company, I had the opportunity to learn and do some DevOps work. Thanks to some amazing colleagues I was able to pick up some concepts and experience regarding infrastructure as code, docker, kubernetes, yaml files and others. Back then we didn’t use Terraform as it was not fully compatible with Azure at the time (I might be wrong about this) and we used plain old ARM Templates to describe infrastructure and bash scripts with tools like Azure CLI and Kubectl to automate the provision and deploy of resources/applications into Azure and Kubernetes.

This week I decided to take a first look at Terraform and AWS, and also to check how familiar I still was with the concepts previously mentioned. So these were my steps…

Since I’m new to AWS the first step should be…

  1. create an account at https://aws.amazon.com/
  2. create a user with “Programmatic access
  3. create a new group ( didn’t check any policies), didn’t add any tags
  4. And at the end save the “Access key ID” and “Secret access key”.

Now … to get Terraform, since I’m on a Windows machine and I have Chocolatey installed

choco install terraform
terraform version
From what I understand Terraform (.tf) files are divided into 4 sections, variables, providers, resources and outputs. Given this simple .tf file
# VARIABLES
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "private_key_path" {}
variable "key_name" {}

# PROVIDERS
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "us-east-1"
}

# RESOURCES
resource "aws_instance" "nginx" {
ami = "ami-c58c1dd3"
instance_type = "t2.micro"
key_name = "${var.key_name}"

  connection {
    user        = "ec2-user"
    private_key = "${file(var.private_key_path)}"
  }

  provisioner "remote-exec" {
    inline = [
      "sudo yum install nginx -y",
      "sudo service nginx start"
    ]
  }
}

# OUTPUTS
output "aws_instance_public_dns" {
    value = "${aws_instance.nginx.public_dns}"
}
We can easily figure out what it does… It has some variables for values like keys and secrets, it uses provider “aws” and for that provider, we have an aws_instance resource with the name “nginx”. We have “ami”, the name of the image to provision the instance and the “instance_type” of that instance. We’re also describing how a connection can be made, with user and a private_key. Using that connection after the resource is provisioned we’re going to remote-exec a couple of commands.

At the end we want the provider to output the “aws_instance_public_dns”.

Simple enough right?

There are many ways you can pass values to the .ts files, to start I choose to have a .tfvars file. Fill up with your values

aws_access_key = ""
aws_secret_key = ""
private_key_path = ""
key_name=""

With both files in place to “execute” them is as simple as

terraform init

https://www.terraform.io/docs/commands/init.html

terraform plan -var-file=terraform.tfvars

https://www.terraform.io/docs/commands/plan.html

terraform apply -var-file=terraform.tfvars

https://www.terraform.io/docs/commands/apply.html

If everything goes as planned you will have the output with a public DNS that you can browse to… *.compute-1.amazonaws.com

“Welcome to nginx on the Amazon Linux AMI!”

And the always usefull $$$$$

terraform destroy -var-file=terraform.tfvars
https://www.terraform.io/docs/commands/destroy.html

Notes :

Now… I did have some issues with the keys.

Next steps :

  • Provide de security group and inbound rules as a resource in the file
  • use Azure as a provider
  • remove the prompt ???

Hope you find it useful …

Cheers!

Posted in continuous delivery, continuous integration, devops, Tools | Leave a comment

(basic / usefull ) kubectl commands

Disclaimer: This is a list of commands/options I found most useful in my day-to-day activities, there are many commands/options available, you may find other commands/options more useful or use them in another way.

kubectl config get-contexts
kubectl config use-context <context>
kubectl config view

kubectl get pods
kubectl get services --all-namespaces
kubectl get namespaces
kubectl get deployments --namespace <namespace>

kubectl logs <pod name> 
kubectl describe pods <pod name>

kubectl exec -it <pod name> -- /bin/bash
kubectl describe secret <secret name>
kubectl delete pod <pod name> --force --grace-period=0
kubectl run -i -tty busybox --image=busybox -restart=Never -- sh
Posted in devops, kubernetes, Tools | Leave a comment

Docker – blog post series

A series of posts from the Microsoft App Consult Team about docker and deploying a multi-container app.

 

  1. First steps with Docker – Introduction
  2. First steps with Docker – “Dockerizing” your first application
  3. Introduction to Docker – Create a multi-container application
  4. Introduction to Docker – Deploy a multi-container application

Enjoy!

Posted in docker | Leave a comment

(basic / useful) Docker commands

Disclaimer: This is a list of commands/options I found most useful in my day-to-day activities, there are many commands/options available, you may find other commands/options more useful or use them in another way.

Basic ( runtime check )

docker -v
docker info

Basic ( listing )

docker ps (containers running)
docker ps -a (last run containers)
docker images (existing images)

Basic (creating / deleting )

docker pull [image name]
docker run -it [image name] [command] (runs a command in a container based on an image) 
docker stop [container name] (stops the container)
docker start -ai [container name] (starts the container)
docker stop $(docker ps -a -q) (stops all containers using ID)
docker exec -it [container name] [command]
docker container top [container name]
docker rm [container name] (removes a container)
docker container prune (removes all stopped containers)
docker rmi [image name] (removes the image)
docker rmi $(docker images -q) (removes all images using ID)
docker image prune (removes unused images)

What are your most useful commands?

Posted in docker | Leave a comment

Do you know you can override the == operator ?

Yes you can!

In order to override equality in Value Types we should :

  • implement IEquatable
  • override object.Equals()
  • implement ==
  • implement !=
  • implement object.GetHashCode()
public struct FoodStruct : IEquatable<FoodStruct>
{
    private readonly string _name;

    private readonly FoodGroup _group;

    public FoodStruct(string name, FoodGroup group)
    {
        _name = name;
        _group = group;
    }

    public string Name
    {
        get
        {
            return _name;
        }
    }

    public FoodGroup Group
    {
        get
        {
            return _group;
        }
    }

    public override string ToString()
    {
        return _name;
    }

    public bool Equals(FoodStruct other)
    {
        return _name == other._name && _group == other._group;
    }

    public override bool Equals(object obj)
    {
        if (obj is FoodStruct)
        {
            return Equals((FoodStruct)obj);
        }

        return false;
    }

    public static bool operator ==(FoodStruct left, FoodStruct right)
    {
        return left.Equals(right);
    }

    public static bool operator !=(FoodStruct left, FoodStruct right)
    {
        return !left.Equals(right);
    }

    public override int GetHashCode()
    {
        return _name.GetHashCode() ^ _group.GetHashCode();
    }
}

Check Simon Robinson course on Pluralight about C# Equality and Comparisons

Posted in c# | Leave a comment

Back to the basics…

While watching this course from K. Scott Allen I’ve re-learned some things about Object Oriented Programming, namely this ..

If you have a class…

public class GradeBook
{
    public List<int> ListOfNumbers { get; set; }

    public int ReturnLowest()
    {
        int lowest = int.MaxValue;

        foreach (int number in ListOfNumbers)
        {
            lowest = Math.Min(lowest, number);
        }

        return lowest;
    }
}

and a derived class…

public class AugmentedGradeBook : GradeBook
{
    public int ReturnLowest()
    {
        int lowest = int.MaxValue;
        foreach (var number in ListOfNumbers)
        {
            lowest = Math.Min(lowest, number);
        }

        ListOfNumbers.Remove(lowest);

        return base.ReturnLowest();
    }
}

The c# compiler will choose the method to run based on the type of the variable.

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 })]
[InlineData(new int[] { 5, 4, 1, 3, 2 })]
public void ReturnsLowestBaseClass(int[] listInts)
{
    GradeBook gradeBook = new AugmentedGradeBook();
    gradeBook.ListOfNumbers = listInts.ToList();

    var lowest = gradeBook.ReturnLowest();

    Assert.Equal(1, lowest);
}

Since we have a variable of type GradeBook gradeBook it will execute the method GradeBook.ReturnLowest();
On the other hand, if we have a variable of type AugmentedGradeBook gradeBook

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 })]
[InlineData(new int[] { 5, 4, 1, 3, 2 })]
public void ReturnsLowestOwnClass(int[] listInts)
{
    AugmentedGradeBook gradeBook = new AugmentedGradeBook();
    gradeBook.ListOfNumbers = listInts.ToList();

    var lowest = gradeBook.ReturnLowest();

    Assert.Equal(2, lowest);
}

it will execute AugmentedGradeBook.ReturnLowest();

To achieve polymorphism we can change the class GradeBook to use a virtual method and then override the behavior in another class.

public class GradeBook
{
    public List<int> ListOfNumbers { get; set; }

    public virtual int ReturnLowest()
    {
        int lowest = int.MaxValue;

        foreach (int number in ListOfNumbers)
        {
            lowest = Math.Min(lowest, number);
        }

        return lowest;
    }
}

and the new derived class

public class AugmentedVirtualGradeBook : GradeBook
{
    public override int ReturnLowest()
    {
        int lowest = int.MaxValue;
        foreach (var number in ListOfNumbers)
        {
           lowest = Math.Min(lowest, number);
        }

        ListOfNumbers.Remove(lowest);

        return base.ReturnLowest();
    }
}

this way we can have a variable of type GradeBook gradeBook and the executed method will be AugmentedVirtualGradeBook.ReturnLowest

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 })]
[InlineData(new int[] { 5, 4, 1, 3, 2 })]
public void ReturnsLowestVirtualAugmentedClass(int[] listInts)
{
    GradeBook gradeBook = new AugmentedVirtualGradeBook();
    gradeBook.ListOfNumbers = listInts.ToList();

    var lowest = gradeBook.ReturnLowest();

    Assert.Equal(2, lowest);
}

Hope it helps…
Cheers!

Posted in c#, Object Oriented Programming | Leave a comment

SSMS Templates : export and import

This week i’ve installed the SSMS  2014 and wanted to get my templates from SSMS 2012. Since there is no import / export feature i’ve found out this post from Grumpy DBA

In my case it was just copying from :

AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\Templates\Sql

TO

AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\Templates\Sql

Thanks Grumpy DBA

Grumpy DBA

Posted in SQL Server Management Studio | Leave a comment

MVC Layouts

I have found this very straightforward post about MVC Layouts…

http://www.dotnet-tricks.com/Tutorial/mvc/3WDE140613-Different-ways-of-rendering-layouts-in-Asp.Net-MVC.html

Simple but effective..

Posted in MVC | Tagged | Leave a comment