Skip to content

Commit

Permalink
Initial support for git integration w 'abaco init'
Browse files Browse the repository at this point in the history
Projects created via 'abaco init' now initialize the new project as a git repo. This
is a forerunner to support automatically creating and connecting a git remote. Also
supported now is a base path (-B) for the new project and a text description (-d).
Finally, project templates do not need to be language-typed only so the help test
for the -l option was changed to reflect this fact.
  • Loading branch information
mwvaughn committed Jul 29, 2019
1 parent 0cdebe9 commit 0cf51b8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 45 deletions.
15 changes: 15 additions & 0 deletions abaco-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ if [[ "${ABACO_ENABLE_AUTO_REFRESH}" == "1" ]]; then
fi
export tapis_cli_avail

git_cli_avail=0
ABACO_USE_GIT_CLI=1
if [[ "${ABACO_USE_GIT_CLI}" == "1" ]]; then
if ! ((git_cli_avail)); then
if [[ -z "${GIT_CLI_PATH}" ]] || [[ -d "${GIT_CLI_PATH}" ]]; then
GIT_CLI_PATH=$(dirname $(which git))
fi
if [[ -f ${GIT_CLI_PATH}/git ]]; then
git_cli_avail=1
export git_cli_avail
fi
fi
fi
export git_cli_avail

AGAVE_AUTH_CACHE=
if [ ! -z "${AGAVE_CACHE_DIR}" ] && [ -d "${AGAVE_CACHE_DIR}" ]; then
if [ -f "${AGAVE_CACHE_DIR}/current" ]; then
Expand Down
102 changes: 57 additions & 45 deletions abaco-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,112 +12,124 @@ Initializes a new Abaco actor project.
Options:
-h show help message
-n project name (e.g. my_new_actor)
-l language (default: python3)
-d project description
-l project type (default: python3)
-B base path (default is .)
"

function usage() { echo "$HELP"; exit 0; }
function usage() {
echo "$HELP"
exit 0
}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR/abaco-common.sh"

function slugify {
function slugify() {
$DIR/slugify.py "${1}"
}

name=
description=
repo=
lang=
tenant=

while getopts ":hl:n:i:" o; do
case "${o}" in
n) # name
name=${OPTARG}
;;
l) # language
lang=${OPTARG}
;;
h | *) # print help text
usage
;;
esac
basepath="./"

while getopts ":hl:n:B:d:i:" o; do
case "${o}" in
n) # name
name=${OPTARG}
;;
d) # description
description=${OPTARG}
;;
l) # language
lang=${OPTARG}
;;
B) # basepath
basepath=${OPTARG}
;;
h | *) # print help text
usage
;;
esac
done
shift $((OPTIND-1))
shift $((OPTIND - 1))
repo="$1"

if [ -z "${name}" ]
then
if [ -z "${name}" ]; then
usage
fi

# URL-safen name
safename=`slugify "${name}"`
if [ "$safename" != "$name" ]
then
safename=$(slugify "${name}")
if [ "$safename" != "$name" ]; then
info "Making project name URL safe: $safename"
name="$safename"
fi

# Ensure directory $name is doens't exist yet
if [ ! -d "$name" ]
then
mkdir -p "$name"
if [ ! -d "${basepath}/${name}" ]; then
mkdir -p "${basepath}/${name}"
else
die "Project directory $name exists."
die "Directory $name exists at ${basepath}"
fi

# Template language - default Python2
if [ -z "${lang}" ]
then
if [ -z "${lang}" ]; then
lang="python3"
info "Defaulting to Python 3.6"
info "Defaulting to Python 3"
fi

# set repo to name if not passed by user
# else, check user-passed repo is valid (slugify)
if [ -z "${repo}" ]
then
if [ -z "${repo}" ]; then
repo=${name}
else
saferepo=$(slugify $repo)
if [ "$saferepo" != "$repo" ]
then
if [ "$saferepo" != "$repo" ]; then
info "Making repo name URL safe: $saferepo"
repo="$saferepo"
fi
fi

# Get tenant ID
if [ -f "$HOME/.agave/current" ]
then
if [ -f "${AGAVE_AUTH_CACHE}" ]; then
tenant=${TENANTID}
else
die "Can't determine TACC Cloud tenant"
fi

# Copy in template
if [ -d "$DIR/templates/$tenant/$lang" ]
then
if [ ! -f "$DIR/templates/$tenant/$lang/placeholder" ]
then
cp -R ${DIR}/templates/${tenant}/${lang}/ ${name}/
if [ -d "$DIR/templates/$tenant/$lang" ]; then
if [ ! -f "$DIR/templates/$tenant/$lang/placeholder" ]; then
cp -R ${DIR}/templates/${tenant}/${lang}/ ${basepath}/${name}/
else
die "Template support for $lang is not yet implemented."
fi
else
rm -rf ${name}
die "Error creating project directory $name"
die "Error creating project directory ${name}"
fi

# Template out the reactor.rc file
cat << EOF > "${name}/reactor.rc"
cat <<EOF >"${basepath}/${name}/reactor.rc"
# Reactor mandatory settings
REACTOR_NAME=${name}
# REACTOR_DESCRIPTION=
# REACTOR_ALIAS=reactor-nickname
REACTOR_DESCRIPTION=${description}
# Docker settings
DOCKER_HUB_ORG=your_docker_registory_uname
DOCKER_IMAGE_TAG=${repo}
DOCKER_IMAGE_VERSION=0.1
EOF

if ((git_cli_avail)); then
info "Initializing ${name} as git repo..."
OWD=${PWD}
cd ${basepath}/${name} && git init && cd ${OWD}
fi

info "Complete: ${basepath}${name}"
exit 0

0 comments on commit 0cf51b8

Please sign in to comment.