From dc5993718064abe16495053fea9b58de61b48733 Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Fri, 6 Sep 2024 21:08:49 +0200 Subject: [PATCH] feat: changed Dockerfile, docker-compose.yml --- .github/workflows/deploy.yml | 49 +++++++++++++++--------------------- Dockerfile | 23 +++-------------- 2 files changed, 23 insertions(+), 49 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 70b1c12..5f11930 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,43 +1,34 @@ -name: Deploy to Debian Server +name: Deploy Vaadin App on: push: branches: - - main + - main # Adjust this to your deployment branch jobs: deploy: runs-on: ubuntu-latest steps: - - name: Checkout the code - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Build JAR + run: ./mvnw clean package -DskipTests - - name: Build Docker image + - name: Upload JAR to server + run: scp -i ${{ secrets.SSH_KEY }} target/munera-1.0-SNAPSHOT.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera + + - name: Upload Dockerfile to server + run: scp -i ${{ secrets.SSH_KEY }} Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera + + - name: Upload docker-compose.yml to server + run: scp -i ${{ secrets.SSH_KEY }} docker-compose.yml ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera + + - name: Deploy on server run: | - docker build -t vaadin-app . - - - name: Set up SSH - uses: webfactory/ssh-agent@v0.5.3 - with: - ssh-private-key: ${{ secrets.SSH_KEY }} - - - name: Deploy Docker Compose and Dockerfile - run: | - scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/ - - - name: Deploy Docker image and run containers - run: | - ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' + ssh -i ${{ secrets.SSH_KEY }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' cd /home/${{ secrets.SSH_USER }}/munera - docker-compose down --remove-orphans || true - docker-compose up -d --build - EOF - env: - DB_ADDRESS: ${{ secrets.DB_ADDRESS }} - DB_USER: ${{ secrets.DB_USER }} - DB_PASSWORD: ${{ secrets.DB_PASSWORD }} - DB_NAME: ${{ secrets.DB_NAME }} + docker-compose down + docker-compose up --build -d + EOF \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b437d85..b2a5e7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,10 @@ -# Use a Maven image with OpenJDK -FROM maven:3.9.4-eclipse-temurin-21-alpine AS build - -# Install Node.js (for Vaadin frontend tasks) -RUN apk add --no-cache nodejs npm +FROM openjdk:21-jdk-slim # Set the working directory WORKDIR /app -# Copy the Maven POM file and source code -COPY pom.xml ./ -COPY src ./src - -# Package the application -RUN mvn clean package -DskipTests - -# Use a JDK image to run the JAR -FROM eclipse-temurin:21-jdk-alpine - -# Set the working directory -WORKDIR /app - -# Copy the JAR file from the build stage -COPY --from=build /app/target/munera-1.0-SNAPSHOT.jar ./munera-1.0-SNAPSHOT.jar +# Copy the JAR file into the container +COPY munera-1.0-SNAPSHOT.jar /app/munera-1.0-SNAPSHOT.jar # Expose the port the app runs on EXPOSE 8080