Skip to content

Instantly share code, notes, and snippets.

@maybe-hello-world
Created March 21, 2023 04:23
Show Gist options
  • Save maybe-hello-world/dba3b6825a3dd6f558e8c464e7ad210a to your computer and use it in GitHub Desktop.
Save maybe-hello-world/dba3b6825a3dd6f558e8c464e7ad210a to your computer and use it in GitHub Desktop.
CICFlowMeter Docker container
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'
group = 'cic.unb.ca'
version = '4.0'
description = """CICFlowMeterV4"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url "https://clojars.org/repo" }
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.25'
compile group: 'org.jnetpcap', name: 'jnetpcap', version:'1.4.1'
compile group: 'junit', name: 'junit', version:'4.12'
compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.6'
compile group: 'org.apache.commons', name: 'commons-math3', version:'3.5'
compile group: 'commons-io', name: 'commons-io', version:'2.5'
compile group: 'nz.ac.waikato.cms.weka', name: 'weka-stable', version:'3.6.14'
// https://mvnrepository.com/artifact/org.jfree/jfreechart
compile group: 'org.jfree', name: 'jfreechart', version: '1.5.0'
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '23.6-jre'
// https://mvnrepository.com/artifact/org.apache.tika/tika-core
compile group: 'org.apache.tika', name: 'tika-core', version: '1.17'
}
sourceSets {
main {
java {
srcDir 'src'
exclude '**/CICFlowMeter.java'
}
}
}
task zipSrc(type: Zip){
baseName "${applicationName}-Source"
destinationDir = file('build/')
from('.'){
include '**/'
exclude '.gradle/','build/','bin/','logs/','*.iml','*.ipr','*.iws','.idea/','out/','data/'
into "${applicationName}V${version}-Src"
}
}
import org.apache.tools.ant.DirectoryScanner
task zipPro(type: Zip){
doFirst {
DirectoryScanner.defaultExcludes.each { DirectoryScanner.removeDefaultExclude it }
//DirectoryScanner.addDefaultExclude 'something has to be in here or everything gets excluded'
}
doLast {
DirectoryScanner.resetDefaultExcludes()
}
baseName "${applicationName}-Full"
destinationDir = file('build/')
from('.'){
include '**/'
exclude '.gradle/','build/','bin/','logs/','*.iml','*.ipr','*.iws','.idea/','out/','data/',".git/"
into "${applicationName}V${version}"
}
}
task fatJar(type: Jar) {
println 'type Jar'
manifest {
attributes 'Premain-Class': 'swing.common.ObjectSizeFetcher'
attributes 'Can-Retransform-Classes': true
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'cic.cs.unb.ca.ifm.App'
}
/*baseName = "NetWorkTraffic" + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
into(new File('build/jar/'))
with jar*/
}
task fatJarCMD(type: Jar) {
manifest {
attributes 'Main-Class': "cic.cs.unb.ca.ifm.Cmd"
applicationDefaultJvmArgs = ['-Djava.library.path=/CICFlowMeter/jnetpcap/linux/jnetpcap-1.4.r1425']
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
task execute(type: JavaExec) {
println 'type JavaExec'
main = "cic.cs.unb.ca.ifm.App" //main class
classpath = sourceSets.main.runtimeClasspath
String osName = System.getProperty('os.name').toLowerCase()
if(osName.contains('windows')){
jvmArgs '-Djava.library.path=jnetpcap/win/jnetpcap-1.4.r1425'
}else{
jvmArgs '-Djava.library.path=jnetpcap/linux/jnetpcap-1.4.r1425'
}
}
task exeCMD(type: JavaExec){
main = "cic.cs.unb.ca.ifm.Cmd" //main class
classpath = sourceSets.main.runtimeClasspath
String osName = System.getProperty('os.name').toLowerCase()
jvmArgs '-Djava.library.path=jnetpcap/linux/jnetpcap-1.4.r1425'
if(project.hasProperty('customargs')){
args(myargs.split(','))
}
}
task cmdScript(type: CreateStartScripts) {
mainClassName = "cic.cs.unb.ca.ifm.Cmd"
applicationName = "cfm"
outputDir = new File(project.buildDir, 'scripts')
classpath = jar.outputs.files + project.configurations.runtime
defaultJvmOpts = ["-Djava.library.path=../lib/native"]
}
applicationDistribution.into("bin") {
from(cmdScript)
fileMode = 0755
}
// The Application Plugin
mainClassName = "cic.cs.unb.ca.ifm.App"
applicationName = "CICFlowMeter"
applicationDefaultJvmArgs = ["-Djava.library.path=../lib/native"]
applicationDistribution.from("jnetpcap/linux/jnetpcap-1.4.r1425") {
include "*.so"
into('lib/native')
}
applicationDistribution.from("jnetpcap/win/jnetpcap-1.4.r1425") {
include "*.dll"
into('lib/native')
}
applicationDistribution.from('LICENSE.txt'){
into('')
}
applicationDistribution.from('ReadMe.txt'){
into('')
rename("ReadMe.txt","README.md")
}
FROM maven:3.8.1-openjdk-8
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y git parallel libpcap-dev gradle && rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/ahlashkari/CICFlowMeter.git
WORKDIR /CICFlowMeter/jnetpcap/linux/jnetpcap-1.4.r1425
RUN mvn install:install-file -Dfile=jnetpcap.jar -DgroupId=org.jnetpcap -DartifactId=jnetpcap -Dversion=1.4.1 -Dpackaging=jar
WORKDIR /CICFlowMeter
COPY ./build.gradle ./build.gradle
RUN gradle fatJarCMD
ENV LD_LIBRARY_PATH /CICFlowMeter/jnetpcap/linux/jnetpcap-1.4.r1425/
ENTRYPOINT ["java", "-Djava.library.path=/CICFlowMeter/jnetpcap/linux/jnetpcap-1.4.r1425/", "-jar", "build/libs/CICFlowMeter-4.0.jar"]
# usage:
# docker run -v filename.pcap:/tmp/filename.pcap -v /output/dir:/tmp/output/ --rm IMAGENAME /tmp/filename.pcap /tmp/output/
# you can extract the jar file from the container
# but make sure you have jnetpcap-lib installed
# docker run --rm --entrypoint cat cicimagename /CICFlowMeter/build/libs/CICFlowMeter-4.0.jar > CICFlowMeter.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment