recipe app/simple

This commit is contained in:
Leon
2022-02-20 22:38:36 +01:00
parent e549095db8
commit 6d24345ddb
7 changed files with 82 additions and 0 deletions

2
app/.env Normal file
View File

@@ -0,0 +1,2 @@
export APP="./app"
export PORT=8050

View File

@@ -0,0 +1,7 @@
daemonize(){
while sleep 1s; do
set +e
${APP}
echo "$(tail -n200 app.log)" > app.log
done
}

30
app/.pod/envfile Normal file
View File

@@ -0,0 +1,30 @@
# info: sources environment variables from `.env` file during deployment
# installation : run 'podi recipe env-file' or put this file into .podi folder
# example usage: * put an .env file in your repo (with 'export FOO=1' e.g.)
# * override them on remote-server using './podi .env git@server FOO=2'
# * run './podi .env' to see all local/remote env-vars
envfile(){
header .pod/envfile
print "usage: ./podi envset [git@server] [app] [FOO=bar]"
test -f .env && print "reading '.env'" && . .env
test -f .env.live && print "override '.env' << .env.live" && . .env.live
}
envset(){ # envset [git@server] [app] [FOO=bar] : shows or sets [remote] environment variables
test -f .env || echo 'export FOO=bar # used for development' > .env
if test -n "$3"; then
loadremote $1 $2
printf "export %-40s # $(date)\n" "$3\"" | awk '{ gsub("=","=\"",$0); print $0; }' | ssh -p $port $1 "cat >> $gitpath/.env.live"
print OK
else
for app in .pod/*@*/*/config; do
. $app
print "$server:$appname (.env.live):"
test -z $3 && ssh -p $port $user@$server "test -f $gitpath/.env.live && cat $gitpath/.env.live || echo ' no env-vars yet'"
echo
done
fi
}
on checkout envfile

View File

@@ -0,0 +1,6 @@
export server='localhost'
export port='2222'
export user='git'
export gitpath='/home/git/app5'
export appname='app5'
export branch='master'

12
app/.pod/pipeline Normal file
View File

@@ -0,0 +1,12 @@
deploy(){
trigger hello
trigger backup
trigger checkout
trigger build
trigger runtests
trigger start
}
checkout(){
git --work-tree=$(pwd) --git-dir=$(pwd)/.git checkout -f
}

24
app/.pod/simple Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/sh
create_app_simple(){
header ".pod/app_simple"
test -f app || {
print "writing app"
echo 'echo "PID=$(cat .pid) => $(date) PORT=$PORT"' > app
chmod 755 app
print "writing .env"
PORT=$(awk 'BEGIN{ srand(); print int(rand()*1000)+8000 }')
echo 'export APP="./app"' > .env
echo 'export PORT='$PORT >> .env
}
}
start(){
. .env
test -f .pid && { print "stopping app5"; silent try kill -15 $(cat .pid); }
nohup ./podi daemonize ${APP} $PM_APP $PORT &> app.log &
echo $! > .pid
print "started: $APP [PID $(cat .pid)]"
}
on init_localhost create_app_simple

1
app/app Executable file
View File

@@ -0,0 +1 @@
echo "PID=$(cat .pid) => $(date) PORT=$PORT"