Skip to content

feat: fix install docker in ci #12

feat: fix install docker in ci

feat: fix install docker in ci #12

Workflow file for this run

name: 🚀 Deploy adonisjs Api to VPS
on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
env:
APP_DIR: /var/www/epitalk.api.dibodev.com
DOMAIN: epitalk.api.dibodev.com
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v4
- name: 🚀 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: 🔍 Install dependencies
run: npm install
- name: 📝 Setup Production .env File
run: cp .env.production .env
- name: 📝 Update .env with Secrets
run: |
sed -i "s|APP_KEY=.*|APP_KEY=${{ secrets.APP_KEY }}|" .env
sed -i "s|MYSQL_DATABASE=.*|MYSQL_DATABASE=${{ secrets.DATABASE_DB_NAME }}|" .env
sed -i "s|MYSQL_HOST=.*|MYSQL_HOST=${{ secrets.MYSQL_HOST }}|" .env
sed -i "s|MYSQL_PORT=.*|MYSQL_PORT=${{ secrets.MYSQL_PORT }}|" .env
sed -i "s|MYSQL_USER=.*|MYSQL_USER=${{ secrets.MYSQL_USER }}|" .env
sed -i "s|MYSQL_PASSWORD=.*|MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }}|" .env
sed -i "s|MERCURE_TOKEN=.*|MERCURE_TOKEN=${{ secrets.MERCURE_TOKEN }}|" .env
- name: 🧱 Build application
run: |
npm run build
cp .env build/.env
- name: 🐳 Copy docker-compose.yml to build folder
run: cp docker-compose.yml build/docker-compose.yml
- name: 🛁 Clean install for production
run: cd build && npm ci --production --ignore-scripts
- name: 📤 Deploy to VPS
uses: easingthemes/ssh-deploy@main
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-azrut --delete"
SOURCE: "build/"
REMOTE_HOST: ${{ secrets.SSH_HOST }}
REMOTE_USER: ${{ secrets.SSH_USERNAME }}
REMOTE_PORT: ${{ secrets.SSH_PORT }}
TARGET: ${{ env.APP_DIR }}/html
SCRIPT_BEFORE: |
if ! command -v rsync &> /dev/null
then
echo "rsync could not be found, installing..."
sudo apt-get update
sudo apt-get install -y rsync
else
echo "rsync is already installed."
fi
if ! docker --version &> /dev/null
then
echo "Docker could not be found or is not working, installing..."
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
else
echo "Docker is already installed and working."
fi
if ! docker-compose --version &> /dev/null
then
echo "docker-compose could not be found or is not working, installing..."
sudo rm -f /usr/local/bin/docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
else
echo "docker-compose is already installed and working."
fi
echo "Starting deployment..."
SCRIPT_AFTER: |
cd ${{ env.APP_DIR }}/html
echo "Restarting API with PM2..."
pm2 restart ${{ env.DOMAIN }} || pm2 start server.js --name ${{ env.DOMAIN }}
pm2 save
echo "Restarting Nginx..."
sudo systemctl restart nginx
echo "Running Migrations..."
node ace migration:run --force
echo "Running Seeders..."
node ace db:seed
echo "Deploying Mercure SSE service..."
docker-compose up -d mercure-sse
echo "Mercure SSE service deployed successfully!"
echo "Deployment completed successfully!"