diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 71c48f4..10bda62 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -9,10 +9,21 @@ + + + + + + + + + + diff --git a/.idea/copilotDiffState.xml b/.idea/copilotDiffState.xml new file mode 100644 index 0000000..403e318 --- /dev/null +++ b/.idea/copilotDiffState.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..a1b86aa --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,65 @@ +# How to run container + +### Build +In the root directory of project there is `Dockerfile` in which image is defined. +
Build the image: +```bash +docker build -t listhub:1.0 . +``` +Then after building the image you can run it. You will need to define some environment variables. +```bash +docker run -d \ +--name listhub_backend \ +-p 8080:8080 \ +-e JWT_SECRET= \ +-e DB_URL=jdbc:postgresql://db:5432/postgres \ +-e DB_USER=postgres \ +-e DB_PASS=postgres \ +listhub_backend:1.0 +``` + +or you can use compose file with .env file + +```text +// .env +JWT_SECRET= + +DB_URL=jdbc:postgresql://db:5432/postgres +DB_USER=listhub +DB_PASS=postgres +``` + +```yaml +# docker-compose.yaml +services: + db: + image: postgres:14 + restart: unless-stopped + environment: + POSTGRES_DB: listhub + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + listhub_backend: + build: . + restart: unless-stopped + depends_on: + - db + environment: + DB_URL: jdbc:postgresql://db:5432/listhub + DB_USER: postgres + DB_PASS: postgres + JWT_SECRET: awdpokawodjawoidjawidjoij120391829d3j8a0jd8s9dawd + ports: + - "8080:8080" + volumes: + - listhub_data:/app + +volumes: + postgres_data: + listhub_data: +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..970cda2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM maven:3-amazoncorretto-21-alpine AS builder +WORKDIR /workspace + +COPY pom.xml ./ +COPY mvnw ./ +COPY .mvn .mvn + +RUN mvn -B -DskipTests dependency:go-offline + +COPY src ./src +RUN mvn -B -DskipTests package + +FROM amazoncorretto:21-alpine AS runtime +WORKDIR /app + +COPY --from=builder /workspace/target/*.jar /app/app.jar + +ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Djava.security.egd=file:/dev/./urandom" + +EXPOSE 8080 + +ENTRYPOINT ["sh", "-c", "exec java $JAVA_OPTS -jar /app/app.jar"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5d13b0e --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +services: + db: + image: postgres + restart: unless-stopped + environment: + POSTGRES_DB: listhub + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + + listhub_backend: + build: . + restart: unless-stopped + depends_on: + - db + environment: + DB_URL: jdbc:postgresql://db:5432/listhub + DB_USER: postgres + DB_PASS: postgres + JWT_SECRET: awdpokawodjawoidjawidjoij120391829d3j8a0jd8s9dawd + ports: + - "8080:8080" + volumes: + - listhub_data:/app + +volumes: + postgres_data: + listhub_data: \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d94143..b547515 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ - 25 + 21 @@ -70,7 +70,8 @@ org.projectlombok lombok - provided + 1.18.30 + compile org.springframework.boot @@ -120,6 +121,23 @@ org.springframework.boot spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${java.version} + ${java.version} + + + org.projectlombok + lombok + 1.18.30 + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/src/main/java/_11/asktpk/artisanconnectbackend/ArtisanConnectBackendApplication.java b/src/main/java/_11/asktpk/artisanconnectbackend/ArtisanConnectBackendApplication.java index 7be767e..ce783a5 100644 --- a/src/main/java/_11/asktpk/artisanconnectbackend/ArtisanConnectBackendApplication.java +++ b/src/main/java/_11/asktpk/artisanconnectbackend/ArtisanConnectBackendApplication.java @@ -14,7 +14,7 @@ public class ArtisanConnectBackendApplication { this.environment = environment; } - static void main(String[] args) { + public static void main(String[] args) { SpringApplication.run(ArtisanConnectBackendApplication.class, args); }