Tips and Tricks in a world of Mix

Taken from http://ift.tt/2kd10Q1

How to use Vagrant on Windows

2015/01/25

"Vagrant logo"

This article shows how to deal with Windows’ specificities while trying to work with Vagrant. If you are not familiar at all with the latter, I suggest you go through this Vagrant tutorial first.

Note: the following was tested on Windows 8, but the steps described below shouldn’t change too much between the different versions.

Vagrant ssh

The first issue I came across was that vagrant ssh doesn’t work out of the box. I was greeted with a constructive message:

`ssh` executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of witch contain an SSH client. Or use your favorite SSH client with the following authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/path/to/project/.vagrant/machines/default/virtualbox/private_key

Fine. Let’s install Git, then (considering it is not already the case).

Git install

The key is when the “Adjusting your PATH environment” screen pops up:

"Adjusting your PATH environment screen"

You want to select “Use Git and optional Unix tools from the Windows Command Prompt”.

Now I know the message in red looks quite scary, but honestly, unless you are a hardcore user of the Windows console, there is not much to worry about. Basically it will override some of the commands and add a few others.

Personally, it never caused me any trouble.

If you are still a bit worried tho, be reassured: none of this is irreversible. All you would need to do is uninstall Git, or update the PATH variable removing the incriminated part.

More on that in a minute.

Try to vagrant ssh your VM again, this time it should do it (you might need to open a new terminal for the update to take effect, tho).

What if Git is installed already?

Well, it was the case for me as well.

You could always remove it and install it again, but there is another way.

You will have to do manually what the installation of Git could have done for you, but fortunately it is quite trivial:

  • Open the Control Panel
  • Go to System and Security
  • Click on System, then on the Change Settings button
  • Display the Advanced tab and click on Environment Variables…
  • Look for the Path variable in the System variables list, select it then Edit…

At the end of the string, add the path to Git’s bin (something like “C:\Program Files\Git\bin”) (don’t forget to add a semicolon first to separate it from the previous path):

"Edit the PATH variable"

Validate and close the different menus. Try to vagrant ssh your box again, it should work (again, you might need to open a new terminal first).

You probably guessed it already, but if you don’t want Git’s commands to override the Windows ones anymore, all you need to do is to remove that bit.

You will need to find another way for ssh to work though!

Ah, but wait. There is another way.

PuTTY

Remember that error message we initially got trying to ssh the box? Let’s have a look at the second part of it:

Or use your favorite SSH client with the following authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/path/to/project/.vagrant/machines/default/virtualbox/private_key

I wasn’t joking when I said it was constructive, because it really tells you what to do.

The Windows console works ok but let’s be honest, in the long run it is a real pain to use. It does the trick for a quick vagrant ssh but when the time comes to actually do some work on an Ubuntu server for example, a better shell is desirable.

Enter PuTTY

PuTTY is a very lightweight tool that allows to do a lot of cool stuff. Some of you are probably familiar with it already, and using it jointly with Vagrant is quite nice.

We will use it to ssh our boxes, and rely on the info given by the message above to that purpose.

First, download it if that is not the case already (the first putty.exe link will do).

Download puttygen.exe as well, we are going to need it.

PuTTY and PuTTYGen are stand-alone applications (no need to install them), so just double click on the .exe files.

Let’s open PuTTYGen first: PuTTY uses its own key format, and we need to convert Vagrant’s one first. Click on File then Load private key, select the file indicated by the error message earlier (e.g. “C:/path/to/project/.vagrant/machines/default/virtualbox/private_key”).

Once selected, PuTTY is kind enough to tell us what to do with it:

"PuttyGen"

Ensure SSH-2 RSA is selected, and that the number in Number of bits in a generated key is 2048. Then click on Save private key (don’t set a passphrase) and save it under your own user directory’s .ssh folder, as “vagrant_private_key”. From now on, we will use this key for all the Vagrant boxes.

Close PuTTYGen and open PuTTY. In the Hostname field, type 127.0.0.1. In the Port one, 2222. Ensure SSH is selected and, in the Saved Sessions field, type vagrant and click Save:

"Putty SSH connection configuration 1"

Go to Connection then Data, and in the Auto-login username field, enter “vagrant”:

"Putty SSH connection configuration 2"

Next, still under Connection, go to SSH then Auth. Browse for the key you generated earlier in the Private key file for authentication field. Now head back to the Session menu, save again the “vagrant” one.

Now click on Open: if everything went alright, you should now be in your Vagrant box \(^o^)/

Using multiple Vagrant boxes simultaneously

Now let’s say you already have a box running, and you need to start a second one. You vagrant up it, the Virtual Machine boots and you want to SSH it. But all the boxes cannot use the same SSH port!

It all happens when the box is being booted:

"Windows console"

See the highlighted line? Seeing port 2222 was busy already, Vagrant picked the port 2200 instead.

Now to SSH it using PuTTY, open it, load the “vagrant” session, and in the Port field, replace “2222” with “2200”. Click Open: there you are, connected to the second box.

Known limitations

Shared folders and symlinks

One of the fairly known limitations of using Vagrant on Windows with VirtualBox is that the latter won’t let you create symlinks on the shared folders for security reasons. This quickly becomes problematic when dealing with npm packages, for example.

One of the workarounds is to use the “no bin link” parameter (e.g. npm install --no-bin-link), but this is not always enough.

Fortunately, there is a way to bypass this restriction. In your Vagrantfile, add the following piece of config:

config.vm.provider "virtualbox" do |v|
  v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end

As Windows won’t let standard users create symlinks, you now need to start your Vagrant box in administrator mode (open a Windows terminal in admin mode before running vagrant up, for example). Make sure no other box is already running though, as it won’t start if VirtualBox is already running in standard mode.

Maximum path length

Another recurring problem comes from the fact that Windows’ maximum length for a path is 255 characters. Again, this is quickly an issue when dealing with npm packages, especially when they have dependencies, themselves having dependencies, etc.

The solution in that case is to create a symbolic link between the “node_modules” directory and another directory outside of the shared folders.

Which brings us to our practical example.

Practical example: npm packages

So you have this project relying on npm packages. You tried to install them using --no-bin-link but no luck, looks like some of the paths are too long.

Fear not, Macless: update your Vagrant config as shown above to allow the creation of symlinks, boot your VM in admin mode, create a destination directory for your npm packages somewhere outside of the shared folder and create a symlink between it and the “node_modules” one:

mkdir ~/node_modules
ln -s /home/vagrant/node_modules /vagrant/node_modules
cd /vagrant
npm install

Et voilà.

Note: this implies preventing the “node_modules” directory from being versionned.

Conclusion

Here you go, now using Vagrant on Windows in decent conditions.

The process can look a bit convoluted, and really it is. It took me quite a while to put everything together, and if today I am rather satisfied, I am still a bit bugged about the multiple Vagrant boxes part. Having to check the SSH port and update it in the PuTTY session everytime is a bit annoying, even though dealing with several instances at the same time might be an edge case.

Anyways, if you have any suggestions about that, don’t hesitate to leave a comment.

ang1_1.png

 

Working with components allow us to use the life cycle hooks .

Enables separating instantiating and initialization to build a model steps.

Instantiating not interact with services for instance.

 

 

So now we can use the $onInit hook to get the data using the $http service after separating the controller logic to a private function.

ang1_2.png

We divide the logic from the controller and just use the function of fetching the movies by usage of $http.

 

Pay attention –

import the annotation of dependencies to the controller definition of the component using array.

initialize the movies as empty array at the controller.- thus , nullifying the previous values. 

 

Now at the template we can create a relevant table with some actions buttons.

ang1_3.png

Using emmet plugin we are creating the bootstrap pattern for table with buttons using the glyphicons to up vote and down vote the movies.

 

Now we add the logic of up and down voting to the controller.

ang1_4.png

We are setting conditions to be more than 1 and less than 5. Simple logic to be improved if needed.

 

In component we always build an element with isolated scope. It is less dynamic then building the directives but it is a best practice and does answer 95% of scenarios needed for business app.

ang1_5.png

 

If we want to change our rating to component we can create it separately (instead of directive as we would do it in the past).

SO we create the files for it – component and html for it.

We’ll add the glyphicons to show the stars at the html of the component of the ratings

ang1_6.png

We’ll create a transclude content for the stars with astrix , this way if none defined from external source the astrix will be shown.

ang1_7.png

 

and inside the component we will define the transclude as true to enable the injection of the glyphicons into the component.

ang1_9.png

the binding “<” says that we will get the data from external source from outside world.

controllerAs changes the $ctrl to model name using isolated scope.

the transclude = true says that if no data will be entered from outside we will use inner data to init the visuals.

 

ang1_8.png

 

Testing definitions :

 

ang1_10.png

So now we create the karma test using the controller initialization to movieList and use it to initialize the controller getting back the controller from the component

ang1_11.png

Adding the routing

ang1_12.png

Adding ngRoute to the module and creating extra component and adding the routingang1_13.png

 

 

Heroku Demo online

msgBoard.png

Download Demo at – Github repository with explanations in Readme

angular2_nodejs_connection

Seeder of all levels to work with Node.js Express with MongoDb and Angular2 – each branch different stage. Connecting Angularjs with nodejs

Demo Heroku Deployed

Demo AWS Deployed

Both use mlab.com as a source for MongoDB database

Node.js

Download node.js https://nodejs.org/en/download/ Now we can use npm – node package manager –http://blog.npmjs.org/post/85484771375/how-to-install-npm

First Command Line run to run node.js server

npm run build  

Second Command Line to run the angular client ( views of node for now)

npm start

MongoDB

Download MongoDB https://www.mongodb.com/download-center?jmp=nav#community And install

To use MongoDB after installation add packages

    Ø npm install --save mongoose
    Ø npm install mongoose-unique-validator   (--this one is for unique fields)

For running MongoDB server for me it worked specificly with –dbpath “e:\data\db” only

cd E:\MongoDB\Server\3.2\bin
E:\MongoDB\Server\3.2\bin>mongod.exe --dbpath "e:\data\db"

More there – Github repository with explanations in Readme

 

 

P.S.

The project based on this course

https://www.udemy.com/angular-2-and-nodejs-the-practical-guide

 

I’ve created some time ago a local MDF file with a bunch of tables for use. So now I want to get back to it and implement it through the edmx Ado.Net template

untitled-picture1

After I’ve added the mdf local db file to the App_DATA folder I can now connect it to the automatic created scheme like this –

untitled-picture2I will go through the wizard and choose the objects of tables to recreate at the edmx model

At the end I will have the objects created with C# from DB for me by this automatic process.

untitled-picture3

Rebuild your solution to make everything checked and ready to go!

I am adding a controller

untitled-picture4

By description I want the scaffold to build everything for me – including the view representation of my objects.

untitled-picture5

Choosing the entity to render

untitled-picture6

After a lot of thinking on his part I am getting new files in the solution folders structure

untitled-picture7

That’s it.

Modell .edmx 
Modell Context.tt 
Modell .Context.cs 
Modell Designer.cs 
Modell .edmx.diagram 
Modell .tt 
A dress.cs 
Event.cs 
Events EventDetaiIs.cs 
EventType.cs 
LocationDetaiI.cs 
Modell 
Place.cs 
PlaceForm.cs 
PlaceScope.cs 
SocialNetwork.cs 
sysdiagram.cs 
User.cs 
UserFriend.cs 
Users UserDetaiIs.cs 
Users_UserSecurity.cs 
WorkDetaiI.cs

This slideshow requires JavaScript.

You can downgrade to Django 1.8

pip uninstall django # just for explicity
pip install django==1.8

then

python manage.py runserver

logo_final_kai.gif

So , people that know me , know that I am no big follower for SharePoint tech. It’s always to slow and buggy.

From today’s review I got a few insights and a summary that will get you started if you’d choose it.

Read the rest of this entry »

AWS getting logs

This slideshow requires JavaScript.

1

Go to applications – see comething is wrong

2

See warning or error inside

3

See details of the warning/error

4

If not enough – go to logs, set logs per request, get 100 first and download it

Tag Cloud

%d bloggers like this: