Skip to content

Commit 401deea

Browse files
committed
Convert to a proper distribution with Dockerfile
1 parent 3eb4f48 commit 401deea

30 files changed

+120
-55
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git/
2+
build/
3+
src/test/
4+
out/
5+
.gradle/
6+
.idea/

Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
13+
FROM openjdk:8-alpine AS builder
14+
15+
RUN mkdir /code
16+
WORKDIR /code
17+
18+
ENV GRADLE_OPTS -Dorg.gradle.daemon=false
19+
20+
COPY ./gradle /code/gradle
21+
COPY ./gradlew /code/
22+
RUN ./gradlew --version
23+
24+
COPY ./build.gradle ./gradle.properties ./settings.gradle /code/
25+
26+
RUN ./gradlew downloadDependencies
27+
28+
COPY ./src /code/src
29+
COPY LICENSE README.md /code/
30+
31+
RUN ./gradlew distTar && \
32+
tar xzf build/distributions/*.tar.gz && \
33+
rm build/distributions/*.tar.gz
34+
35+
FROM openjdk:8-jre-alpine
36+
37+
MAINTAINER Joris Borgdorff <[email protected]>
38+
39+
LABEL description="RADAR-base HDFS data restructuring"
40+
41+
COPY --from=builder /code/radar-hdfs-restructure-*/bin /usr/bin
42+
COPY --from=builder /code/radar-hdfs-restructure-*/share /usr/share
43+
COPY --from=builder /code/radar-hdfs-restructure-*/lib /usr/lib
44+
45+
ENTRYPOINT ["radar-hdfs-restructure"]

build.gradle

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ apply plugin: 'application'
33

44
group 'org.radarcns.restructurehdfs'
55
version '0.4.0-SNAPSHOT'
6-
mainClassName = 'org.radarcns.RestructureAvroRecords'
7-
8-
run {
9-
args = ['webhdfs://localhost:50070', '/topicAndroidNew/android_phone_sensor_acceleration', "${projectDir}/data"]
10-
}
6+
mainClassName = 'org.radarcns.hdfs.RestructureAvroRecords'
117

128
sourceCompatibility = '1.8'
139
targetCompatibility = '1.8'
@@ -37,26 +33,32 @@ dependencies {
3733
testImplementation group: 'junit', name: 'junit', version: '4.12'
3834
}
3935

40-
//create a single Jar with all dependencies
41-
task fatJar(type: Jar) {
36+
jar {
4237
manifest {
43-
attributes 'Implementation-Title': 'radar-restructure-hdfs',
44-
'Implementation-Version': version,
45-
'Main-Class': mainClassName
38+
attributes 'Implementation-Title': 'RADAR-base HDFS data restructuring',
39+
'Implementation-Version': version
4640
}
47-
classifier = 'all'
48-
from {
49-
configurations.runtimeClasspath.collect {
50-
it.isDirectory() ? it : zipTree(it)
41+
}
42+
43+
distributions {
44+
main {
45+
contents {
46+
into ("share/${project.name}") {
47+
from 'README.md', 'LICENSE'
48+
}
5149
}
52-
} {
53-
exclude 'META-INF/*'
5450
}
55-
with jar
5651
}
5752

58-
artifacts {
59-
archives fatJar
53+
tasks.withType(Tar){
54+
compression = Compression.GZIP
55+
extension = 'tar.gz'
56+
}
57+
58+
task downloadDependencies {
59+
description "Pre-downloads dependencies"
60+
configurations.compileClasspath.files
61+
configurations.runtimeClasspath.files
6062
}
6163

6264
wrapper {

gradle.properties

Whitespace-only changes.

settings.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
rootProject.name = 'restructurehdfs'
2-
1+
rootProject.name = 'radar-hdfs-restructure'

src/main/java/org/radarcns/Frequency.java renamed to src/main/java/org/radarcns/hdfs/Frequency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.radarcns;
17+
package org.radarcns.hdfs;
1818

1919
import org.apache.commons.collections.MapIterator;
2020
import org.apache.commons.collections.keyvalue.MultiKey;

src/main/java/org/radarcns/OffsetRange.java renamed to src/main/java/org/radarcns/hdfs/OffsetRange.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.radarcns;
17+
package org.radarcns.hdfs;
1818

1919
import com.fasterxml.jackson.annotation.JsonCreator;
2020
import com.fasterxml.jackson.annotation.JsonProperty;

src/main/java/org/radarcns/OffsetRangeFile.java renamed to src/main/java/org/radarcns/hdfs/OffsetRangeFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.radarcns;
17+
package org.radarcns.hdfs;
1818

1919
import com.fasterxml.jackson.databind.MappingIterator;
2020
import com.fasterxml.jackson.databind.ObjectReader;

src/main/java/org/radarcns/OffsetRangeSet.java renamed to src/main/java/org/radarcns/hdfs/OffsetRangeSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.radarcns;
17+
package org.radarcns.hdfs;
1818

1919
import javax.annotation.Nonnull;
2020
import java.util.Iterator;

src/main/java/org/radarcns/RestructureAvroRecords.java renamed to src/main/java/org/radarcns/hdfs/RestructureAvroRecords.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.radarcns;
17+
package org.radarcns.hdfs;
1818

1919
import com.beust.jcommander.JCommander;
20+
import com.beust.jcommander.ParameterException;
2021
import com.fasterxml.jackson.databind.JsonMappingException;
2122
import org.apache.avro.Schema.Field;
2223
import org.apache.avro.file.DataFileReader;
@@ -28,12 +29,12 @@
2829
import org.apache.hadoop.fs.LocatedFileStatus;
2930
import org.apache.hadoop.fs.Path;
3031
import org.apache.hadoop.fs.RemoteIterator;
31-
import org.radarcns.data.CsvAvroConverter;
32-
import org.radarcns.data.FileCacheStore;
33-
import org.radarcns.data.JsonAvroConverter;
34-
import org.radarcns.data.RecordConverterFactory;
35-
import org.radarcns.util.ProgressBar;
36-
import org.radarcns.util.commandline.CommandLineArgs;
32+
import org.radarcns.hdfs.data.CsvAvroConverter;
33+
import org.radarcns.hdfs.data.FileCacheStore;
34+
import org.radarcns.hdfs.data.JsonAvroConverter;
35+
import org.radarcns.hdfs.data.RecordConverterFactory;
36+
import org.radarcns.hdfs.util.ProgressBar;
37+
import org.radarcns.hdfs.util.commandline.CommandLineArgs;
3738
import org.slf4j.Logger;
3839
import org.slf4j.LoggerFactory;
3940

@@ -83,10 +84,16 @@ public static void main(String [] args) {
8384
final CommandLineArgs commandLineArgs = new CommandLineArgs();
8485
final JCommander parser = JCommander.newBuilder().addObject(commandLineArgs).build();
8586

86-
parser.setProgramName("hadoop jar restructurehdfs-all-0.3.3.jar");
87-
parser.parse(args);
87+
parser.setProgramName("radar-hdfs-restructure");
88+
try {
89+
parser.parse(args);
90+
} catch (ParameterException ex) {
91+
logger.error(ex.getMessage());
92+
parser.usage();
93+
System.exit(1);
94+
}
8895

89-
if(commandLineArgs.help) {
96+
if (commandLineArgs.help) {
9097
parser.usage();
9198
System.exit(0);
9299
}

0 commit comments

Comments
 (0)