Part 1: Technologies that we will use and why
Part 2: Getting your local development environment started with Vagrant and Ansible
Part 3: Getting started with Docker and Jenkins
Part 4: Using Docker in AWS through Ansible
Wow, you got this far eh? Well, you are almost done! Let’s start chopping.
AWS lets us make a new account and have access to a free tier instance. And we will do just that. So first go make your new account. You will need to pair your account with a credit card. But don’t worry, you won’t get charged a thing for free tier if you follow the limits of usage from Amazon. If you still don’t feel secure enough you can make an alert in case something is billed.
So after you have your account activated go to your AWS Console and click in EC2. EC2 instances are “servers” that you rent from Amazon.
Ok now from the EC2 page click the blue button that says Launch Instance.
From there we are going to choose the Ubuntu 14.04 AMI eligible for free tier.
Then we are going for the t2.micro or the correspondent free tier type.
Then click next until you reach Tag Instance and choose to add the Name Docker.
The click next and in Configure Security Group create a new rule to open the TCP port 3000 for Express.
And finally launch the instance! And when it asks you for a key pair. Tell Amazon to make a new key pair, call it Ansible and download it.
And you are done. A new instance should be running in a few seconds.
And remember to save your Public DNS and Public IP. You will need them.
So now log in into your Vagrant machine and lets start that configuration cooking. We are going to do the process manually and then run it through Jenkins. So first copy your Ansible.pem file to the project folder so it replicates to the Vagrant machine. I usually put it inside the ansible folder. Then follow this commands.
ssh-agent
sudo cp /vagrant/ansible/Ansible.pem ~/.ssh/
sudo chmod 600 ~/.ssh/Ansible.pem
ssh-add ~/.ssh/Ansible.pem
Now you can enter your AWS instance. Run the command sudo ssh ubuntu@{{Public DNS}} -i ~/.ssh/Ansible.pem where {{Public DNS}} is your instance’s Public DNS. Type yes, and congratulations your are inside your AWS Ubuntu instance.
The default user for Ubuntu AMIs is ubuntu.
Now that we can connect to our AWS instance lets try to run the Ansible playbook. We are going to connect to our AWS instance, install Docker and Run our Node app. Run sudo ansible-playbook -i “{{Public IP}}”, /vagrant/ansible/first.yml --extra-vars “build=v0 ouruser={{ouruser}}” --private-key ~/.ssh/Ansible.pem
where {{Public IP}} is your instance’s Public IP and {{ouruser}} is your user. You should receive a satisfactory run from Ansible. To check your new Docker Node app go to your Public DNS address on port 3000.
Now we can go back to our Jenkins server and run a build. Just remember to change your {{ouruser}} in the last script of the configuration. You can even change the code from the app to say something different. In my case my name.
Remember to change the app.js and the test.js files for the new message you want to try out.
Well that is the end of this series. I hope you enjoyed it as much as I did. Follow me on Twitter, if you so desire, for new tutorials and interesting news. On my next project list I’ll work with something around this lines:
If you find any of this topics interesting or you want me to check one you propose leave it in the comments and I’ll look at it. Hasta la próxima!