/ip-org-resolver

IP:OrgName resolver

Primary LanguageKotlinApache License 2.0Apache-2.0

IP Org Resolver

An application continuum style example using Kotlin and Ktor that includes a single web application with two background workers.

  • Basic web application
  • Data analyzer
  • Data collector

Technology stack

This codebase is written in a language called Kotlin that is able to run on the JVM with full Java compatibility. It uses the Ktor web framework, and runs on the Netty web server. HTML templates are written using Freemarker. The codebase is tested with JUnit and uses Gradle to build a jarfile. The pack cli is used to build a Docker container which is deployed to: Heroku Cloud on Heroku's Cloud Platform. Continuous Integration - GitHub Actions Continuous Deployment - Heroku Pipeline

Getting Started

Building a Docker container and running with Docker.

Buildpacks

  1. Install the pack CLI.

    brew install buildpacks/tap/pack
  2. Build using pack.

    pack build ip-org-resolver --builder heroku/buildpacks:20
  3. Run with docker.

    docker run  -e "PORT=8882" -e "APP=applications/basic-server/build/libs/basic-server-1.0-SNAPSHOT.jar" ip-org-resolver

Development

The below steps walk through the environment setup necessary to run the application in both local and production environments.

Install dependencies

  1. Install PostgreSQL.

    brew install postgresql
    brew services run postgres
    brew status (you should see postgres running)
  2. Install Flyway.

    brew install flyway
  3. Create a PostgreSQL database.

    createdb

Set up the test environment

  1. Create the ip_test database.

    psql -c "create database ip_test;"
    psql -c "create user dcp with password 'dcp';"
  2. Migrate the database with Flyway.

    flyway -cleanDisabled="false" -user=dcp -password=dcp -url="jdbc:postgresql://localhost:5432/ip_test" -locations=filesystem:databases/iporg clean migrate
  3. Build a Java Archive (jar) file.

    ./gradlew clean build

    Set up the development environment

  4. Create the ip_development database.

    psql -c "create database ip_development;"
  5. Migrate the database with Flyway.

    flyway -cleanDisabled="false" -user=dcp -password=dcp -url="jdbc:postgresql://localhost:5432/ip_development" -locations=filesystem:databases/iporg clean migrate
  6. Configure the port that each server runs on.

    export PORT=8881

Run the servers locally using the below examples.

Web application

java -jar applications/basic-server/build/libs/basic-server-1.0-SNAPSHOT.jar

Data collector

java -jar applications/data-collector-server/build/libs/data-collector-server-1.0-SNAPSHOT.jar

Data analyzer

java -jar applications/data-analyzer-server/build/libs/data-analyzer-server-1.0-SNAPSHOT.jar

Testing

run: ./gradlew tests

Unit Tests:

  1. components/endpoints/src/test/java/test.collective.ip.IpToOrgWebAPIResolverTest.java
  2. applications/basic-server/src/test/kotlin/test/collective/start/AppTest.kt

Integration Test:

  1. applications/basic-server/src/test/kotlin/test/collective/start/AppTest.kt (fun testPostValidIPAddressFormat())

CI/CD

On every push a github action is triggered that runs the unit and the integration test. After that a docker image is created that is deployed to the heroku. The file .github/workflows/ci.yml can be changed to alter the deployment strategy accordingly. The docker file Dockerfile creates the heroku docker image.