From 87285ff9bac41f337334537cec009ebdcba26c18 Mon Sep 17 00:00:00 2001 From: Werner Raath Date: Wed, 5 Oct 2016 15:37:04 +0200 Subject: [PATCH 1/2] Added Dockerized support --- .gitignore | 3 +++ Dockerfile | 10 ++++++++++ README.md | 4 +++- build | 10 ++++++++++ docker-compose.yml | 12 ++++++++++++ docker-entrypoint.sh | 8 ++++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100755 build create mode 100644 docker-compose.yml create mode 100755 docker-entrypoint.sh diff --git a/.gitignore b/.gitignore index f4c4a25..af99e3d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ node_modules target scratch *.iml +bin/* +lib/* +m2_cache/* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..97c6a98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM maven:3-jdk-8 + +ARG GOSU_VERSION=1.9 +ARG GOSU_DOWNLOAD_URL="https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" +RUN curl -o gosu -fsSL "$GOSU_DOWNLOAD_URL" > gosu-amd64 \ + && mv gosu /usr/bin/gosu \ + && chmod +x /usr/bin/gosu + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app \ No newline at end of file diff --git a/README.md b/README.md index afed7db..c0b95b2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ Installation ``` git clone -mvn package +docker-compose run grib2json ./build + +export PATH=$PATH:/path/to/this/dir/bin ``` This creates a .tar.gz in the target directory. Unzip and untar the package in a location of choice. diff --git a/build b/build new file mode 100755 index 0000000..1414a7d --- /dev/null +++ b/build @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -ux +mvn package +tar -xvzf target/grib2json-0.8.0-SNAPSHOT.tar.gz +cp grib2json-0.8.0-SNAPSHOT/bin/* /usr/src/app/bin + +cp grib2json-0.8.0-SNAPSHOT/lib/grib2json-0.8.0-SNAPSHOT.jar /usr/src/app/lib/ +rm -Rf /usr/src/app/grib2json-0.8.0-SNAPSHOT +rm -Rf /usr/src/app/target \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a442b29 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '2' +services: + grib2json: + container_name: grib2json + build: + context: . + dockerfile: Dockerfile + volumes: + - .:/usr/src/app + - ./m2_cache:/home/temp/.m2 + working_dir: /usr/src/app + entrypoint: ./docker-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..96ca0e6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,8 @@ +#! /bin/sh + +set -ux +export PATH=$PATH:/usr/src/app/bin + +TEMP_UID="${TEMP_UID:-1000}" +useradd -s /bin/false --no-create-home -u ${TEMP_UID} temp +exec gosu temp $@ \ No newline at end of file From 13f96c9f53876bc252459f6203a9ff4f581be700 Mon Sep 17 00:00:00 2001 From: Werner Raath Date: Thu, 6 Oct 2016 11:06:38 +0200 Subject: [PATCH 2/2] Improved project structure and improved usage efficiency. --- .gitignore | 3 +- README.md | 14 +++- build | 8 +- compiled/grib2json/LICENSE.md | 21 ++++++ compiled/grib2json/README.md | 74 +++++++++++++++++++ compiled/grib2json/bin/grib2json | 5 ++ compiled/grib2json/bin/grib2json.cmd | 4 + docker-compose.yml | 6 +- Dockerfile => docker/Dockerfile | 2 +- .../docker-entrypoint.sh | 2 +- grib2json | 3 + 11 files changed, 127 insertions(+), 15 deletions(-) create mode 100644 compiled/grib2json/LICENSE.md create mode 100644 compiled/grib2json/README.md create mode 100755 compiled/grib2json/bin/grib2json create mode 100755 compiled/grib2json/bin/grib2json.cmd rename Dockerfile => docker/Dockerfile (93%) rename docker-entrypoint.sh => docker/docker-entrypoint.sh (70%) create mode 100755 grib2json diff --git a/.gitignore b/.gitignore index af99e3d..0c5ed2a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ node_modules target scratch *.iml -bin/* -lib/* +compiled/* m2_cache/* diff --git a/README.md b/README.md index c0b95b2..9db18ea 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,17 @@ Installation ``` git clone docker-compose run grib2json ./build - -export PATH=$PATH:/path/to/this/dir/bin ``` -This creates a .tar.gz in the target directory. Unzip and untar the package in a location of choice. +*You have two choices*: + - Use docker to run grib2json (No local java dependencies required) + ``` + export PATH=$PATH:/path/to/this/dir/ + ``` + - Or use provided executable (Local java dependencies required) + ``` + export PATH=$PATH:/path/to/this/dir/compiled/grib2json/bin + ``` Usage ----- @@ -24,6 +30,8 @@ Usage The `grib2json` launch script is located in the `bin` directory and requires the `JAVA_HOME` environment variable to be defined. +**Note that using the docker to run grib2json requires the output to be saved in `/usr/src/app/output` ** + ``` > grib2json --help Usage: grib2json [options] FILE diff --git a/build b/build index 1414a7d..c8adf4b 100755 --- a/build +++ b/build @@ -2,9 +2,7 @@ set -ux mvn package -tar -xvzf target/grib2json-0.8.0-SNAPSHOT.tar.gz -cp grib2json-0.8.0-SNAPSHOT/bin/* /usr/src/app/bin -cp grib2json-0.8.0-SNAPSHOT/lib/grib2json-0.8.0-SNAPSHOT.jar /usr/src/app/lib/ -rm -Rf /usr/src/app/grib2json-0.8.0-SNAPSHOT -rm -Rf /usr/src/app/target \ No newline at end of file +tar -xvzf /usr/src/app/target/grib2json-0.8.0-SNAPSHOT.tar.gz -C /usr/src/app/compiled/ +rm -Rf /usr/src/app/target +mv /usr/src/app/compiled/grib2json-0.8.0-SNAPSHOT /usr/src/app/compiled/grib2json \ No newline at end of file diff --git a/compiled/grib2json/LICENSE.md b/compiled/grib2json/LICENSE.md new file mode 100644 index 0000000..52f404e --- /dev/null +++ b/compiled/grib2json/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 Cameron Beccario + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/compiled/grib2json/README.md b/compiled/grib2json/README.md new file mode 100644 index 0000000..c0b95b2 --- /dev/null +++ b/compiled/grib2json/README.md @@ -0,0 +1,74 @@ +grib2json +========= + +A command line utility that decodes [GRIB2](http://en.wikipedia.org/wiki/GRIB) files as JSON. + +This utility uses the netCDF-Java GRIB decoder, part of the [THREDDS](https://github.com/Unidata/thredds) project +by University Corporation for Atmospheric Research/Unidata. + +Installation +------------ + +``` +git clone +docker-compose run grib2json ./build + +export PATH=$PATH:/path/to/this/dir/bin +``` + +This creates a .tar.gz in the target directory. Unzip and untar the package in a location of choice. + +Usage +----- + +The `grib2json` launch script is located in the `bin` directory and requires the `JAVA_HOME` environment +variable to be defined. + +``` +> grib2json --help +Usage: grib2json [options] FILE + [--compact -c] : enable compact Json formatting + [--data -d] : print GRIB record data + [--filter.category --fc value] : select records with this numeric category + [--filter.parameter --fp value] : select records with this numeric parameter + [--filter.surface --fs value] : select records with this numeric surface type + [--filter.value --fv value] : select records with this numeric surface value + [--help -h] : display this help + [--names -n] : print names of numeric codes + [--output -o value] : write output to the specified file (default is stdout) + [--verbose -v] : enable logging to stdout +``` + +For example, the following command outputs to stdout the records for parameter 2 (U-component_of_wind), with +surface type 103 (Specified height level above ground), and surface value 10.0 meters from the GRIB2 file +_gfs.t18z.pgrbf00.2p5deg.grib2_. Notice the optional inclusion of human-readable _xyzName_ keys and the data array: + +``` +> grib2json --names --data --fp 2 --fs 103 --fv 10.0 gfs.t18z.pgrbf00.2p5deg.grib2 + +[ + { + "header":{ + "discipline":0, + "disciplineName":"Meteorological products", + "gribEdition":2, + "gribLength":27759, + "center":7, + "centerName":"US National Weather Service - NCEP(WMC)", + "parameterNumber":2, + "parameterNumberName":"U-component_of_wind", + "parameterUnit":"m.s-1", + "surface1Type":103, + "surface1TypeName":"Specified height level above ground", + "surface1Value":10.0, + ... + }, + "data":[ + -2.12, + -2.27, + -2.41, + ... + ] + } +] +``` diff --git a/compiled/grib2json/bin/grib2json b/compiled/grib2json/bin/grib2json new file mode 100755 index 0000000..c458057 --- /dev/null +++ b/compiled/grib2json/bin/grib2json @@ -0,0 +1,5 @@ +#!/bin/sh +#set -x +LIB_DIR=$(dirname "$0")/../lib +LAUNCH_JAR=$LIB_DIR/grib2json-*.jar +$JAVA_HOME/bin/java -Xmx512M -jar $LAUNCH_JAR $@ diff --git a/compiled/grib2json/bin/grib2json.cmd b/compiled/grib2json/bin/grib2json.cmd new file mode 100755 index 0000000..788abb5 --- /dev/null +++ b/compiled/grib2json/bin/grib2json.cmd @@ -0,0 +1,4 @@ +@echo off +set LIB_DIR="%~dp0..\lib" +for /f "delims=X" %%i in ('dir /b %LIB_DIR%\grib2json-*.jar') do set LAUNCH_JAR=%LIB_DIR%\%%i +"%JAVA_HOME%\bin\java.exe" -Xmx512M -jar %LAUNCH_JAR% %* diff --git a/docker-compose.yml b/docker-compose.yml index a442b29..f802745 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,10 @@ services: grib2json: container_name: grib2json build: - context: . + context: ./docker dockerfile: Dockerfile volumes: - - .:/usr/src/app - - ./m2_cache:/home/temp/.m2 + - ../:/usr/src/app + - ../m2_cache:/home/temp/.m2 working_dir: /usr/src/app entrypoint: ./docker-entrypoint.sh diff --git a/Dockerfile b/docker/Dockerfile similarity index 93% rename from Dockerfile rename to docker/Dockerfile index 97c6a98..9bca6cc 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM maven:3-jdk-8 +FROM maven:3-jdk-7 ARG GOSU_VERSION=1.9 ARG GOSU_DOWNLOAD_URL="https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" diff --git a/docker-entrypoint.sh b/docker/docker-entrypoint.sh similarity index 70% rename from docker-entrypoint.sh rename to docker/docker-entrypoint.sh index 96ca0e6..7b54404 100755 --- a/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,7 +1,7 @@ #! /bin/sh set -ux -export PATH=$PATH:/usr/src/app/bin +export PATH=$PATH:/usr/src/app/compiled/grib2json/bin TEMP_UID="${TEMP_UID:-1000}" useradd -s /bin/false --no-create-home -u ${TEMP_UID} temp diff --git a/grib2json b/grib2json new file mode 100755 index 0000000..19f809a --- /dev/null +++ b/grib2json @@ -0,0 +1,3 @@ +#!/bin/sh + +docker-compose run grib2json grib2json $@