Add GitHub workflow
This commit is contained in:
parent
69eea2ebf4
commit
a1c6a29eea
6 changed files with 47 additions and 23 deletions
16
.github/workflows/docker-image.yml
vendored
Normal file
16
.github/workflows/docker-image.yml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["**"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["**"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Build the Docker image
|
||||||
|
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
|
8
pom.xml
8
pom.xml
|
@ -13,7 +13,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.7.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
|
@ -39,11 +39,7 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.13.0</version>
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<target>8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
|
@ -14,6 +14,8 @@ import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
@ -23,17 +25,16 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
||||||
|
|
||||||
public static final AttributeKey<HttpRequest> ATTR_REQUEST = AttributeKey.newInstance("request");
|
public static final AttributeKey<HttpRequest> ATTR_REQUEST = AttributeKey.newInstance("request");
|
||||||
public static final AttributeKey<List<HttpContent>> ATTR_CONTENT = AttributeKey.newInstance("content");
|
public static final AttributeKey<List<HttpContent>> ATTR_CONTENT = AttributeKey.newInstance("content");
|
||||||
|
private static final Logger LOGGER = Logger.getLogger("Handler");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx,Object msg){
|
public void channelRead(ChannelHandlerContext ctx,Object msg){
|
||||||
if(msg instanceof HttpRequest){
|
if(msg instanceof HttpRequest){
|
||||||
HttpRequest request = (HttpRequest) msg;
|
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set((HttpRequest) msg);
|
||||||
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set(request);
|
|
||||||
}
|
}
|
||||||
if(msg instanceof HttpContent){
|
if(msg instanceof HttpContent){
|
||||||
HttpContent content = (HttpContent) msg;
|
|
||||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).setIfAbsent(new ArrayList<>());
|
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).setIfAbsent(new ArrayList<>());
|
||||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).get().add(content);
|
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).get().add((HttpContent) msg);
|
||||||
|
|
||||||
if(msg instanceof LastHttpContent){
|
if(msg instanceof LastHttpContent){
|
||||||
this.handleResponse(ctx);
|
this.handleResponse(ctx);
|
||||||
|
@ -47,6 +48,8 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
||||||
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set(null);
|
ctx.channel().attr(HTTPHandler.ATTR_REQUEST).set(null);
|
||||||
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).set(null);
|
ctx.channel().attr(HTTPHandler.ATTR_CONTENT).set(null);
|
||||||
|
|
||||||
|
assert content!=null;
|
||||||
|
|
||||||
if(request.method().equals(HttpMethod.GET)){
|
if(request.method().equals(HttpMethod.GET)){
|
||||||
URI uri = URI.create(request.uri());
|
URI uri = URI.create(request.uri());
|
||||||
|
|
||||||
|
@ -118,7 +121,7 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
|
||||||
cause.printStackTrace(); //TODO
|
HTTPHandler.LOGGER.log(Level.WARNING,"Exception during HTTP handling",cause);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class Node{
|
||||||
private final InetAddress address;
|
private final InetAddress address;
|
||||||
private Double latitude;
|
private Double latitude;
|
||||||
private Double longitude;
|
private Double longitude;
|
||||||
private List<Service> services = new ArrayList<>();
|
private final List<Service> services = new ArrayList<>();
|
||||||
|
|
||||||
public Node(InetAddress address,Double latitude,Double longitude){
|
public Node(InetAddress address,Double latitude,Double longitude){
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
@ -25,10 +25,18 @@ public class Node{
|
||||||
return this.latitude;
|
return this.latitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLatitude(Double latitude) {
|
||||||
|
this.latitude = latitude;
|
||||||
|
}
|
||||||
|
|
||||||
public Double getLongitude() {
|
public Double getLongitude() {
|
||||||
return this.longitude;
|
return this.longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLongitude(Double longitude) {
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Service> getServices(){
|
public List<Service> getServices(){
|
||||||
return this.services;
|
return this.services;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
@ -22,7 +22,7 @@ public class BlockchainNodeFinderThread implements Runnable{
|
||||||
public void run() {
|
public void run() {
|
||||||
while(true){
|
while(true){
|
||||||
try{
|
try{
|
||||||
HttpURLConnection conn = (HttpURLConnection) new URL(System.getenv("BLOCKCHAIN_RPC_URL")).openConnection();
|
HttpURLConnection conn = (HttpURLConnection) new URI(System.getenv("BLOCKCHAIN_RPC_URL")).toURL().openConnection();
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.addRequestProperty("Authorization","Basic "+ Base64.getEncoder().encodeToString((System.getenv("BLOCKCHAIN_USERNAME")+":"+System.getenv("BLOCKCHAIN_PASSWORD")).getBytes()));
|
conn.addRequestProperty("Authorization","Basic "+ Base64.getEncoder().encodeToString((System.getenv("BLOCKCHAIN_USERNAME")+":"+System.getenv("BLOCKCHAIN_PASSWORD")).getBytes()));
|
||||||
conn.connect();
|
conn.connect();
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package com.lbry.globe.util;
|
package com.lbry.globe.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.*;
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class GeoIP{
|
public class GeoIP{
|
||||||
|
|
||||||
private static final Map<InetAddress,JSONObject> CACHE = new TreeMap<>(Comparator.comparing(InetAddress::getHostAddress));
|
private static final Map<InetAddress,JSONObject> CACHE = new TreeMap<>(Comparator.comparing(InetAddress::getHostAddress));
|
||||||
|
private static final Logger LOGGER = Logger.getLogger("GeoIP");
|
||||||
private static final String TOKEN = System.getenv("IPINFO_TOKEN");
|
private static final String TOKEN = System.getenv("IPINFO_TOKEN");
|
||||||
|
|
||||||
public static JSONObject getCachedGeoIPInformation(InetAddress ip){
|
public static JSONObject getCachedGeoIPInformation(InetAddress ip){
|
||||||
|
@ -23,14 +24,14 @@ public class GeoIP{
|
||||||
GeoIP.CACHE.put(ip,result);
|
GeoIP.CACHE.put(ip,result);
|
||||||
GeoIP.saveCache();
|
GeoIP.saveCache();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
GeoIP.LOGGER.log(Level.WARNING,"Failed getting cached GeoIP information.",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JSONObject getGeoIPInformation(InetAddress ip) throws IOException{
|
public static JSONObject getGeoIPInformation(InetAddress ip) throws IOException,URISyntaxException{
|
||||||
HttpURLConnection conn = (HttpURLConnection) new URL("https://ipinfo.io/"+ip.getHostAddress()+"?token="+GeoIP.TOKEN).openConnection();
|
HttpURLConnection conn = (HttpURLConnection) new URI("https://ipinfo.io/"+ip.getHostAddress()+"?token="+GeoIP.TOKEN).toURL().openConnection();
|
||||||
conn.connect();
|
conn.connect();
|
||||||
InputStream in = conn.getInputStream();
|
InputStream in = conn.getInputStream();
|
||||||
if(in==null){
|
if(in==null){
|
||||||
|
@ -68,7 +69,7 @@ public class GeoIP{
|
||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
GeoIP.LOGGER.log(Level.WARNING,"Failed loading GeoIP cache.",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ public class GeoIP{
|
||||||
fos.write(obj.toString().getBytes());
|
fos.write(obj.toString().getBytes());
|
||||||
fos.close();
|
fos.close();
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
GeoIP.LOGGER.log(Level.WARNING,"Failed saving GeoIP cache.",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue