From 7be6a076a02bce4e5ff007fb552a79b10690aa5f Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Sun, 20 Oct 2019 20:36:51 -0500
Subject: [PATCH] Add basic buildbucket environment

---
 buildbucket/Dockerfile                   | 16 +++++++
 buildbucket/buildbucket_environment.yaml | 19 ++++++++
 buildbucket/package.sh                   | 57 ++++++++++++++++++++++++
 gridded_glm/PACKAGE_README.md            |  3 ++
 gridded_glm/bin/run.sh                   |  4 ++
 5 files changed, 99 insertions(+)
 create mode 100644 buildbucket/Dockerfile
 create mode 100644 buildbucket/buildbucket_environment.yaml
 create mode 100644 buildbucket/package.sh
 create mode 100644 gridded_glm/PACKAGE_README.md
 create mode 100644 gridded_glm/bin/run.sh

diff --git a/buildbucket/Dockerfile b/buildbucket/Dockerfile
new file mode 100644
index 0000000..a636f48
--- /dev/null
+++ b/buildbucket/Dockerfile
@@ -0,0 +1,16 @@
+FROM centos:7
+
+WORKDIR /work
+
+COPY buildbucket_environment.yaml .
+COPY package.sh .
+
+# Download miniconda
+RUN curl -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
+# Install miniconda
+RUN bash miniconda.sh -b -p $HOME/miniconda
+
+ENV PATH $HOME/miniconda/bin:$PATH
+RUN conda env create -y -n build -f buildbucket_environment.yaml
+RUN conda activate build
+
diff --git a/buildbucket/buildbucket_environment.yaml b/buildbucket/buildbucket_environment.yaml
new file mode 100644
index 0000000..35f6874
--- /dev/null
+++ b/buildbucket/buildbucket_environment.yaml
@@ -0,0 +1,19 @@
+name: gridded_glm_buildbucket
+channels:
+  - conda-forge
+dependencies:
+  - conda-pack
+  - curl
+  - dask
+  - distributed
+  - netcdf4
+  - pip
+  - pyclipper
+  - pyproj
+  - pytables
+  - python=3.7
+  - pyyaml
+  - scipy
+  - setuptools
+  - xarray
+  - zarr
\ No newline at end of file
diff --git a/buildbucket/package.sh b/buildbucket/package.sh
new file mode 100644
index 0000000..74104c1
--- /dev/null
+++ b/buildbucket/package.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+# purpose: Create package and place it in /dock
+# requires: /gridded_glm to be mounted with package contents (gridded_glm in repository)
+set -ex
+
+USAGE="Usage: package.sh vX.Y.Z [lmatools_ref glmtools_ref]"
+if [ $# -eq 1 ]; then
+    version=$1
+    lmatools_ref=minvaluegrids
+    glmtools_ref=ugf-newgrid
+else if [ $# -eq 3 ]; then
+    version=$1
+    lmatools_ref=minvaluegrids
+    glmtools_ref=ugf-newgrid
+else
+    echo $USAGE
+    exit 1
+fi
+
+# conda activate build
+
+# Debug Info
+which python
+conda info -a
+conda list --export
+echo "Version specified: ${version}"
+echo "lmatools reference: ${lmatools_ref}"
+echo "glmtools reference: ${glmtools_ref}"
+
+# Install glmtools and related packages
+# All dependencies should have been built with the buildbucket
+# Careful: Could result in missing dependencies but we want reproducibility
+pip install --no-deps git+https://github.com/deeplycloudy/lmatools.git@${lmatools_ref}
+pip install --no-deps git+https://github.com/deeplycloudy/stormdrain.git
+pip install --no-deps git+https://github.com/deeplycloudy/glmtools.git@${glmtools_ref}
+
+# Build a tarball version of the current conda environment
+conda_tb=conda_lmatools-${lmatools}_glmtools-${glmtools_ref}.tar.gz
+conda pack -n build -o ${conda_tb}
+
+# Build up our package directory
+pkg_name=cspp_geo_gridded_glm-${version}
+mkdir -p ${pkg_name}
+cd ${pkg_name}
+mkdir -p bin opt/conda
+# Copy package scripts/data to package directory
+cp /gridded_glm/PACKAGE_README.md ./README.md
+cp /gridded_glm/bin/* ./bin/
+# Untar the tarball so we can put things where we want
+tar -xz -C ./opt/conda -f ../${conda_tb}
+# Go back to original work directory
+cd ..
+
+# Create tarball of package directory
+tar -czf ${pkg_name}.tar.gz ${pkg_name}
+mv ${pkg_name}.tar.gz /dock/
+
diff --git a/gridded_glm/PACKAGE_README.md b/gridded_glm/PACKAGE_README.md
new file mode 100644
index 0000000..c04e353
--- /dev/null
+++ b/gridded_glm/PACKAGE_README.md
@@ -0,0 +1,3 @@
+# CSPP Geo Gridded GLM
+
+TODO
\ No newline at end of file
diff --git a/gridded_glm/bin/run.sh b/gridded_glm/bin/run.sh
new file mode 100644
index 0000000..5850002
--- /dev/null
+++ b/gridded_glm/bin/run.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+echo "TODO"
+exit 1
\ No newline at end of file
-- 
GitLab