blob: cfc417eb28878a23ab7fb42c3b379600f6c63b1c [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
version: '3'
vars:
FL: ""
API_HOST:
sh: |
echo "http://localhost:80"
DEPLOY_CURRENT_HASH:
sh: |
if test -e "$OPS_ROOT/ide/deploy/bun.lockb"
then cd $OPS_ROOT/ide/deploy && bun $OPS_ROOT/ide/deploy/bun.lockb --hash
else echo "0"
fi
DEPLOY_PREVIOUS_HASH:
sh: |
if test -e "$OPS_ROOT/ide/deploy/hash.lock"
then cat $OPS_ROOT/ide/deploy/hash.lock
else echo "0"
fi
tasks:
prereq:
silent: true
cmds:
- test "$(python3 -V | awk -F. '{print $2}')" -ge 10 || die "python 3.10 or greater not available"
- test -x "$(which virtualenv)" || die "virtualenv does not exist"
- test "$(node -v | awk -F. '{print substr($1,2) }')" -ge 18 || die "nodejs 18 or greater not available"
- test "$(printf '%s\n' "$(bun -v)" "1.1.18" | sort -V | head -n 1)" = "1.1.18" || die "bun 1.1.18 or greater not available"
- test -d "$OPS_PWD/packages" || die "no packages in current directory"
- test -e ~/.wskprops || die "please run 'ops ide login' first"
- test -n "$OPSDEV_HOST" || die "please run 'ops ide login' first"
- test "$(ops -wsk property get --namespace | awk '{ print $3 }')" = "$OPSDEV_USERNAME" || die "Repeat the login"
- |
if ! test -d "$OPS_ROOT/ide/deploy/node_modules" || [ "{{.DEPLOY_CURRENT_HASH}}" != "{{.DEPLOY_PREVIOUS_HASH}}" ]
then
cd $OPS_ROOT/ide/deploy && bun install && rm -f $OPS_ROOT/ide/deploy/hash.lock && bun $OPS_ROOT/ide/deploy/bun.lockb --hash > $OPS_ROOT/ide/deploy/hash.lock
fi
- |
if test -e "$OPS_PWD/package.json"
then if ! test -d "$OPS_PWD/node_modules"
then cd $OPS_PWD ; bun install
fi
fi
- task: kill
kill:
silent: true
ignore_errors: true
cmds:
- |
PIDFILE=$(ops -opspath ~/.ops/tmp/deploy.pid)
echo $PIDFILE
if test -e $PIDFILE
then
PID=$(cat $PIDFILE)
if [ ! -z "$PID" ]; then
if ps -p "$PID" > /dev/null;
then
echo "Found previous deploy pid: $PID"
kill "$PID"
# PGRP=$(ps -o 'pgid=' -p $PID | xargs)
# if [ ! -z "$PGRP" ];
# then
# echo "Terminating deploy process group $PGRP"
# kill "$PGRP"
# else
# echo "Terminating deploy process $PID"
# kill "$PID"
# fi
fi
fi
rm -f $PIDFILE
fi
setup:
silent: true
desc: setup OpenServerless ide
cmds:
- |
clear
while ! test -e ~/.wskprops
do $OPS ide login
done
- |
echo "**************************************************************************************"
echo "*** Available Commands on Terminal:"
echo "*** 'deploy' (alias for 'ops ide deploy') to deploy your app to {{.API_HOST}}"
echo "*** 'devel' (alias for 'ops ide devel') to start incremental development mode"
echo "*** 'login' (alias for 'ops ide login') to login as a different user"
echo "*** 'ops ide' for more informations"
echo "*** https://openserverless.apache.org/ for online documentation"
echo "**************************************************************************************"
login:
silent: true
desc: login in you OpenServerless host
cmds:
- |
if test -n "{{._apihost_}}"
then OPSDEV_APIHOST="{{._apihost_}}"
#else OPSDEV_APIHOST="http://localhost"
fi
echo "*** Configuring Access to OpenServerless ***"
if test -z "{{._apihost_}}"
then echo -n "Enter Apihost: "
read OPSDEV_APIHOST
OPSDEV_APIHOST="$(echo $OPSDEV_APIHOST | tr -d '\r')"
else OPSDEV_APIHOST="{{._apihost_}}"
fi
if test -z "{{._username_}}"
then echo -n "Enter Username: "
read OPSDEV_USERNAME
OPSDEV_USERNAME="$(echo $OPSDEV_USERNAME | tr -d '\r')"
else OPSDEV_USERNAME="{{._username_}}"
fi
echo apihost=$OPSDEV_APIHOST username=$OPSDEV_USERNAME
if $OPS -login "$OPSDEV_APIHOST" "$OPSDEV_USERNAME"
then
OPSDEV_HOST_PROT="$(echo "$OPSDEV_APIHOST" | awk -F '://' '{print $1}')"
OPSDEV_HOST_URL="$(echo "$OPSDEV_APIHOST" | awk -F '://' '{print $2}')"
config OPSDEV_APIHOST="$OPSDEV_APIHOST"
config OPSDEV_USERNAME="$OPSDEV_USERNAME"
config OPSDEV_HOST="$OPSDEV_HOST_PROT://$OPSDEV_USERNAME.$OPSDEV_HOST_URL"
source ~/.wskprops
#config OPENAI_API_HOST=https://openai.nuvolaris.io
#config OPENAI_API_KEY="$(echo "$AUTH" | awk -F: '{print $1 }')"
#config OLLAMA_API_HOST=https://ollama.nuvolaris.io
#config OLLAMA_API_KEY="$(echo "$AUTH" | awk -F: '{print $1 }')"
else
false
fi
poll:
silent: true
desc: poll activation logs
cmds:
- $OPS activation poll
serve:
silent: true
desc: local web server
ignore_error: true
cmds:
- |
OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web`
echo "Serving assets from ${OPS_UPLOAD_FOLDER:-web}"
bun {{.TASKFILE_DIR}}/deploy/serve.js -h 127.0.0.1 -P $OPSDEV_HOST -d "$OPS_PWD/${OPS_UPLOAD_FOLDER:-web}"
deploy:
silent: true
interactive: true
desc: deploy a project or a single action (with _action_=<dir-or-file>)
cmds:
- task: prereq
- |
set -a
if test -e $OPS_PWD/.env
then source $OPS_PWD/.env
fi
if test -e $OPS_PWD/packages/.env
then source $OPS_PWD/packages/.env
fi
if test -n "$AUTH_CHECK"
then if test "$AUTH_CHECK" != "$AUTH"
then echo "You are logged in a different user than your configured AUTH_CHECK" ; exit 1
fi
fi
if {{.__dry_run}}
then DRY="--dry-run" ; ECHO='echo'
else DRY="" ; ECHO=""
fi
if test -z "{{._action_}}"
then
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY
OPS_UPLOAD_FOLDER=`bun {{.TASKFILE_DIR}}/deploy/info.js upload web`
echo "UPLOAD ASSETS FROM ${OPS_UPLOAD_FOLDER}"
$ECHO $OPS util upload ${OPS_UPLOAD_FOLDER:-web}
echo "URL: $OPSDEV_HOST"
else
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s "{{._action_}}" $DRY
fi
undeploy:
desc: undeploy all the actions
prompt: "are you sure you want to remove all actions and packages?"
silent: true
cmds:
- task: prereq
- >
$OPS action list
| awk 'NR>1 { print $1}'
| while read action ;
do if {{.__dry_run}}
then echo '$' $OPS action delete "$action"
else $OPS action delete "$action"
fi
done
- >
$OPS package list
| awk 'NR>1 { print $1}'
| while read package ;
do if {{.__dry_run}}
then echo '$' $OPS package delete "$package"
else $OPS package delete "$package"
fi
done
- >
if {{.__dry_run}}
then echo '$' $OPS util clean
else $OPS util clean
fi
clean:
silent: true
cmds:
- task: kill
- |
if test -d "$OPS_PWD/packages"
then
echo "*** removing virtualenv"
/bin/rm -rvf "$OPS_PWD"/packages/*/*/virtualenv/
echo "*** removing node_modules"
/bin/rm -rvf "$OPS_PWD"/packages/*/*/node_modules/
echo "*** removing .zip"
/bin/rm -vf "$OPS_PWD"/packages/*/*.zip
else die "no packages in current directory"
fi
devel:
interactive: true
silent: true
desc: start interactive development mode files
cmds:
- task: prereq
- |
set -a
if test -e $OPS_PWD/.env
then source $OPS_PWD/.env
fi
if test -e $OPS_PWD/packages/.env
then source $OPS_PWD/packages/.env
fi
if test -n "$AUTH_CHECK"
then if test "$AUTH_CHECK" != "$AUTH"
then echo "You are logged in a different user than your configured AUTH_CHECK" ; exit 1
fi
fi
if {{.__dry_run}}
then DRY="--dry-run" ; ECHO='echo'
else DRY="" ; ECHO=""
fi
if {{.__fast}}
then FAST="-f"
else FAST=""
fi
if [ -f /proc/version ]; then
if rg -i microsoft /proc/version >/dev/null 2>&1; then
export WATCHFILES_FORCE_POLLING=1
fi
# Check for macOS platform
elif [ "$(uname)" == "Darwin" ]; then
#export WATCHFILES_FORCE_POLLING=1
# Check for Windows platform (via WSL or similar)
elif [ -n "$WSL_DISTRO_NAME" ]; then
# WSL can have /proc/version like Linux
if rg -i microsoft /proc/version >/dev/null 2>&1; then
export WATCHFILES_FORCE_POLLING=1
fi
fi
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -w $FAST $DRY
true
shell:
desc: open a bash shell with the current environment
interactive: true
dir: $OPS_PWD
cmds:
- bash
python:
desc: python subcommand
nodejs:
desc: nodejs subcommand