diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..2a7e107 --- /dev/null +++ b/.env.dist @@ -0,0 +1,2 @@ +HOST_DATA_ABS_DIR="/abs/path/to/data/dir" +HOST_SCRIPT_ABS_DIR="/abs/path/to/script/dir" \ No newline at end of file diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..3c67aff --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,32 @@ +name: Docker Hub Push +on: + push: +# Publish semver tags as releases. + tags: [ '*' ] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + pull: true + cache-from: type=registry,ref=sondngyn/wgrib2:latest + cache-to: type=inline + tags: sondngyn/wgrib2:latest diff --git a/.gitignore b/.gitignore index cc25533..7942131 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.env -data/* \ No newline at end of file +.env +data +script \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index bb796d0..357a76f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,21 +13,20 @@ RUN apt-get update && apt-get install -y \ bzip2 \ tar \ amqp-tools \ - openssh-client - -RUN apt-get install -y \ + openssh-client \ gfortran \ - --no-install-recommends && rm -r /var/lib/apt/lists/* -RUN wget ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz -O /tmp/wgrib2.tgz -RUN mkdir -p /usr/local/grib2/ -RUN tar -xf /tmp/wgrib2.tgz -C /tmp/ -RUN rm -r /tmp/wgrib2.tgz -RUN mv /tmp/grib2/ /usr/local/grib2/ -RUN cd /usr/local/grib2/grib2 && make -RUN ln -s /usr/local/grib2/grib2/wgrib2/wgrib2 /usr/local/bin/wgrib2 -RUN apt-get -y autoremove build-essential + --no-install-recommends && rm -r /var/lib/apt/lists/* \ + && wget ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz -O /tmp/wgrib2.tgz \ + && mkdir -p /usr/local/grib2/ \ + && tar -xf /tmp/wgrib2.tgz -C /tmp/ \ + && rm -r /tmp/wgrib2.tgz \ + && mv /tmp/grib2/ /usr/local/grib2/ \ + && cd /usr/local/grib2/grib2 && make \ + && ln -s /usr/local/grib2/grib2/wgrib2/wgrib2 /usr/local/bin/wgrib2 \ + && apt-get -y autoremove build-essential VOLUME /srv/ VOLUME /opt/ WORKDIR /opt/ -CMD ["/bin/bash", "entrypoint.sh"] \ No newline at end of file +ENTRYPOINT [ "/bin/bash" ] +CMD ["/opt/entrypoint.sh"] diff --git a/README.md b/README.md index 63bf8da..b677480 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,23 @@ -WGRIB2 on Container (Debian Bulleyes) -### Note: I update the container based on: https://hub.docker.com/r/bearstudio/wgrib/ -## USAGE - -### Build: -`docker build -t sondngyn/wgrib2 .` -### On Linux: -`docker run -v /path/to/data:/srv/ -v /path/to/script:/opt/ sondngyn/wgrib2 /opt/script_file_name.sh` -### On Windows: -*Note: -Remember to put `#!bin/bash` in the beginning of your script file -Make sure your script file uses LF (Linux line break types) instead of CRLF (Windows). You can easily change it on VS Code -`docker run -v C:\absolute\path\to\data\dir\:/srv/ -v C:\absolute\path\to\script\dir\:/opt/ sondngyn/wgrib2 /opt/script_file_name.sh` -(watch out for back-slashes and forward-slashes) -### Example on Windows (powershell): -`docker run -v C:\Users\myuser\mydata\:/srv/ -v C:\Users\myuser\myscript\:/opt/ sondngyn/wgrib2 /opt/myscript.sh` - -## DEV: -0. Clean up: `docker container rm wgrib2 -f` -1. Build image: `docker build -t wgrib2 .` -2. Spin up container: `docker run --rm --name wgrib2 -d -it wgrib2` -3. Exec: `docker exec -it wgrib2 bash` +WGRIB2 on Container (Debian Bulleyes) +### Note: I update the container based on: https://hub.docker.com/r/bearstudio/wgrib/ +## USAGE + +### Usage: + +#### Docker-Compose CLI +Create `.env` file from `.env.dist` and change the env values to the dirs location on your computer (for windows, use `/c/abs/path/`) +`docker-compose build wgrib2` +`docker-compose up wgrib2` (change `command` in docker-compose file to your script filename before running `up`) + +#### Docker CLI +`docker build -t wgrib2 .` +##### On Linux: +`docker run -v /path/to/data:/srv/ -v /path/to/script:/opt/ sondngyn/wgrib2 /opt/script_file_name.sh` +##### On Windows: +*Note: +Remember to put `#!bin/bash` in the beginning of your script file +Make sure your script file uses LF (Linux line break types) instead of CRLF (Windows) +`docker run -v C:\\absolute\\path\\:/srv/ -v C:\\absolute\\path\\:/opt/ wgrib2 script_file_name.sh` +(watch out for back-slashes and forward-slashes) +### Example on Windows (powershell): +`docker run -v C:\\Users\\myuser\\mydata\\:/srv/ -v C:\\Users\\myuser\\myscript\\:/opt/ wgrib2 myscript.sh` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..453eec3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: "3.8" + +services: + wgrib2: + image: wgrib2 + container_name: wgrib2 + restart: unless-stopped + env_file: ./.env + entrypoint: /bin/bash + # Change this command to your bash script filename + command: "/srv/script.sh" + build: + context: ./ + volumes: + - type: bind + source: ${HOST_DATA_ABS_DIR} + target: /opt/ + - type: bind + source: ${HOST_SCRIPT_ABS_DIR} + target: /srv/ +