mirror of
https://github.com/coderofsalvation/podi.git
synced 2026-05-18 05:04:56 +02:00
work in progress [might break]
This commit is contained in:
27
README.md
27
README.md
@@ -1 +1,28 @@
|
||||
> remove layers of complexity.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
$ cd myapp
|
||||
$ git init
|
||||
$ podi init git@myserver:/dir/to/deploy
|
||||
.pod dir created
|
||||
$ git push git@myserver
|
||||
# PROFIT!
|
||||
```
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
$ wget "https://raw.githubusercontent.com/coderofsalvation/podi/master/podi"
|
||||
$ chmod 755 podi
|
||||
$ ./podi
|
||||
usage:
|
||||
init git@server:/dir/to/deploy [branch] [port] [name] initializes a deployment
|
||||
recipe <name_or_url> installs a recipe from podi repo or url
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
||||
* [adding your own recipes](doc/recipes.md)
|
||||
|
||||
24
doc/recipes.md
Normal file
24
doc/recipes.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Adding your own recipes
|
||||
|
||||
```bash
|
||||
$ ./podi recipe hello # install helloworld-example
|
||||
$ mv .pod/{hello,foo} # rename to foo and modify
|
||||
$ git add .pod/foo
|
||||
# PROFIT!
|
||||
```
|
||||
|
||||
# Adding your own recipe repository
|
||||
|
||||
Just expose a directory with recipes, and add `.index.txt` in that directory:
|
||||
|
||||
```bash
|
||||
$ \ls | xargs -n1 echo > .index.txt
|
||||
```
|
||||
|
||||
Then add it to the `podi` script:
|
||||
|
||||
```bash
|
||||
RECIPE_REPOS="https://raw.githubusercontent.com/coderofsalvation/podi/master/recipe/.index.txt https://yoururl/.index.txt"
|
||||
```
|
||||
|
||||
> Profit!
|
||||
64
podi
64
podi
@@ -2,6 +2,7 @@
|
||||
set -e
|
||||
required="awk ssh git hostname basename"
|
||||
test -z $HOST && host=$USER@$(hostname) || host=$HOST
|
||||
RECIPE_REPOS="https://raw.githubusercontent.com/coderofsalvation/podi/master/recipe/.index.txt"
|
||||
#trap "trigger cleanup" 0 1 2 3 6
|
||||
C_GREY="\\033[1;30m"
|
||||
C_BOLD="\\033[1;37;40m"
|
||||
@@ -61,32 +62,34 @@ init_post_receive(){
|
||||
mkdir .tmp
|
||||
alias git=\"git --work-tree=$1/.tmp --git-dir=$1/.git\"
|
||||
git checkout -f 1>/dev/null 2>/dev/null
|
||||
test -f podmen && rm podmen
|
||||
test -d .podmen && rm -rf .podmen
|
||||
cp -r .tmp/podmen .tmp/.podmen .
|
||||
test -f podi && rm podi
|
||||
test -d .pod && rm -rf .pod
|
||||
cp -r .tmp/podi .tmp/.pod .
|
||||
rm -rf .tmp
|
||||
test -f podmen && ./podmen deploy
|
||||
test -f podi && ./podi deploy
|
||||
" | awk '{ gsub("^[ ]+","",$0); print $0 }'
|
||||
}
|
||||
|
||||
loadremote(){
|
||||
cfg=.podmen/$1/$2/config
|
||||
test -f $cfg || error "remote (.podmen/$1/$2/config) does not exist"
|
||||
cfg=.pod/$1/$2/config
|
||||
test -f $cfg || error "remote (.pod/$1/$2/config) does not exist"
|
||||
. $cfg
|
||||
}
|
||||
|
||||
hello(){
|
||||
echo -e '
|
||||
\e[38;5;57m 888
|
||||
\e[38;5;93m 888 88e e88 88e e88 888 888 888 8e ,e e, 888 8e
|
||||
\e[38;5;129m 888 888b d888 888b d888 888 888 888 88b d88 88b 888 88b
|
||||
\e[38;5;165m 888 888P Y888 888P Y888 888 888 888 888 888 , 888 888
|
||||
\e[38;5;201m 888 88" "88 88" "88 888 888 888 888 "YeeP" 888 888
|
||||
\e[38;5;207m 888
|
||||
\e[38;5;57m 88 88
|
||||
\e[38;5;93m 88
|
||||
\e[38;5;129m 8b,dPPYba, ,adPPYba, ,adPPYb,88 88
|
||||
\e[38;5;165m 88P` "8a a8" "8a a8" `Y88 88
|
||||
\e[0m 88 d8 8b d8 8b 88 88
|
||||
\e[38;5;201m 88b, ,a8" "8a, ,a8" "8a, ,d88 88
|
||||
\e[38;5;201m 88`YbbdP"` `"YbbdP"` `"8bbdP"Y8 88
|
||||
\e[38;5;205m 88
|
||||
\e[38;5;207m 88
|
||||
\e[0m'
|
||||
}
|
||||
|
||||
|
||||
init(){ # init git@server:/dir/to/deploy [branch] [port] [name] : initializes a deployment
|
||||
test -z $1 && usage
|
||||
trigger init_localhost
|
||||
@@ -94,11 +97,11 @@ init(){ # init git@server:/dir/to/deploy [branch] [port] [name] : initializes a
|
||||
}
|
||||
|
||||
init_localhost(){
|
||||
test -d ~/.podmen || { mkdir -p ~/.podmen && extract config > ~/.podmen/config; }
|
||||
test -d .podmen || {
|
||||
mkdir -p .podmen && extract pipeline > .podmen/pipeline;
|
||||
test -d .podmen && for i in .podmen/* ; do . $i; done
|
||||
test -f podmen || cp $0 .
|
||||
test -d ~/.pod || { mkdir -p ~/.pod && extract config > ~/.pod/config; }
|
||||
test -d .pod || {
|
||||
mkdir -p .pod && extract pipeline > .pod/pipeline;
|
||||
test -d .pod && for i in .pod/* ; do . $i; done
|
||||
test -f podi || cp $0 .
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +114,8 @@ init_server(){
|
||||
test -z $3 && port=22 || port=$3
|
||||
test -z $4 && gitremote=$appname || gitremote=$4
|
||||
test $gitpath = $server && gitpath="$(basename $(pwd))"
|
||||
mkdir -p .podmen/$user@$server
|
||||
local config=.podmen/$user@$server/$appname/config
|
||||
mkdir -p .pod/$user@$server
|
||||
local config=.pod/$user@$server/$appname/config
|
||||
mkdir -p $(dirname $config)
|
||||
echo "export server='$server' " > $config
|
||||
echo "export port='$port' " >> $config
|
||||
@@ -122,7 +125,7 @@ init_server(){
|
||||
echo "export branch='$branch' " >> $config
|
||||
. $config
|
||||
scp -P $port $0 $user@$server:/tmp/. 1>/dev/null
|
||||
ssh -p $port $user@$server HOST=$user@$server /tmp/podmen init_gitops $gitpath $server $user $port
|
||||
ssh -p $port $user@$server HOST=$user@$server /tmp/podi init_gitops $gitpath $server $user $port
|
||||
test -d .git || git init
|
||||
git remote | silent grep $gitremote || git remote add -t $branch $gitremote ssh://$user@$server:$port$gitpath/.git
|
||||
silent git push $server $branch && print "you can now run: git push $user@server:$appname"
|
||||
@@ -139,12 +142,15 @@ init_gitops(){
|
||||
chmod +x $1/.git/hooks/post-receive
|
||||
}
|
||||
|
||||
deploy(){ # deploy <gitremote> <branch> : use local .podmen to trigger deployment (without gitcommit)
|
||||
echo todo
|
||||
}
|
||||
|
||||
recipe(){ # recipe <name_or_url> : installs a recipe from podmen repo or url
|
||||
echo
|
||||
recipe(){ # recipe <name_or_url> : installs a recipe from podi repo or url
|
||||
list(){
|
||||
for repo in $RECIPE_REPOS; do
|
||||
print $(dirname $repo)
|
||||
curl $repo
|
||||
done
|
||||
}
|
||||
test -z $1 && list
|
||||
"$@"
|
||||
}
|
||||
|
||||
usage(){
|
||||
@@ -155,7 +161,7 @@ usage(){
|
||||
gsub(".*{ # ","",$0)
|
||||
gsub(" :.*","",$0)
|
||||
printf(" %-55s %s\n",$0,info)
|
||||
}' $0 .podmen/* 2>/dev/null
|
||||
}' $0 .pod/* 2>/dev/null
|
||||
printf "\ndeploy targets:\n\n"
|
||||
git remote | awk '{ printf(" %s\n",$1) }'
|
||||
exit 0
|
||||
@@ -163,6 +169,6 @@ usage(){
|
||||
|
||||
foreach "$required" installed || error "please install: $required"
|
||||
# source external variables, functions and decorators
|
||||
test -d .podmen && for i in .podmen/* ; do . $i; done
|
||||
test -d .pod && for i in .pod/* ; do . $i; done
|
||||
test -z $1 && usage
|
||||
trigger "$@"
|
||||
|
||||
7
recipe/deploy
Normal file
7
recipe/deploy
Normal file
@@ -0,0 +1,7 @@
|
||||
# description: trigger deployment without gitcommit (just execute .pod)
|
||||
# installation : run 'podi recipe deploy' or put this file into .podman folder
|
||||
# example usage: ./podman deploy
|
||||
|
||||
deploy(){ # deploy <gitremote> <branch> : use local .pod to trigger deployment (without gitcommit)
|
||||
echo todo
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
# installation : run 'podmen recipe env-file' or put this file into .podman folder
|
||||
# info: sources environment variables from `.env` file during deployment
|
||||
# installation : run 'podi recipe env-file' or put this file into .podman folder
|
||||
# example usage: * put an .env file in your repo (with 'export FOO=1' e.g.)
|
||||
# * override them on remote-server using './podmen .env git@server FOO=2'
|
||||
# * run './podmen .env' to see all local/remote env-vars
|
||||
# * override them on remote-server using './podi .env git@server FOO=2'
|
||||
# * run './podi .env' to see all local/remote env-vars
|
||||
|
||||
recipe_envfile(){
|
||||
header .podmen/envfile
|
||||
header .pod/envfile
|
||||
test -f .env && print "reading '.env'" && . .env
|
||||
test -f .env.live && print "override '.env' << .env.live" && . .env.live
|
||||
print PORT=$PORT
|
||||
@@ -17,7 +18,7 @@ envset(){ # envset [git@server] [app] [FOO=bar] : shows or sets [remote] environ
|
||||
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 .podmen/*@*/*/config; do
|
||||
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'"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# a barebones recipe
|
||||
# info: a barebones recipe (startingpoint for own recipe)
|
||||
|
||||
hello(){ header myrecipe; }
|
||||
world(){ print helloworld; }
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
# installation : run 'podmen recipe rollback.simple' or put this file into .podman folder
|
||||
# info: perform easy server-rollbacks based on gitcommit
|
||||
# installation: run 'podi recipe rollback.simple' or put this file into .podman folder
|
||||
# example usage: ./podman rollback git@server 3fe2f615
|
||||
|
||||
checkout(){
|
||||
header rollback.simple
|
||||
test -z $ROLLBACK && {
|
||||
git --work-tree=$(pwd) --git-dir=$(pwd)/.git checkout -f
|
||||
print usage: ./podmen rollback $USER@$PM_REMOTE $PM_APP $PM_COMMIT
|
||||
print usage: ./podi rollback $USER@$PM_REMOTE $PM_APP $PM_COMMIT
|
||||
}
|
||||
test -z $ROLLBACK || trigger do_rollback
|
||||
}
|
||||
@@ -17,7 +18,7 @@ do_rollback(){
|
||||
rollback(){ # rollback <user@remote> <app> <commit> : rolls back deployment to certain commit
|
||||
loadremote $1 $2
|
||||
scp -P $port $0 $user@$server:/tmp/. 1>/dev/null
|
||||
ssh -p $port $user@$server "export HOST=$user@$server; export ROLLBACK=$3; cd $gitpath; ./podmen deploy"
|
||||
ssh -p $port $user@$server "export HOST=$user@$server; export ROLLBACK=$3; cd $gitpath; ./podi deploy"
|
||||
}
|
||||
|
||||
on extract checkout_or_rollback
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# installation : run 'podmen recipe sshkey' or put this file into .podman folder
|
||||
# info: generates sshkey to be shared with external developers
|
||||
# installation : run 'podi recipe sshkey' or put this file into .podman folder
|
||||
# example usage: ./podman init git@yourserver
|
||||
|
||||
init_sshkey(){
|
||||
|
||||
Reference in New Issue
Block a user