Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dockerized support #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
target
scratch
*.iml
compiled/*
m2_cache/*
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ Installation

```
git clone <this project>
mvn package
docker-compose run grib2json ./build
```

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
-----

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
Expand Down
8 changes: 8 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -ux
mvn package

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
21 changes: 21 additions & 0 deletions compiled/grib2json/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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.
74 changes: 74 additions & 0 deletions compiled/grib2json/README.md
Original file line number Diff line number Diff line change
@@ -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 <this project>
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,
...
]
}
]
```
5 changes: 5 additions & 0 deletions compiled/grib2json/bin/grib2json
Original file line number Diff line number Diff line change
@@ -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 $@
4 changes: 4 additions & 0 deletions compiled/grib2json/bin/grib2json.cmd
Original file line number Diff line number Diff line change
@@ -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% %*
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '2'
services:
grib2json:
container_name: grib2json
build:
context: ./docker
dockerfile: Dockerfile
volumes:
- ../:/usr/src/app
- ../m2_cache:/home/temp/.m2
working_dir: /usr/src/app
entrypoint: ./docker-entrypoint.sh
10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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"
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
8 changes: 8 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/sh

set -ux
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
exec gosu temp $@
3 changes: 3 additions & 0 deletions grib2json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker-compose run grib2json grib2json $@