Files
podi/recipe/run/container
2022-03-15 18:33:17 +01:00

68 lines
2.2 KiB
Plaintext

# info: containerized app, nice starting point for Dockerfile + app
export POD=$(which podman || which docker || echo "")
hint_systemd(){
service=/etc/systemd/system/$PODI_APP.service
silent which podman || return 0
test -f $service && return 0
try podman generate systemd $PODI_APP 2>/dev/null > $PODI_APP.service
print "to survive server-reboots please run as root:"
echo "podman generate systemd $PODI_APP $service" | soften
echo "systemctl enable $PODI_APP.service" | soften
}
build(){
header .pod/app/container
test -f Dockerfile || { print "'Dockerfile' not found..skipping build"; }
test -f Dockerfile && {
silent which $POD || print '[!] please install podman (or docker)'
silent which $POD && verbose $POD build -t $PODI_APP .
} | soften
return 0
}
stop(){
test -z $POD || {
silent try $POD kill $PODI_APP
silent try $POD rm -f $PODI_APP
}
}
start(){
header .pod/app/container
silent which $POD || error "please install podman (or docker)"
test -z $POD || {
export PODI_APP=$PODI_APP
eval "$(cat .env)"
verbose ./app
hint_systemd
print ""
print "your container is running at $PODI_REMOTE:$PORT"
}
return 0
}
init_runtime(){
test -f app || {
generate(){
echo '#!/bin/sh'
echo 'set -x'
echo 'POD=$(which podman || which docker)'
echo 'test -z $PODI_APP && export PODI_APP=$(basename $(pwd))'
echo
echo '$POD run -d --rm --volume $(pwd):/app -w /app -e PORT -p $PORT:8080 --name $PODI_APP $PODI_APP /redbean.com'
echo '$POD logs $PODI_APP'
}
prompt "generate + commit 'app' startfile?" "$(generate | soften)" "[y/n] "
test $answer = "y" || error aborting
echo "FROM docker.io/coderofsalvation/redbean:1.5" > Dockerfile
echo "export PORT=$(awk 'BEGIN{ srand(); print int(rand()*1000)+8000 }')" >> .env
generate > app
chmod 755 app
git add app Dockerfile .env .pod podi && git commit -m "adding podi"
}
test -f .pod/checkout/rollback_simple || recipe checkout/rollback_simple
test -f .pod/start/envfile || recipe start/envfile
test -f .pod/init/server/sshkey || recipe init/server/sshkey
}