From ce94ee04b542c7531ad0949ba5ea049e96789c56 Mon Sep 17 00:00:00 2001 From: Devin Smith Date: Tue, 10 Aug 2021 13:14:52 -0700 Subject: [PATCH] Add samples/Dockerfile and workflow (#21) --- .github/workflows/build-ci.yml | 47 +++++++++++++ README.md | 35 +++++++--- docker/Dockerfile | 7 ++ docker/examples_script.sh | 116 +++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/build-ci.yml create mode 100644 docker/Dockerfile create mode 100755 docker/examples_script.sh diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml new file mode 100644 index 00000000..8a03c606 --- /dev/null +++ b/.github/workflows/build-ci.yml @@ -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/metadata-action@v3.3.0 + 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/login-action@v1.9.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker build + uses: docker/build-push-action@v2.5.0 + with: + context: ./samples/ + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + push: ${{ github.event_name != 'pull_request' }} diff --git a/README.md b/README.md index fa4d39e8..69a5eabd 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..e3feaa64 --- /dev/null +++ b/docker/Dockerfile @@ -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 / diff --git a/docker/examples_script.sh b/docker/examples_script.sh new file mode 100755 index 00000000..858f5581 --- /dev/null +++ b/docker/examples_script.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env sh + +# set -xv + +# show usage and quit +function usage() +{ + printf "usage: %s \n" $(basename $0) >&2 + printf "\n" >&2 + printf " commands are:\n" + printf " download [] - downloads and mounts all example data\n" >&2 + printf " gets latest version, unless 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