In this class, we're going to build up a simple deployment server from scratch. We're going to do it all by hand so that you can see all the different steps that are involved. And then later on in other classes, I can show you some automation tools that make all of this easier. But the idea here is to get a sense of the different concepts involved in deploying to a server.
So on the left I've got some code. This is going to be our application. And it's not going to use any particular application level framework. It's just going to use Node.js as its runtime. But this could be a Ruby application. It could be a Meteor application. It could be any of the other frameworks. I just made one completely from scratch so we could keep things as simple as possible.
And what you should be able to do by the end of this class is to type get push deploy master. And this should trigger a deploy workflow, just like what you see here, that brings up our latest changes on the deployment server and makes the web application available to the users, just by using get.
It's going to listen on port 3,000. And that's pretty much all this application does. You can go through and take a look at this source code. The two path method up here is going to look for these files in the Application directory of the project. So you see this two path. If you're wondering what that's all about, that's going to look inside of this folder for these various files.
And inside of that, we've got our regular app, HTML. And that's going to be the HTML for the application. And notice that the HTML file is going to look for an app.css file and also the app.js file. And so those are located in the App directory as well.
The application gs file has a simple es 6 class in it, and will create a new instance of that and call the text method. And that'll just return hello world. And then down here, we're not using any jQuery or anything fancy. We're just going to use the regular document object model, add an event listener for the DOMContentLoaded, and then search for the element on the page that has this data attribute. When we find it, we'll go ahead and change it to enter HTML to hello world.
To run the application locally, you can type bin and then that server file is actually an executable itself. So I can just type bin/server, and you'll need Node.js installed on your local machine, on your Mac or your PC. If you have Node.js installed, you should be able to just type this and it starts up the server listening on port 3,000.
You'll also notice there's a Vagrant configuration file, a Vagrant file in the project, which will allow us to use a virtual server and that's the one that we're going to be deploying to. I'm using a virtual server here because I think it makes it much easier to play around with deployment concepts when they're local. At some later time, I'll show you how to do this on Amazon and some of the other service providers. But for now, we'll just work on our local machines.
And if I scroll down a little bit, notice that I've also given this virtual machine an IP address that we can access at 192.168.33.10. In the prerequisites, I'll link to the video that shows you how to use Vagrant if you're not familiar with it already.
We can start up the Vagrant server by typing Vagrant up. And that'll bring up the virtual machine, and then we can SSH into it by typing Vagrant SSH. Now this drops me into the Boom 2 instance, running the wily 64-bit operating system. I can press Exit, and that will get me out of it. So we're going to be deploying to that server.
Now, I would like to be able to SSH into that machine using the regular SSH commands instead of typing Vagrant SSH. And if you recall from the SSH class, you don't have to have seen that one but it will make it a little bit more intuitive what's happening here, I want to update my SSH configuration file to include this particular host.
So to do that, I need to get the SSH config to begin with. And I can type Vagrant SSH config. And then will print a standard out, the SSH configuration for this virtual machine. What I want to do is to add us to the end of my regular SSH config, and then I can just use SSH like usual. So I'll type Vagrant SSH config, and we'll send that, we'll append it to, the config file in my home directory's SSH folder.
Then we'll open it up. And I'm going to change the name of the host to something a little bit more-- something that's a little bit more of a useful name. Inside my SSH config file, notice we've appended at the end here a new host called Default. And it's going to map to the local host, host name with the user Vagrant. And here's the port. And it's going to use the identity file that's located in that project.
So if I move the project to a different folder, keep in mind you'll have to change the location here of the identity file. And let me change the host from Default to Deploy. So that way we can just type SSH deploy, that'll land us right inside of the Boom 2 instance.
Let's test it out and make sure it's working, SSH deploy. And if we did it correctly, it should land us right inside of our virtual machine and everything looks OK so far. We can exit again to get back to our laptop.
Another reason to set up that centralized SSH config is that get is going to use SSH under the hood to find our server and authenticate. So this will be like we have a server actually running on Amazon or in some remote location, except that it's just really a virtual machine. But we're going to trick our system into believing that it's a remote machine. And now we can just use SSH and get like we would with any other remote machine.
In this class, we're going to be doing a lot by hand. I'm not going to use any other tools. We're just going to use the regular operating system and some of the concepts that we learned from the other servers and tools classes, like the shell, users and groups, and SSH. So go back and watch those classes if anything doesn't make sense.
But let me give you a little bit of advice. Even if I'm moving quickly and you see something that you don't understand, watch it anyway because just even seeing it is beneficial. And later on the concepts will gel as you practice the concepts more and more yourself. So even if something doesn't make sense, just go ahead and watch.
I'll link to the other classes that fill in all the prerequisite knowledge so you can watch those as well. But you don't necessarily have to watch them all in order. So take a look at the prerequisites link down here in the body. And, as always, if something really resonates with you, if you like a piece of content in the class, it's really useful and helpful to me if you're able to share that with your friends and help me spread the word. It helps me get new users, and that I always like.
So with that, we should be all set up to get into the class. So let's get started.