blob: 815e32278ab2edad3aae5572a8da920720437036 [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
vars:
MSG: |
This command must be run inside a devcontainer.
Please use 'ops ide devcontainer' to create a configuration and enter in a devcontainer.
You can then use 'ops ide devel' and 'ops ide deploy'.
You can also reopen the project with VSCode and use the command 'Reopen in Container'.
cmds:
- test -e "/.dockerenv" || die "{{.MSG}}"
- test "$(python3 -V | awk -F. '{print $2}')" -ge 10 || die "python 3.10 or greater not available"
- test -x "$(which virtualenv)" || die "you need python virtualenv"
- 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
devcontainer:
silent: true
desc: add a devcontainer to your project
cmds:
- |
if test -e "$OPS_PWD/.devcontainer/devcontainer.json"
then echo "a .devcontainer already exists"
else
mkdir -p "$OPS_PWD/.devcontainer"
cp devcontainer.json "$OPS_PWD/.devcontainer/"
echo "devcontainer created in .devcontainer - please use VSCode and the command 'Reopen in Container'"
fi
- |
if echo "$OPS_PWD/" | rg ' '
then die "please place your workspace in a folder WITHOUT SPACES IN THE FOLDER NAME!!!!"
fi
- bun x @devcontainers/cli up --workspace-folder "$OPS_PWD"
- bun x @devcontainers/cli exec --workspace-folder "$OPS_PWD" -- bash
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 -e "$OPS_PWD/.env"
then source "$OPS_PWD/.env"
fi
if test -n "{{._apihost_}}"
then OPSDEV_APIHOST="{{._apihost_}}"
fi
echo "*** Configuring Access to OpenServerless ***"
if test -z "{{._apihost_}}"
then
if test -z "$OPS_APIHOST"
then
echo -n "Enter Apihost: "
read OPSDEV_APIHOST
OPSDEV_APIHOST="$(echo $OPSDEV_APIHOST | tr -d '\r')"
else
OPSDEV_APIHOST="$OPS_APIHOST"
fi
else OPSDEV_APIHOST="{{._apihost_}}"
fi
if test -z "{{._username_}}"
then
if test -n "$OPS_USERNAME"
then
OPSDEV_USERNAME="$OPS_USERNAME"
else
echo -n "Enter Username: "
read OPSDEV_USERNAME
OPSDEV_USERNAME="$(echo $OPSDEV_USERNAME | tr -d '\r')"
fi
else OPSDEV_USERNAME="{{._username_}}"
fi
echo "Logging user $OPSDEV_USERNAME in $OPSDEV_APIHOST"
if test -n "$OPS_PASSWORD"
then export "OPS_PASSWORD"
fi
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
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 "WARNING: wrong deploy! You are logged in a different user than your pinned one and configured in .env as AUTH_CHECK" ; exit 1
fi
fi
if {{.__dry_run}}
then DRY="--dry-run" ; ECHO='echo'
else DRY="" ; ECHO=""
fi
if {{.__web}}
then deploy_packages=""
else deploy_packages="1"
fi
if {{.__packages}}
then deploy_web=""
else deploy_web="1"
fi
if test -n "{{._action_}}"
then
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -s "{{._action_}}" $DRY
else
if [ -n "$deploy_packages" ]
then
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -d $DRY
fi
if [ -n "$deploy_web" ]
then
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"
fi
fi
undeploy:
desc: undeploy actions and packages from the current project
silent: true
cmds:
- task: prereq
- |
if {{.__dry_run}}
then DRY="--dry-run"
else DRY=""
fi
# Check if an action argument is provided
if test -n "{{._action_}}"
then
# Undeploy a specific action
echo "Undeploying specific action: {{._action_}}"
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -u -s "{{._action_}}" $DRY
else
# Undeploy all actions and packages from the current project
bun {{.TASKFILE_DIR}}/deploy/index.js "$OPS_PWD" -u $DRY
fi
- >
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 "WARNING: wrong deploy! 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