Skip to content

Commit

Permalink
chore: improve orb deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Jul 4, 2024
1 parent f11eac3 commit 57f8da9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 8 additions & 4 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ tasks:

## Local prod env in Orbstack
# run `orb` into default ubuntu env, now in current project path
# run: `run/setup.sh _build/prod-orb` to setup deploy.sh
# run: `_build/prod-orb/deploy.sh v0.1.4` to deploy a version from github vsn release
# current release at: _build/prod-orb/current
# Visit by: http://ubox1.orb.local:4000/
orb-ping: curl http://ubox1.orb.local:4000/ | jq
orb-run: _build/prod-orb/current/bin/hello_api {{.CLI_ARGS}}
orb-pid: task orb-run -- pid
orb-sh: task orb-run -- remote
# deploy a version from github vsn release, as: task orb-deploy -- v0.1.4
orb-deploy: _build/prod-orb/deploy.sh {{.CLI_ARGS}}
orb-deploy-setup: run/setup.sh _build/prod-orb
orb-deploy-setup-local: cp run/deploy.sh _build/prod-orb/

## Docker env
dk-builder: docker pull hexpm/elixir:1.17.1-erlang-27.0-debian-bullseye-20240612-slim
Expand Down
18 changes: 14 additions & 4 deletions run/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ if [ -e $cur_rel ]; then
echo Clean current-release old link from $cur_rel
fi

echo Link new current-release to $vsn_dir and start it at $(date -Iseconds)
echo Link new current-release to $vsn_dir
ln -sf $vsn_dir $cur_rel
echo "==> app bin-path: $full_bin"

env_file=$app_root/.env.prod
if [ -f $env_file ]; then
echo "load env file: $env_file"
. $env_file
fi
echo Starting app at $(date -Iseconds)
$full_bin daemon_iex

echo Waiting app ready...
timeout=60
limit=$(( $timeout + 1 ))
for i in $(seq 1 $limit); do
# echo waiting $i
if [ $i -gt $timeout ]; then
echo "Waiting timeout, more than $timeout seconds at $(date -Iseconds)"
exit 1
Expand All @@ -63,8 +74,7 @@ for i in $(seq 1 $limit); do
sleep 1
fi
done
echo "Congrats! Deploy app to ${vsn_dir} at $(date -Iseconds)"
echo "==> bin-path: $full_bin"
echo "Congrats! Deployed app to ${vsn_dir} at $(date -Iseconds)"

## clean old versions
cd $app_root
Expand All @@ -77,4 +87,4 @@ if [ $total -gt $keep_limit ]; then
rm -fr $app_root/$vsn.tar.gz
done
fi
echo Keep ${keep_limit} versions from total=$total in app_root=$app_root
echo Kept at most ${keep_limit} from total $total versions in app_root=$app_root
5 changes: 4 additions & 1 deletion run/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ mkdir -p $app_root
script_path=${app_root}/deploy.sh
git_repo=cao7113/hello-api-elixir

mkdir -p $app_root
mkdir -p $app_root
# force clean old version
[ -f $script_path ] && rm -fr $script_path

script_url="https://raw.githubusercontent.com/${git_repo}/main/run/deploy.sh"
if [ ! -e $script_path ]; then
wget -q -O $script_path $script_url
Expand Down

0 comments on commit 57f8da9

Please sign in to comment.