Friday, February 26, 2016

Docker Image for JBoss EAP

Docker Image for JBoss EAP 

Following post explains how to create Docker Image for JBoss EAP and expose its management and web 8080 port for access from host machine or other applications.

Before proceeding with this article you should have Docker and Docker Machine installed on your machine.

You can also refer to my previous post on how to create simple java post.

Dockerfile

Create a similar Docker file. This file is available at following Github repo - tuhingupta/docker-jboss-eap.


If you look at the dockerfile, you will notice:
at line 1, we start with FROM key word. This tells Docker what image to use as base image.
at line 2, we specify MAINTAINER that tells the name, email of the person maintaining the image
at line 4, WORKDIR specifies the working directory in the image.
at line 5, RUN keyword runs whatever command proceeds it.
at line 6, copy jboss-eap zip file to /usr/software folder in the image
at line 9, unzip jbos-eap zip
at line 15, setup user for jboss admin
at line 18, set JAVA_OPT . We need to bind address and management console address so that EAP will bind on all IP addresses for our container.
at line 21, EXPOSE command is used to expose ports from the container.
at line 26, ENTRYPOINT command tells what command will run when the container starts.

Save this file as Dockerfile in a folder that also contains jboss-eap-6.2.4.zip file.

Building the container 

Now you build the image using the following command:

$ docker build --rm -f Dockerfile -t jboss-eap .

Once the image is built, it is ready to be run.

Run docker image

Run the docker image

$ docker run -it -p 0.0.0.0:9990:9990 -p 0.0.0.0:8080:8080 --name jboss-serv -d jboss-eap

you will notice that we used -p option. 
-p option publishes a container's port(s) to the host.

This option publishes the ip that we bind in line 18 of Dockerfile so that it can be accessed from host by using localhost.

Accessing JBoss URLs

Now you can access JBoss management console using 
http://localhost:9990/management



Saturday, February 20, 2016

Multi-platform Hybrid Mobile App Development

Looking for a hybrid mobile app using ionic, cordova, angular.js.
Refer to a sample restaurant app developed using Ionic, Cordova and Angular JS
The backend data is provided using json-server.

Refer to the project on my Github site - https://github.com/tuhingupta/ionic-cordova

Post you comments/questions on github or on this blog for more information about the application or how to develop a similar mobile app.


Reference Docs:
http://ionicframework.com/docs/components/

Wednesday, February 3, 2016

Amazon EC2 - Install node application on EC2 instance.


Before working on this blog you must have the EC2 environment setup. Refer to my older blogs for the same.



Get your project

Use git to download your node.js application. 
I have my application on Github - https://github.com/tuhingupta/gitwebhooks

$ git clone https://github.com/tuhingupta/gitwebhooks.git
$ cd gitwebhooks

Configure EC2 to listen inbound traffic at 8080

Somethings need to be configured in your application so that it can be accessed over internet.

Have your node.js application run server over port 8080

In my application (gitwebhooks) above I have set it in app.js

app.set('port', process.env.PORT || 8080);

Now configure your EC2 instance to listen inbound traffic at port 8080

Setup your security groups in EC2 like image below:



Now route HTTP traffic on port 80 to redirect to port 8080

$ sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080

Access your application from internet

Now you can access your application over internet using your public DNS.

I can access my application (a Node.js Express REST API) using:

http://ec2-{my_ec2_id}.us-west-2.compute.amazonaws.com/api/name


Amazon AWS - Installing Git, Node.js and npm on EC2 instance

Before we setup Node.js on AWS, you should have AWS EC2 instance setup and you should be able to login using Putty or Terminal.

Refer to my previous blog on how to setup EC2 instance -
 http://javaredhot.blogspot.com/2016/02/amazon-ec2-creating-and-setting-up.html

Now login to EC2 instance

Install Git

$ sudo yum install git
This will ask for your confirmation and then install git.


Install Node.js

To install node and npm following steps need to be performed.

To compile node we need gcc, make and git to import node source code:
sudo yum install gcc-c++ make
sudo yum install openssl-devel
sudo yum install git
Cloning node.js source code:
git clone https://github.com/nodejs/node.git
Compile and install node.js
cd node
./configure 
make
sudo make install
Add user´s directory to BIN Paths (node binaries location)
sudo su
nano /etc/ec2-user
Inside the editor scroll to where you see the line: 
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Append the value :/usr/local/bin
In some cases node does not install at /usr/local/bin and there is no soft link to the actual location. So in that case you can create a soft link from actual node location to /usr/local/bin

$ cd /usr/local/bin
$ sudo ln -s  /home/ec2-user/node/out/Release/node node
$ sudo ln -s /home/ec2-user/node/out/lib/node_modules/npm/bin/npm npm
$ sudo ln -s /home/ec2-user/node/out/lib/node_modules node_modules

Install npm

git clone https://github.com/npm/npm.git
cd npm
sudo make install

Test if node is working:

node
References:

https://gist.github.com/isaacs/579814
http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/

Amazon EC2 - Creating and setting up an instance on AWS

Setup AWS account

Set up AWS account at - https://aws.amazon.com/


Launch EC2 instance

On AWS console, 
  • Go to AWS services dropdown and select EC2 instance
  • Create and launch EC2 instance



Select Container and configure


  • I selected Amazon Linux
  • Using the configuration available as Free Tier.

Once setup & review is complete you are now provision your instance. And it will be ready to launch



Login to the instance


You can use Mac terminal or Putty on Windows to connect AWS instance.

Store pem file downloaded when creating instance. Make sure that the permissions are restrictive. Hence use 
$ chmod 400 aws.pem

Now use ssh command to connect to instance

ssh -i /path/my-key-pair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com

For more details on how to ssh, read here - http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html