2024-09-06 17:41:47 +00:00
|
|
|
name: Deploy to Debian Server
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2024-09-06 17:48:36 +00:00
|
|
|
- name: Checkout the code
|
|
|
|
uses: actions/checkout@v2
|
2024-09-06 17:41:47 +00:00
|
|
|
|
2024-09-06 17:48:36 +00:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v2
|
2024-09-06 17:41:47 +00:00
|
|
|
|
2024-09-06 17:48:36 +00:00
|
|
|
- name: Build Docker image
|
|
|
|
run: |
|
|
|
|
docker build -t vaadin-app .
|
2024-09-06 17:41:47 +00:00
|
|
|
|
2024-09-06 17:48:36 +00:00
|
|
|
- name: Set up SSH
|
|
|
|
uses: webfactory/ssh-agent@v0.5.3
|
|
|
|
with:
|
|
|
|
ssh-private-key: ${{ secrets.SSH_KEY }}
|
|
|
|
|
2024-09-06 18:30:32 +00:00
|
|
|
- name: Copy files to server
|
|
|
|
run: |
|
|
|
|
scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
|
|
|
|
scp -o StrictHostKeyChecking=no target/munera-1.0-SNAPSHOT.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
|
|
|
|
|
|
|
|
- name: Deploy using Docker Compose
|
2024-09-06 17:48:36 +00:00
|
|
|
run: |
|
|
|
|
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
|
2024-09-06 18:30:32 +00:00
|
|
|
cd /home/${{ secrets.SSH_USER }}/munera
|
|
|
|
|
|
|
|
# Stop and remove only the specific application container
|
2024-09-06 17:48:36 +00:00
|
|
|
docker stop vaadin-app || true
|
|
|
|
docker rm vaadin-app || true
|
2024-09-06 18:30:32 +00:00
|
|
|
|
|
|
|
# Build and start the containers (including the database container)
|
|
|
|
docker-compose up -d --build
|
2024-09-06 17:48:36 +00:00
|
|
|
EOF
|
|
|
|
env:
|
|
|
|
DB_ADDRESS: ${{ secrets.DB_ADDRESS }}
|
|
|
|
DB_USER: ${{ secrets.DB_USER }}
|
|
|
|
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
2024-09-06 18:30:32 +00:00
|
|
|
DB_NAME: ${{ secrets.DB_NAME }}
|