Skip to content

gkirok-deploy/perl

 
 

Repository files navigation

Geo::IPinfo

Official ipinfo.io Perl library. Running into Non official docker container.

REQUIREMENTS

LOCAL RUNNING IN DOCKER

  1. clone project
  2. create file ipinfo.token contains token as described above
    $ cat ipinfo.token
    1234567890abcd
  1. build test image and run

    • docker build --build-arg RELEASE_TESTING=yes . -t gkirok/ipinfo:test
    • docker run -it gkirok/ipinfo:test
  2. build image

    • docker build . -t gkirok/ipinfo:latest
  3. run container

    • run as web service
      • docker run -d -v ipinfo.token:/opt/ipinfo.token -p 80:8080 --name ipinfo gkirok/ipinfo:latest
      • curl localhost/IP_YOU_WANT_TO_DESCRIBE

    OR

    • run single request
      • docker run -d -v ipinfo.token:/opt/ipinfo.token -p 80:8080 --name ipinfo gkirok/ipinfo:latest IP_YOU_WANT_TO_DESCRIBE

DEPLOY IPINFO TO AWS EC2 USING JENKINS PIPELINE

REQUIREMENTS

  1. aws credentials with full ec2 premissions
  2. installed Jenkins Pipeline server with configured docker, terraform and ansible

WHAT HAPPEN

By default ipinfo web server will be deployed as docker container to t2.micro ec2 instance, has been accessed by http to all, and by ssh from jenkins server and user 'access' server.

JENKINS PIPELINE STAGES

  • docker: build test image - building test image and running unit tests
  • docker: build & push image - building deploy image and push it to registry
  • terraform: pull & init - pulling terraform image and init project terraform folder
  • terraform: plan - create plan for deployed ec2 server and security group
  • terraform: apply - deploy ec2 server and security group
  • ansible: requirements - install required software as docker
  • ansible: deploy - pull new image and redeploy ipinfo container
  • result - print ip of deployed server

HOW TO START

  1. ssh connect to your jenkins server and generate private/public keys have been using to connect to ec2 server. and save it as ~/.ssh/tikal and ~/.ssh/tikal.pub
  2. add these credentials parameters to your jenkins server
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • JENKINS_IP
    • ACCESS_IP
    • ipinfo_token
    • private key using to connect to ec2 server by ansible from step 1 ('3276ccf3-13bc-4408-b815-7b07bfd4e972' in Jenkinsfile)
    • github credentials
    • hub.docker.com credentials
  3. fork project
  4. create project in hub.docker.com
  5. edit Jenkinsfile, commit and push changes
    • replace ids of credentials have been configured in step 2.
    • update global variables
  6. create new pipeline with forked project and run it
  7. go to browser and enter ip of deployed server and ip yuu want to describe
    • for example: http://54.54.54.54/8.8.8.8

LOCAL RUNNING BY PERL

EXAMPLE

use Geo::IPinfo;

my $token = "1234567";

# if you have a valid token, use it
my $ipinfo = Geo::IPinfo->new($token);

# or, if you don't have a token, use this:
# my $ipinfo = Geo::IPinfo->new();

# return a hash reference containing all IP related information
my $data = $ipinfo->info("8.8.8.8");

if (defined $data)   # valid data returned
{
  print "Information about IP 8.8.8.8:\n";
  for my $key (sort keys %$data )
  {
    printf "%10s : %s\n", $key, $data->{$key};
  }
  print "\n";
}
else   # invalid data obtained, show error message
{
  print $ipinfo->error_msg . "\n";
}

# retrieve only city information of the IP address
my $city = $ipinfo->field("8.8.8.8", "city");

print "The city of 8.8.8.8 is $city\n";

OUTPUT

Information about IP 8.8.8.8:
      city : Mountain View
   country : US
  hostname : google-public-dns-a.google.com
        ip : 8.8.8.8
       loc : 37.3860,-122.0840
       org : AS15169 Google LLC
     phone : 650
    postal : 94035
    region : California

The city of 8.8.8.8 is Mountain View

RUNNING TEST

  • export RELEASE_TESTING=yes && for i in *.t; do /bin/perl -T $i; done

USAGE

For details about how to use the library, install it and then run:

perldoc Geo::IPinfo

Before submitting to CPAN

Make sure ALL tests executed without errors; to do this, run:

$ cd Geo-IPinfo/
$ perl Makefile.PL
$ RELEASE_TESTING=1 make test

In particular, pay attention to the result of the execution of 't/01-usage.t'; to see more detailed information about the execution of this test, run:

$ RELEASE_TESTING=1 prove -bv t/01-usage.t

About

Official Perl client library for IPinfo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Makefile 56.7%
  • Perl 34.1%
  • HCL 5.4%
  • Dockerfile 3.0%
  • Shell 0.8%