From dae50f4e06a419fad43cc4a3421f755e0704ebcc Mon Sep 17 00:00:00 2001 From: PiCiU1221 <96005164+PiCiU1221@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:33:12 +0100 Subject: [PATCH 1/3] Fix backend pipeline --- .github/workflows/backend-deploy.yml | 102 +++++++++++++++++++++++++++ backend/Dockerfile | 12 ++-- 2 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/backend-deploy.yml diff --git a/.github/workflows/backend-deploy.yml b/.github/workflows/backend-deploy.yml new file mode 100644 index 00000000..099bbd61 --- /dev/null +++ b/.github/workflows/backend-deploy.yml @@ -0,0 +1,102 @@ +name: Deploy Backend + +on: + pull_request: + branches: + - dev + types: + - closed + paths: + - "backend/**" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build Application + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Provision JDK environment + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + cache: "maven" + + - name: Execute Maven build + working-directory: backend + run: mvn clean verify -Duser.timezone=Europe/Warsaw + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: backend-dist + path: | + backend/target/*.jar + backend/Dockerfile + retention-days: 1 + + deploy: + name: Deploy to EC2 + needs: build + runs-on: ubuntu-latest + + steps: + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: backend-dist + path: backend-dist + + - name: Transfer artifacts to target environment + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + source: "backend-dist/*" + target: "/tmp/backend-deploy" + strip_components: 1 + + - name: Orchestrate container deployment + uses: appleboy/ssh-action@v1.0.3 + env: + DB_URL: ${{ secrets.DB_URL }} + DB_USERNAME: ${{ secrets.DB_USERNAME }} + DB_PASSWORD: ${{ secrets.DB_PASSWORD }} + OPENROUTESERVICE_API_KEY: ${{ secrets.OPENROUTESERVICE_API_KEY }} + JWT_SERVICE_KEY: ${{ secrets.JWT_SERVICE_KEY }} + JWT_EXPIRATION: ${{ secrets.JWT_EXPIRATION }} + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + envs: DB_URL,DB_USERNAME,DB_PASSWORD,OPENROUTESERVICE_API_KEY,JWT_SERVICE_KEY,JWT_EXPIRATION + script: | + mkdir -p ~/BookRider/backend + mv /tmp/backend-deploy/* ~/BookRider/backend/ + cd ~/BookRider/backend + + echo "DB_URL=$DB_URL" > .env + echo "DB_USERNAME=$DB_USERNAME" >> .env + echo "DB_PASSWORD=$DB_PASSWORD" >> .env + echo "OPENROUTESERVICE_API_KEY=$OPENROUTESERVICE_API_KEY" >> .env + echo "JWT_SERVICE_KEY=$JWT_SERVICE_KEY" >> .env + echo "JWT_EXPIRATION=$JWT_EXPIRATION" >> .env + + docker stop backend-container || true + docker rm backend-container || true + docker rmi backend-image || true + docker system prune -af --volumes + + docker build -t backend-image . + docker run -d --restart unless-stopped -p 8080:8080 --env-file .env --name backend-container backend-image + + rm -rf /tmp/backend-deploy diff --git a/backend/Dockerfile b/backend/Dockerfile index af7a70d8..15deacbf 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,9 +1,4 @@ -FROM maven:3.9.4-eclipse-temurin-17 AS builder -WORKDIR /app -COPY . . -RUN mvn clean package -DskipTests - -FROM eclipse-temurin:17-jdk-jammy +FROM eclipse-temurin:17-jre-jammy ENV TZ=Europe/Warsaw RUN apt-get update && \ @@ -14,6 +9,9 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY --from=builder /app/target/*.jar app.jar + +COPY target/*.jar app.jar + EXPOSE 8080 + ENTRYPOINT ["java", "-Duser.timezone=Europe/Warsaw", "-jar", "app.jar"] From d20522f1bad40dba88356850b0d5657178ac602b Mon Sep 17 00:00:00 2001 From: PiCiU1221 <96005164+PiCiU1221@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:33:23 +0100 Subject: [PATCH 2/3] Fix frontend pipeline --- .github/workflows/web-app-deploy.yml | 85 ++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/web-app-deploy.yml diff --git a/.github/workflows/web-app-deploy.yml b/.github/workflows/web-app-deploy.yml new file mode 100644 index 00000000..4f475a6c --- /dev/null +++ b/.github/workflows/web-app-deploy.yml @@ -0,0 +1,85 @@ +name: Deploy Frontend + +on: + pull_request: + branches: + - dev + types: + - closed + paths: + - "web_app/**" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build Application + runs-on: ubuntu-latest + defaults: + run: + working-directory: web_app + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "npm" + cache-dependency-path: web_app/package-lock.json + + - name: Generate environment variables + run: echo "VITE_API_BASE_URL=${{ secrets.API_BASE_URL }}" > .env + + - name: Install dependencies + run: npm ci + + - name: Build frontend + run: npm run build + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: webapp-dist + path: web_app/dist/ + retention-days: 1 + + deploy: + name: Deploy to EC2 + runs-on: ubuntu-latest + needs: build + if: github.event.pull_request.merged == true + + steps: + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: webapp-dist + path: dist + + - name: Transfer artifacts to EC2 + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + source: "dist/" + target: "/tmp/webapp" + strip_components: 1 + + - name: Update webroot and reload NGINX + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + script: | + sudo mkdir -p /var/www/myreactapp + sudo rsync -a --delete /tmp/webapp/ /var/www/myreactapp/ + sudo chown -R www-data:www-data /var/www/myreactapp + sudo rm -rf /tmp/webapp + sudo systemctl reload nginx From 3793a84344925f833a7ba983126524dbfe5cb505 Mon Sep 17 00:00:00 2001 From: PiCiU1221 <96005164+PiCiU1221@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:33:48 +0100 Subject: [PATCH 3/3] Fix integration test runner for backend --- backend/pom.xml | 9 ++++++++- backend/src/test/resources/application.properties | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 backend/src/test/resources/application.properties diff --git a/backend/pom.xml b/backend/pom.xml index df10fe73..8009b59a 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -56,7 +56,7 @@ org.springframework.boot spring-boot-starter-data-jpa - + org.springframework.boot spring-boot-starter-jdbc @@ -121,6 +121,13 @@ org.springframework.boot spring-boot-starter-websocket + + + org.testcontainers + postgresql + 1.19.7 + test + diff --git a/backend/src/test/resources/application.properties b/backend/src/test/resources/application.properties new file mode 100644 index 00000000..1f8841d1 --- /dev/null +++ b/backend/src/test/resources/application.properties @@ -0,0 +1,9 @@ +spring.config.import= + +spring.datasource.url=jdbc:tc:postgresql:15-alpine:///testdb +spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver + +spring.datasource.username=test +spring.datasource.password=test + +spring.jpa.hibernate.ddl-auto=create-drop