Files
podi/recipe/run/container

68 lines
2.2 KiB
Plaintext
Raw Normal View History

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