#!/bin/bash
# docker run -it --rm -v d:/relflow_example:/relflow_example -e HEX_CDN=https://hexpm.upyun.com erlang /relflow_example/relflow_example.sh
# has git
which git >/dev/null 2>&1 || { echo "no git"; exit 1; }
# has rebar3
which rebar3 >/dev/null 2>&1 || { echo "no rebar3"; exit 1; }
press_to_continue() {
echo -e "\e[34m###### $1, press enter to continue\e[0m"
read -s -n 1
}
relflow_example_erl() {
echo -e "-module(relflow_example).\n-export([run/0]).\nrun() -> $1." > apps/relflow_example/src/relflow_example.erl
cat apps/relflow_example/src/relflow_example.erl
}
deploy_tar_gz() {
mv _build/default/rel/relflow_example/relflow_example-*.tar.gz deploy/releases/
}
# clean up
press_to_continue "clean up"
echo "cd ~"
cd ~
# stop exist server
if [ -f "relflow_example/deploy/bin/relflow_example" ]; then
cd relflow_example/deploy
if [ "$(./bin/relflow_example ping)" == "pong" ]; then
echo "stop exist server"
./bin/relflow_example stop
fi
cd ..
fi
echo "rm -rf relflow_example"
rm -rf relflow_example
# new release
press_to_continue "rebar3 new release relflow_example"
rebar3 new release relflow_example
cd relflow_example
press_to_continue "modify rebar.config"
# add %% relflow-release-version-marker
sed -i "s/\"\0.1.0\"/\n\"0.1.0\" %% relflow-release-version-marker\n/" rebar.config
# use minimal mode
sed -i "s/{mode, dev}/{mode, minimal}/" rebar.config
# add relflow plugin
echo "{plugins, [relflow]}." >> rebar.config
echo "deploy" >> .gitignore
cat rebar.config
# add example code
press_to_continue "add apps/relflow_example/src/relflow_example.erl"
relflow_example_erl "111"
# init git
press_to_continue "git init and tag"
git init -b master
git config user.email "relflow_example@example.com"
git config user.name "relflow_example"
git add .
git commit -m "0.1.0"
git tag v0.1.0
press_to_continue "rebar3 tar"
rebar3 tar
# deploy
press_to_continue "deploy first release v0.1.0"
echo "mkdir -p deploy/releases"
mkdir -p deploy/releases
deploy_tar_gz
cd deploy
press_to_continue "unzip first tar"
echo "tar -zxvf releases/relflow_example-0.1.0.tar.gz"
tar -zxf releases/relflow_example-0.1.0.tar.gz
# run server
press_to_continue "run server"
./bin/relflow_example daemon
./bin/relflow_example ping
press_to_continue "rpc: relflow_exwample:run() => 111"
./bin/relflow_example rpc relflow_example run []
# update code
cd ..
press_to_continue "modify relflow_example.erl"
relflow_example_erl "222"
press_to_continue "git commit"
git commit -am "update"
# new release
press_to_continue "relflow"
rebar3 relflow -u $(git tag | tail -n 2 | head -n 1)
rebar3 relup -n relflow_example -v $(git tag | tail -n 1 | cut -c2-) -u $(git tag | tail -n 2 | head -n 1 | cut -c2-)
press_to_continue "rebar3 tar"
rebar3 tar
# deploy new release
press_to_continue "deploy new release"
deploy_tar_gz
cd deploy
press_to_continue "upgrade"
./bin/relflow_example upgrade $(git tag | tail -n 1 | cut -c2-)
press_to_continue "versions"
./bin/relflow_example versions
press_to_continue "rpc: relflow_exwample:run() => 222"
./bin/relflow_example rpc relflow_example run []
press_to_continue "stop server"
./bin/relflow_example stop
press_to_continue "run relflow_example successfully"
I just learn about relflow plugins, share some play code
save code to /host/path/relflow_example.sh
play with docker
docker run -it --rm -v /host/path:/container/path erlang /container/path/relflow_example.sh
replace with your path -v /host/path:/container/path
have fun