Skip to content

Commit

Permalink
Add samples/Dockerfile and workflow (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinrsmith authored Aug 10, 2021
1 parent 2b053e0 commit ce94ee0
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 8 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build CI

on:
push:
branches: [ 'main' ]
tags: [ 'v*' ]
pull_request:
branches: [ 'main' ]

jobs:
examples:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Docker meta
id: docker_meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ github.repository_owner }}/examples
labels: |
org.opencontainers.image.vendor=Deephaven Data Labs
org.opencontainers.image.title=Deephaven Examples
org.opencontainers.image.description=Deephaven Examples
org.opencontainers.image.licenses=Deephaven Community License Agreement 1.0
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to ghcr.io
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker build
uses: docker/[email protected]
with:
context: ./samples/
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This repository contains open source data sets. They are intended to be used as part of an introduction to the Deephaven Community Core Engine. For more information, check out [Deephaven Community Core](https://github.com/deephaven/deephaven-core).

![Build CI](https://github.com/deephaven/examples/actions/workflows/build-ci.yml/badge.svg?branch=main)

## Table of Contents

The following folders can be found in this repository:
Expand All @@ -22,16 +24,33 @@ Each folder in this repository has the following structure within:

## Installation Instructions

1. Follow the README instructions on [Deephaven Community Core](https://github.com/deephaven/deephaven-core) for installing the code studio and all required dependencies.
2. From the root of your `deephaven-core` clone, run:
1. `docker build -t deephaven/examples samples`
2. `docker run --rm -v "$(pwd)/docker/core/data:/data" deephaven/examples download`
The examples script image can be pulled via:

```
docker pull ghcr.io/deephaven/examples
```

The `docker build` command builds a Docker container containing a script that helps manage the examples.
That script will automate the management of the example files. It allows you to download and update the example files without directly working with the git project hosting the examples. This `docker build` command is only needed once; after it runs, the container is available to use on your host.
To download the examples, from the root of your `deephaven-core` clone, run:

The `docker run` command downloads the example data by running the new examples management container. The `-v "$(pwd)/docker/core/data:/data"` argument mounts your local `deephaven-core/docker/core/data` path as `/data` in the container. The example data is stored to `/data/examples` inside the container, which is `deephaven-core/docker/core/data/examples` on the local filesystem.
```
docker run --rm -v "$(pwd)/docker/core/data:/data" ghcr.io/deephaven/examples download
```

The `docker run` command downloads the example data by running the examples management container. The `-v "$(pwd)/docker/core/data:/data"` argument mounts your local `$(pwd)/docker/core/data` path as `/data` in the container. The example data is stored to `/data/examples` inside the container, which is `$(pwd)/docker/core/data/examples` on the local filesystem.

You can run `docker run` again to manage the example data -- for example, to download a new version. To see what options are available, run:

`docker run --rm -v "$(pwd)/docker/core/data:/data" deephaven/examples`
```
docker run --rm -v "$(pwd)/docker/core/data:/data" ghcr.io/deephaven/examples
```

## Build Instructions

From the root of `examples`, run:

```
docker build -t ghcr.io/deephaven/examples docker
```

The `docker build` command builds a Docker container containing a script that helps manage the examples.
That script will automate the management of the example files. It allows you to download and update the example files without directly working with the git project hosting the examples. This `docker build` command is only needed once; after it runs, the container is available to use on your host.
7 changes: 7 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3
RUN apk add --no-cache git git-lfs

VOLUME [ "/data" ]
ENTRYPOINT [ "/examples_script.sh" ]

COPY examples_script.sh /
116 changes: 116 additions & 0 deletions docker/examples_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env sh

# set -xv

# show usage and quit
function usage()
{
printf "usage: %s <command>\n" $(basename $0) >&2
printf "\n" >&2
printf " commands are:\n"
printf " download [<version>] - downloads and mounts all example data\n" >&2
printf " gets latest version, unless <version> supplied\n" >&2
printf " remove - removes all example data\n" >&2
printf " version - shows current the version\n" >&2
printf " versions - list available versions\n" >&2
exit 2
}


# complain and quit
function fail_out()
{
printf "Failed! %s\n" "$@" >&2
exit 2
}


# check that we have the expected enlistment directory; download it if not
function ensure_enlistment()
{
if [ ! -d $target_path/.git ]; then
printf "no examples collection at %s; dowloading ..." $target_path >&2
do_download
fi
}


# clone the git repo, don't report progress but DO report errors
function do_download()
{
if [ -d $target_path/.git ]; then
printf "examples collection already exists at %s\n" $target_path >&2
git pull || fail_out "Couldn't update existing collection"
else
git clone --quiet $git_root_url $target_path || fail_out "Couldn't clone examples repository"
printf "examples downloaded to $target_path\n"
fi

if [ ! -z "$1" ]; then
do_checkout_version "$1"
else
cd $target_path
do_checkout_version `git describe --tags $(git rev-list --tags --max-count=1)`
fi
}


# remove the enlistment directory
function do_remove()
{
[ -d $target_path ] || fail_out "Couldn't find $target_path$root_path"
rm -rf $target_path
printf "$target_path removed\n"
}


# list all the tags we know
function do_list_versions()
{
cd $target_path
printf "local versions follow:\n"
git tag -n
printf "remote versions follow:\n"
git ls-remote --tags $git_root_url | grep -v "{}" | awk '{print $2}' | sed 's/refs\/tags\///'
printf "Version listed\n"
}


# switch version to something different
function do_checkout_version()
{
cd $target_path
printf "checkout out version %s ...\n" "$1"
git -c advice.detachedHead=false checkout "$1" || fail_out "Couldn't change versions"
printf "set to version %s\n" "$1"
}


#####
# set up the source and target info
git_root_url="git://github.com/deephaven/examples.git"

target_path="/data/examples"

# figure out command and dispatch ...
case "$1" in
download)
do_download "$2"
;;
version)
ensure_enlistment
cd $target_path
git describe
;;
versions)
ensure_enlistment
do_list_versions
;;
remove)
do_remove
;;
*)
printf "Unknown command '%s'\n" $1 >&2
usage
;;
esac

0 comments on commit ce94ee0

Please sign in to comment.