This document provides instructions on how to set up and deploy the project using a Git-based deployment strategy with automated service restarts and environment variable management.
- A Virtual Private Server (VPS) with SSH access.
- Git installed on both local machine and VPS.
- A bare Git repository set up on the VPS.
- Create a Bare Repository on Your VPS
mkdir -p /path/to/git/repos/your-project.git
cd /path/to/git/repos/your-project.git
git init --bare
- Set Up the
post-receive
Hook Create apost-receive
hook to automate deployment tasks:
nano /path/to/git/repos/your-project.git/hooks/post-receive
Add the following script:
#!/bin/bash
GIT_WORK_TREE=/home/telegram/bitcoin_bus_bot.git git checkout -f main
# Keep the repository files to run the bot
TARGET="/home/telegram/bitcoin_bus_bot"
BRANCH="main"
while read oldrev newrev ref
do
if [[ $ref =~ .*/$BRANCH$ ]]; then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=/home/telegram/bitcoin_bus_bot.git checkout -f
else
echo "Ref $ref successfully received. Not deploying, since it's not the main branch."
fi
done
# Restart the bot
sudo systemctl restart grouphug-bot
Make the hook executable:
chmod +x /path/to/git/repos/your-project.git/hooks/post-receive
Configure GitHub Actions to automate pushing changes to the VPS:
name: Push to VPS and Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up SSH keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add remote and push
run: |
git remote add deploy ssh://user@your-vps-ip/path/to/git/repos/your-project.git
git push deploy main
- Ensure that SSH keys are managed securely.
- Use secrets management tools for sensitive data like TELEGRAM_BOT_TOKEN.
- Create or update the Markdown file: Open your text editor or use the GitHub interface to create or edit
README.md
orDEPLOYMENT.md
. - Paste the content: Use the above example as a template.
- Commit and push: Save your changes, commit, and push them to your repository.
git add README.md # or DEPLOYMENT.md
git commit -m "Update deployment documentation"
git push origin main
This will help ensure anyone working with or deploying your project has clear guidelines and can maintain the necessary operational standards.