Update deploy.yml #19
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 Bettermi to OVH | |
on: | |
push: | |
branches: main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create SSH key | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts | |
sudo chmod 600 ~/.ssh/id_rsa | |
- name: Access to Server, Remove Docker Containers, Build Docker Image, Run Docker Container | |
run: | | |
ssh -i "~/.ssh/id_rsa" -o StrictHostKeyChecking=no ${{ secrets.SSH_USER_NAME }}@${{ secrets.SERVER_ADDRESS }} << 'ENDSSH' | |
echo ✅ SSH connection successful | |
cd ~/${{ secrets.APP_ROOT }} | |
git pull origin main | |
echo ✅ Pulling from GitHub | |
running_containers=$(docker ps -q --filter ancestor=deploy-bettermi-app) | |
if [ -n \"$running_containers\" ]; then | |
echo ✅ Stopping and removing running containers | |
docker stop $running_containers | |
docker rm $running_containers | |
fi | |
echo ✅ Building Docker Image | |
docker build -t deploy-bettermi-app . | |
echo ✅ Running Docker Container | |
docker run -d -p 127.0.0.1:3000:3000 --name deploy-bettermi-app deploy-bettermi-app | |
echo ✅ Deployed successfully | |
ENDSSH |