From 62e92756bc59d9af6946ccf989c31ceb217abacf Mon Sep 17 00:00:00 2001 From: Aritra Date: Fri, 15 Aug 2025 18:09:35 +0530 Subject: [PATCH] Feat:Added backend deployment setup --- backend/Makefile | 69 +++ backend/compose.yml | 28 ++ backend/pom.xml | 392 +++++++++--------- .../api/BarberTokenSystemApplication.java | 4 +- .../barbershop/api/service/OtpService.java | 2 +- .../src/main/resources/application-prod.yml | 1 - backend/src/main/resources/application.yml | 2 + 7 files changed, 294 insertions(+), 204 deletions(-) create mode 100644 backend/Makefile create mode 100644 backend/compose.yml diff --git a/backend/Makefile b/backend/Makefile new file mode 100644 index 0000000..be8e45b --- /dev/null +++ b/backend/Makefile @@ -0,0 +1,69 @@ +# ---- Project config ---- +APP_NAME := my-spring-app +JAR_FILE := target/$(APP_NAME).jar +PORT := 8080 +IMAGE := $(APP_NAME):latest + +MVN?=mvn + +# ---- Default target ---- +.PHONY: help +help: + @echo "Usage:" + @echo " make build - Clean and build the project (fast build)" + @echo " make clean - Remove build artifacts" + @echo " make test - Run unit tests" + @echo " make run - Run the app from the built jar" + @echo " make dev - Run the app via spring-boot:run (auto-reload if configured)" + @echo " make package - Package jar with maven wrapper" + @echo " build-image - Building image based on oci standard" + + +# ---- Build & test ---- +.PHONY: build +build: + ${MVN} -q -DskipTests package + +.PHONY: clean +clean: + ${MVN} -q clean + +.PHONY: test +test: + ${MVN} -q test + +.PHONY: package +package: + ${MVN} -q -DskipTests package + +# ---- Run locally ---- +# Ensure your pom builds a single executable JAR named $(APP_NAME).jar. +# You can set the finalName in pom.xml: +# my-spring-app +.PHONY: run +run: package + java -jar $(JAR_FILE) + +# Developer mode using spring-boot:run (no JAR required) +.PHONY: dev +dev: + ${MVN} -q spring-boot:run + +.PHONY: build-image +build-image: + ${MVN} -q spring-boot:build-image + + +# Print Maven project version +.PHONY: version +version: + ${MVN} help:evaluate -Dexpression=project.version -q -DforceStdout + +# Optional: code formatting if you use e.g. spotless or formatter plugin +.PHONY: fmt +fmt: + +.PHONY: docker-run +docker-run: + docker compose up + diff --git a/backend/compose.yml b/backend/compose.yml new file mode 100644 index 0000000..4760613 --- /dev/null +++ b/backend/compose.yml @@ -0,0 +1,28 @@ +version: "3.9" + +services: + barbar-shop: + image: aritraghorai/burbur-shop:latest + container_name: barbar-shop + # If you build locally from the Dockerfile in the repo: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + env_file: .env + environment: + SPRING_PROFILES_ACTIVE: prod + JAVA_TOOL_OPTIONS: "-XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError" + SERVER_PORT: "8080" + SPRING_APPLICATION_NAME: barbar-shop + healthcheck: + test: ["CMD", "wget", "-qO-", "http://localhost:8080/actuator/health"] # requires Spring Boot Actuator + interval: 15s + timeout: 5s + retries: 5 + start_period: 30s + read_only: true + tmpfs: + - /tmp + restart: unless-stopped diff --git a/backend/pom.xml b/backend/pom.xml index a727c71..656e03f 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -1,31 +1,30 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.5.3 - - - com.barbershop - barber-token-system - 0.0.1-SNAPSHOT - barber-token-system - Demo project for Spring Boot - - - - - - - - - - - - - + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.3 + + + com.barbershop + barber-token-system + 0.0.1-SNAPSHOT + barber-token-system + Demo project for Spring Boot + + + + + + + + + + + + + 17 dev-madhurendra @@ -33,208 +32,182 @@ - - - - - - - org.springframework.boot - spring-boot-starter-web - - - com.fasterxml.jackson.core - jackson-databind - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - - org.springframework.boot - spring-boot-starter-aop - - - - - org.springframework.boot - spring-boot-starter-mail - - - - - - org.springframework.boot - spring-boot-starter-security - - - - - io.jsonwebtoken - jjwt-api - 0.11.5 - - - - - io.jsonwebtoken - jjwt-impl - 0.11.5 - runtime - - - - - io.jsonwebtoken - jjwt-jackson - 0.11.5 - runtime - - - - - - org.postgresql - postgresql - runtime - - - - - - jakarta.validation - jakarta.validation-api - - - - - org.springframework.boot - spring-boot-starter-validation - - - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - - - org.projectlombok - lombok - 1.18.32 - provided - - - - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.8.5 - - - - org.springdoc - springdoc-openapi-starter-webmvc-ui - 2.8.5 - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - org.springframework.security - spring-security-test - test - - - - org.springframework.boot - spring-boot-starter-json - 3.0.2 - compile - - - - - org.springframework.boot - spring-boot-starter-oauth2-client - - + + + + + org.springframework.boot + spring-boot-starter-web + + + com.fasterxml.jackson.core + jackson-databind + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.springframework.boot + spring-boot-starter-mail + + + + + org.springframework.boot + spring-boot-starter-security + + + + io.jsonwebtoken + jjwt-api + 0.11.5 + + + + io.jsonwebtoken + jjwt-impl + 0.11.5 + runtime + + + + io.jsonwebtoken + jjwt-jackson + 0.11.5 + runtime + + + + + org.postgresql + postgresql + runtime + + + + + jakarta.validation + jakarta.validation-api + + + + org.springframework.boot + spring-boot-starter-validation + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.projectlombok + lombok + 1.18.32 + provided + + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.5 + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.5 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-json + 3.0.2 + compile + + + + org.springframework.boot + spring-boot-starter-oauth2-client + org.jacoco jacoco-maven-plugin 0.8.8 - com.h2database h2 test - - - - - + + + org.apache.maven.plugins maven-compiler-plugin 3.11.0 ${java.version} - - - + + + - org.apache.maven.plugins maven-surefire-plugin 3.1.2 - - - + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - org.jacoco jacoco-maven-plugin 0.8.8 - - - + + coverage @@ -243,6 +216,26 @@ + + org.springframework.boot + spring-boot-maven-plugin + + + aritraghorai/burbur-shop:${project.version} + + aritraghorai/burbur-shop:latest + + + + + + + + build-image-no-fork + + + + org.jacoco jacoco-maven-plugin @@ -265,5 +258,4 @@ - diff --git a/backend/src/main/java/com/barbershop/api/BarberTokenSystemApplication.java b/backend/src/main/java/com/barbershop/api/BarberTokenSystemApplication.java index 2b8cd64..35c18a3 100644 --- a/backend/src/main/java/com/barbershop/api/BarberTokenSystemApplication.java +++ b/backend/src/main/java/com/barbershop/api/BarberTokenSystemApplication.java @@ -8,6 +8,6 @@ @EnableScheduling public class BarberTokenSystemApplication { public static void main(String[] args) { - SpringApplication.run(BarberTokenSystemApplication.class, args); - } + SpringApplication.run(BarberTokenSystemApplication.class, args); + } } diff --git a/backend/src/main/java/com/barbershop/api/service/OtpService.java b/backend/src/main/java/com/barbershop/api/service/OtpService.java index ddc3ac5..6f6ecb0 100644 --- a/backend/src/main/java/com/barbershop/api/service/OtpService.java +++ b/backend/src/main/java/com/barbershop/api/service/OtpService.java @@ -6,4 +6,4 @@ public interface OtpService { String sendOtp(String destination); VerificationResponse verifyOtp(String destination, String otp); boolean supports(String medium); -} \ No newline at end of file +} diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index 0229bbe..ab7fbb1 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -49,7 +49,6 @@ spring: user-info-uri: https://www.googleapis.com/oauth2/v3/userinfo user-name-attribute: sub - jwt: secret: ${JWT_SECRET} expiration: ${JWT_EXPIRATION} diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index b072edc..aaedfdf 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -2,6 +2,8 @@ server: port: ${SERVER_PORT} spring: + profiles: + default: prod config: import: optional:file:.env[.properties]