fix bo build with docker #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to VPS | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
pull_request: | |
branches: | |
- master | |
- develop | |
types: | |
- closed | |
jobs: | |
deploy: | |
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Récupérer le code du dépôt | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# 2. Configurer l'agent SSH avec la clé privée | |
- name: Setup SSH agent | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.VPS_SSH_KEY }} | |
- name: Add server to known_hosts | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan -H ${{ secrets.VPS_IP }} >> ~/.ssh/known_hosts | |
# 3. Déployer sur le VPS | |
- name: Deploy to VPS | |
env: | |
VPS_IP: ${{ secrets.VPS_IP }} | |
VPS_USER: ${{ secrets.VPS_USER }} | |
run: | | |
if [ -z "$VPS_USER" ]; then | |
echo "Error: VPS_USER is not set." | |
exit 1 | |
else | |
echo "VPS_USER is set." | |
fi | |
if [ -z "$VPS_IP" ]; then | |
echo "Error: VPS_IP is not set." | |
exit 1 | |
else | |
echo "VPS_IP is set." | |
fi | |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then | |
echo "Deploy in production environment" | |
ssh $VPS_USER@$VPS_IP 'mkdir -p ~/server/cyberlife-front' | |
rsync -avz --delete \ | |
--exclude '.git' \ | |
--exclude '.env' \ | |
--exclude 'node_modules' \ | |
. $VPS_USER@$VPS_IP:/home/$VPS_USER/server/cyberlife-front/ | |
ssh $VPS_USER@$VPS_IP ' | |
set -e | |
cd ~/server/ && | |
docker-compose restart cyberlife-front | |
' | |
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then | |
echo "Deploy in staging environment" | |
ssh $VPS_USER@$VPS_IP 'mkdir -p ~/server/cyberlife-staging' | |
rsync -avz --delete \ | |
--exclude '.git' \ | |
--exclude 'node_modules' \ | |
--exclude '.env' \ | |
. $VPS_USER@$VPS_IP:/home/$VPS_USER/server/cyberlife-staging/ | |
ssh $VPS_USER@$VPS_IP ' | |
set -e | |
cd ~/server/ && | |
docker-compose restart cyberlife-staging | |
' | |
fi |