97 lines
2.9 KiB
Bash
Executable File
97 lines
2.9 KiB
Bash
Executable File
# The deployment process works like this:
|
|
# 1. Build locally just to make sure that things work
|
|
# 2. SSH into the machine that will build the AppImage for ARM. There:
|
|
# 2.1. run git pull to get the latest version of the code
|
|
# 2.2. run argo appimage to build the image
|
|
# 3. SCP the appimage back to the local machine
|
|
# 4. SCP the files to the Raspberry Pi running the display:
|
|
# AppImage
|
|
# systemd service file
|
|
# 5. SSH into the display machine as root and:
|
|
# 5.1. Copy the AppImage file to /opt/dublinbus-display (create the directory if necessary)
|
|
# 5.2. If the service exists, restart it and exit
|
|
# 5.3. Copy the service file to /etc/systemd/system
|
|
# 5.4. Enable and activate the service
|
|
|
|
|
|
|
|
# Variables
|
|
GIT_REPO_URL="http://git.nahuellofeudo.com/nahuel/rs-dublinbus.git"
|
|
|
|
# For the build machine
|
|
BUILD_MACHINE_NAME=raspi-ssd.localnet
|
|
BUILD_MACHINE_USER=nahuel
|
|
BUILD_MACHINE_SOURCE_DIRECTORY=/home/nahuel/Documents/sources
|
|
|
|
DEPLOY_MACHINE_NAME=dublinbus-display.local
|
|
DEPLOY_MACHINE_USER=display
|
|
DEPLOY_MACHINE_TARGET_DIRECTORY=/opt/dublinbus
|
|
|
|
|
|
# 1. Build locally
|
|
cargo appimage
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
echo
|
|
echo
|
|
echo "-------------------------------------------------------"
|
|
echo "\"cargo appimage\" failed. Check the logs"
|
|
echo "-------------------------------------------------------"
|
|
exit $?
|
|
fi
|
|
|
|
echo
|
|
echo
|
|
echo "-------------------------------------------------------"
|
|
echo "Local build successful "
|
|
echo "-------------------------------------------------------"
|
|
|
|
|
|
# 2. Build remotely on the ARM machine
|
|
ssh $BUILD_MACHINE_USER@$BUILD_MACHINE_NAME << EOF
|
|
echo Entering ${BUILD_MACHINE_SOURCE_DIRECTORY}
|
|
cd ${BUILD_MACHINE_SOURCE_DIRECTORY}
|
|
if [[ ! -d rs-dublinbus ]]; then
|
|
git clone ${GIT_REPO_URL}
|
|
cd rs-dublinbus
|
|
else
|
|
cd rs-dublinbus
|
|
git pull
|
|
fi
|
|
|
|
cargo appimage
|
|
EOF
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
echo
|
|
echo
|
|
echo "-------------------------------------------------------"
|
|
echo "Remote build failed. Check the logs"
|
|
echo "-------------------------------------------------------"
|
|
exit $?
|
|
fi
|
|
|
|
|
|
echo
|
|
echo
|
|
echo "-------------------------------------------------------"
|
|
echo "Remote build successful "
|
|
echo "-------------------------------------------------------"
|
|
|
|
# 3. SCP the appimage back to the local machine
|
|
scp $BUILD_MACHINE_USER@$BUILD_MACHINE_NAME:Documents/sources/rs-dublinbus/target/appimage/rs-dublinbus.AppImage /tmp
|
|
|
|
# 4. SCP the files to the Raspberry Pi running the display:
|
|
scp /tmp/rs-dublinbus.AppImage $DEPLOY_MACHINE_USER@$DEPLOY_MACHINE_NAME:$DEPLOY_MACHINE_TARGET_DIRECTORY
|
|
|
|
# Set up the service
|
|
ssh $DEPLOY_MACHINE_USER@$DEPLOY_MACHINE_NAME << EOF
|
|
sudo systemctl restart dublinbus
|
|
EOF
|
|
|
|
echo
|
|
echo
|
|
echo "-------------------------------------------------------"
|
|
echo "Service deployed and restarted "
|
|
echo "-------------------------------------------------------"
|