Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**
!target/*.jar
.*
examples
target
#!target/*.jar
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ env:

script:
- mvn clean verify -Drevisison=$(date +%Y-%V)
- docker build --build-arg MAXMIND_LICENSE_KEY=${MAXMIND_LICENSE_KEY} -t observabilitystack/geoip-api:latest -t observabilitystack/geoip-api:$(date +%Y-%V) .
- docker build --build-arg MAXMIND_LICENSE_KEY=${MAXMIND_LICENSE_KEY} -t observabilitystack/geoip-api:latest -t observabilitystack/geoip-api:native -t observabilitystack/geoip-api:$(date +%Y-%V) .
- ./test-native-image.sh

before_deploy:
- export TRAVIS_TAG=${TRAVIS_TAG:-$(date +%Y-%V)}
- GIT_COMMITTER_DATE=$(date -R) git tag -fm '${TRAVIS_TAG}' ${TRAVIS_TAG}

deploy:
- provider: script
script: bash push-to-dockerhub.sh
script: ./push-to-dockerhub.sh
on:
branch: master
- provider: releases
Expand All @@ -34,4 +35,4 @@ deploy:
skip_cleanup: true
body: Updated MaxMind GeoLite database as of ${TRAVIS_TAG}
on:
branch: master
branch: master
40 changes: 33 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
FROM openjdk:11.0.8
ARG MAXMIND_LICENSE_KEY
# build stage
FROM oracle/graalvm-ce:20.2.0-java11 AS builder

ADD . /build
WORKDIR /build

# For SDKMAN to work we need unzip & zip
RUN yum -y install unzip zip
RUN \
# Install SDKMAN
curl -s "https://get.sdkman.io" | bash; \
source "$HOME/.sdkman/bin/sdkman-init.sh" && \
sdk install maven && \
# Install GraalVM Native Image
gu install native-image && \
native-image --version && \
mvn --version && \
java -version && \
ls -la .

# place app
COPY target/*.jar /opt/geoip-api.jar
# build image
RUN source "$HOME/.sdkman/bin/sdkman-init.sh" && mvn -P native clean package

# run stage
FROM centos:7.8.2003
ARG MAXMIND_LICENSE_KEY

# download current maxmind databases
WORKDIR /srv
RUN curl -sSL "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz&license_key=${MAXMIND_LICENSE_KEY}" | tar -xz && \
#RUN apk add curl && \
RUN yum install -y tar gzip && \
curl -sfSL "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&suffix=tar.gz&license_key=${MAXMIND_LICENSE_KEY}" | tar -xz && \
ln -s GeoLite2-City_*/GeoLite2-City.mmdb .

# place app
COPY --from=builder "/build/target/geoip-api" /srv/geoip-api

ENV CITY_DB_FILE /srv/GeoLite2-City.mmdb
HEALTHCHECK --interval=5s --timeout=2s CMD curl -f http://localhost:8080/actuator/health
HEALTHCHECK --interval=5s --timeout=1s CMD curl -f http://localhost:8080/actuator/health
EXPOSE 8080
CMD exec java ${JAVA_GC_OPTS} ${JAVA_OPTS} -jar /opt/geoip-api.jar
CMD exec /srv/geoip-api
88 changes: 78 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<version>2.3.4.RELEASE</version>
</parent>

<licenses>
Expand Down Expand Up @@ -63,8 +63,26 @@
<!-- This build builds a docker image, there is no maven artifact to install or deploy -->
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>

<start-class>com.s24.geoip.GeoIpApi</start-class>
</properties>

<!-- for spring-graal-native -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -74,12 +92,14 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -89,10 +109,22 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-graalvm-native</artifactId>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
Expand All @@ -108,15 +140,51 @@
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>20.2.0</version>
<configuration>
<buildArgs>
-J-Xmx4G
-H:+TraceClassInitialization
-H:+ReportExceptionStackTraces
-H:ReflectionConfigurationFiles=/build/src/main/resources/reflection-config.json
-Dspring.graal.remove-unused-autoconfig=true
-Dspring.graal.remove-yaml-support=true
</buildArgs>
<imageName>${project.artifactId}</imageName>
</configuration>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Empty file modified push-to-dockerhub.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/main/java/com/s24/geoip/GeoIpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SpringBootApplication
@SpringBootApplication(proxyBeanMethods = false)
public class GeoIpApi {

private static final Logger logger = LoggerFactory.getLogger(GeoIpApi.class);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/s24/geoip/web/GeoIpRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ public ResponseEntity<Void> handleKnownNotFounds() {
/**
* Lookup the geolocation information for an ip address.
*/

@GetMapping("/{address:.+}")
public ResponseEntity<GeoIpEntry> lookup(@PathVariable InetAddress address) {
public ResponseEntity<GeoIpEntry> lookup(@PathVariable("address") InetAddress address) {
return ResponseEntity.of(geolocations.lookup(address));
}

Expand Down
102 changes: 102 additions & 0 deletions src/main/resources/reflection-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
{
"name" : "com.s24.geoip.GeoIpEntry",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.model.CityResponse",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.City",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.Continent",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.Location",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.Postal",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.Country",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.RepresentedCountry",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.Subdivision",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.record.Traits",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "com.maxmind.geoip2.NetworkDeserializer",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}
]

23 changes: 23 additions & 0 deletions test-native-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

# clean up after test
function shutdown {
docker rm -f geoip-native-test
}
trap shutdown EXIT

# launch docker
docker run -dp 18080:8080 --name geoip-native-test observabilitystack/geoip-api:native
sleep 1

# execute some curls
curl -fso /dev/null "http://localhost:18080/actuator"
curl -fso /dev/null "http://localhost:18080/actuator/health"
curl -fso /dev/null "http://localhost:18080/actuator/prometheus"
curl -fso /dev/null "http://localhost:18080/$(curl -s https://ifconfig.me/ip)"
curl -fso /dev/null "http://localhost:18080/8.8.4.4"
curl -fso /dev/null "http://localhost:18080/8.8.8.8"
curl -fso /dev/null "http://localhost:18080/206.80.238.253"
curl -fso /dev/null "http://localhost:18080/2.161.45.64"
curl -fso /dev/null "http://localhost:18080/5.4.55.34"