#!/bin/sh set -e REV=1f55d7a32750b3e63c56aad00370411b90420a29 REPO_ROOT=$(git rev-parse --show-toplevel) FIXTURE=$REPO_ROOT/tests/fixtures/seeds/palm-heartwood.tar.bz2 WORKSPACE=$REPO_ROOT/tests/tmp/palm PASSPHRASE=asdf CONTAINER_NAME=radicle-httpd-with-fixtures HTTP_API_BINARY=radicle-httpd show_usage() { echo echo "Starts a radicle-httpd backend with test fixtures." echo echo "USAGE:" echo " run-httpd-with-fixtures [-b|d|h|n]" echo echo "OPTIONS:" echo " -b --binary Use a ${HTTP_API_BINARY} binary that is in PATH to avoid using Docker." echo " -d --detach Daemonize the docker process." echo " -h --help Print this Help." echo " -n --non-interactive Run in non-interactive mode, no user prompts." echo } prompt_workspace_removal() { echo "This will irrevocably destroy the following directories:" echo echo $WORKSPACE echo read -r -p "Are you sure you want to continue? [yes/no]: " confirm case "$confirm" in [yY][eE][sS]) rm -rf $WORKSPACE echo "Done" ;; *) echo "Ok, I won't touch your data." exit ;; esac } prepare_workspace() { echo echo "Unpacking fixture $FIXTURE" mkdir -p $WORKSPACE tar -xf $FIXTURE -C $WORKSPACE } run_docker() { echo "Starting docker at container $CONTAINER_NAME at $REV" echo " RAD_HOME=$WORKSPACE RAD_PASSPHRASE=$PASSPHRASE radicle-http" echo exec docker run \ --init \ --publish 8080:8080 \ --rm \ --name $CONTAINER_NAME \ --volume $WORKSPACE:/app/radicle \ "$@" \ --env "RAD_HOME=/app/radicle" \ --env "RAD_PASSPHRASE=$PASSPHRASE" \ "gcr.io/radicle-services/radicle-httpd:$REV" } run_binary() { if [ $CI = true ]; then local binaries_dir="$REPO_ROOT/tests/tmp" gsutil cp "gs://heartwood-artifacts/${REV}/radicle-httpd" "$binaries_dir" chmod a+x "${binaries_dir}/radicle-httpd" export PATH="$binaries_dir:$PATH" fi if ! [ -x "$(command -v $HTTP_API_BINARY)" ]; then echo echo "Couldn't find the $HTTP_API_BINARY binary in your PATH." echo "You can compile it from source:" echo " 👉 https://github.com/radicle-dev/heartwood" echo exit 1 fi echo echo "Starting $HTTP_API_BINARY" echo " RAD_HOME=$WORKSPACE $HTTP_API_BINARY" echo RAD_HOME=$WORKSPACE RAD_PASSPHRASE=$PASSPHRASE $HTTP_API_BINARY } BINARY=false NON_INTERACTIVE=false DETACH=false while [ $# -ne 0 ]; do case "$1" in --binary | -b) BINARY=true ;; --detach | -d) DETACH=true ;; --non-interactive | -n) NON_INTERACTIVE=true ;; *) show_usage exit ;; esac shift done if [ "$NON_INTERACTIVE" = true ]; then rm -rf $WORKSPACE prepare_workspace else prompt_workspace_removal prepare_workspace fi if [ "$BINARY" = true ]; then run_binary else if [ "$DETACH" = true ]; then run_docker --detach else run_docker fi fi