diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index bfdcfc6..70b1c12 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,22 +25,16 @@ jobs: with: ssh-private-key: ${{ secrets.SSH_KEY }} - - name: Copy Docker files to server + - name: Deploy Docker Compose and Dockerfile run: | - scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/effe/munera/ + scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/ - - name: Deploy Docker containers + - name: Deploy Docker image and run containers run: | ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' - cd /home/effe/munera - - # Stop and remove existing containers for vaadin-app only - docker-compose stop vaadin-app || true - docker-compose rm -f vaadin-app || true - - # Rebuild and restart containers using docker-compose + cd /home/${{ secrets.SSH_USER }}/munera + docker-compose down --remove-orphans || true docker-compose up -d --build - EOF env: DB_ADDRESS: ${{ secrets.DB_ADDRESS }} diff --git a/Dockerfile b/Dockerfile index 5b1cb3f..1a95a8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,17 @@ -# Use a Maven image with OpenJDK 22 to build the JAR +# Use a Maven image to build the JAR FROM maven:3.9.4-eclipse-temurin-21-alpine AS build -# Install Node.js (needed for Vaadin frontend tooling) -RUN apk add --no-cache nodejs npm - # Set the working directory WORKDIR /app -# Copy the source code into the container -COPY . . +# Copy the pom.xml and the source code +COPY pom.xml ./ +COPY src ./src -# Build the JAR file +# Package the application RUN mvn clean package -DskipTests -# Use a lightweight image with OpenJDK 22 to run the JAR +# Use an OpenJDK image to run the JAR FROM openjdk:22-jdk-slim # Set the working directory