Skip to content

Merge pull request #323 from StampyAI/autopost-in-ai-safety-questions… #233

Merge pull request #323 from StampyAI/autopost-in-ai-safety-questions…

Merge pull request #323 from StampyAI/autopost-in-ai-safety-questions… #233

name: Deploy to Production Server
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
env:
CODA_API_TOKEN: ${{secrets.CODA_API_TOKEN}}
steps:
- name: Deploy Stampy to Production Server
uses: appleboy/[email protected]
with:
host: ${{secrets.SSH_PROD_HOST}}
username: ${{secrets.SSH_PROD_USERNAME}}
password: ${{secrets.SSH_PROD_PASSWORD}}
port: ${{secrets.SSH_PROD_PORT}}
script: |
export PATH=$PATH:/home/rob/miniconda3/condabin/
source ~/.bashrc
# Set up an environment variable to overide the SSL certificate location
# because for some reason by default it looks for:
# /root/miniconda3/envs/stampy/ssl/cert.pem
# which no longer exists
export SSL_CERT_FILE=/home/rob/miniconda3/envs/stampy/ssl/cert.pem
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/rob/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/rob/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/rob/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/rob/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
conda deactivate
export ENVIRONMENT_TYPE="production"
export DATABASE_PATH="/home/rob/stampy.local/stampy.db"
echo "Rebooting Stampy $(date +"%F-%T")"
# These for loops kill the existing stampy processes
# they check to make sure that they only kill processes
# that have been running for 60 seconds so that this
# update process does not kill itself.
for i in $(pgrep -f runstampy)
do
TIME=$(ps --no-headers -o etimes $i)
if [ "$TIME" -ge 60 ] ; then
kill $i
fi
done
for i in $(pgrep -f stam.py)
do
TIME=$(ps --no-headers -o etimes $i)
if [ "$TIME" -ge 60 ] ; then
kill $i
fi
done
export DISCORD_TOKEN="$(cat ~/.discordtoken)"
export DISCORD_GUILD="$(cat ~/.discordguild)"
export YOUTUBE_API_KEY="$(cat ~/.youtubeapikey)"
export CLIENT_SECRET_PATH="$(cat ~/.clientsecretpath)"
export OPENAI_API_KEY="$(cat ~/.openaikey)"
export WOLFRAM_TOKEN=$(cat ~/.wolframtoken);
export CODA_API_TOKEN=$(cat ~/.codatoken);
export IS_ROB_SERVER="TRUE"
cd ~/stampy
conda activate stampy
python -m scripts.notify-discord-stampy-offline
git stash
git pull --rebase
conda deactivate
conda env remove -n stampy
conda env create -f environment.yml
conda activate stampy
mkdir -p ~/stampy.local/logs/
export log_file=~/stampy.local/logs/stampy-log-$(date +"%F-%T.log")
./runstampy > $log_file 2>&1 &
ln -s -f $log_file ~/stampy.local/logs/stampy-latest.log
conda deactivate