35 lines
1.1 KiB
YAML
35 lines
1.1 KiB
YAML
name: Deploy to Server
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # or 'master', or your preferred branch for deployment
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest # The runner environment for this job
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4 # Action to checkout your repository code
|
|
|
|
- name: Set up SSH
|
|
uses: webfactory/ssh-agent@v0.9.0 # Action to set up SSH agent
|
|
with:
|
|
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} # Your server's SSH private key
|
|
|
|
- name: Add Server to Known Hosts
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
ssh-keyscan -H your_server_ip >> ~/.ssh/known_hosts # Replace with your server's IP
|
|
chmod 600 ~/.ssh/known_hosts
|
|
|
|
- name: Deploy via SSH
|
|
run: |
|
|
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_SERVER }} << 'EOF'
|
|
cd ~/cover-letter # Replace with your project's path on the server
|
|
git pull origin main # or your branch
|
|
docker compose down
|
|
docker compose up -d --build
|
|
EOF
|