summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile6
-rw-r--r--Dockerfile.test15
-rw-r--r--README.md54
-rw-r--r--docker-compose.yml23
-rw-r--r--pom.xml24
-rw-r--r--src/main/resources/application.properties2
-rw-r--r--src/test/resources/application-test.properties2
7 files changed, 117 insertions, 9 deletions
diff --git a/Dockerfile b/Dockerfile
index 63481f7..3381117 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,13 +1,13 @@
-# Stage 1: Build the JAR file
+# Stage 1: BUILD
FROM maven:3.8.5-openjdk-17 AS build
WORKDIR /app
COPY mvnw pom.xml ./
COPY .mvn .mvn
COPY src src
RUN chmod +x mvnw
-RUN ./mvnw clean package -Dmaven.test.skip=true
+RUN ./mvnw clean package -q -Dmaven.test.skip=true
-# Stage 2: Run the JAR file
+# Stage 2: RUN
FROM openjdk:17-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
diff --git a/Dockerfile.test b/Dockerfile.test
new file mode 100644
index 0000000..9a82cc5
--- /dev/null
+++ b/Dockerfile.test
@@ -0,0 +1,15 @@
+# Stage 1: BUILD
+FROM maven:3.8.5-openjdk-17 AS build
+WORKDIR /app
+COPY mvnw pom.xml ./
+COPY .mvn .mvn
+COPY src src
+RUN chmod +x mvnw
+RUN ./mvnw clean package -q -Dmaven.test.skip=true
+
+# Stage 2: TEST
+FROM maven:3.8.5-openjdk-17 AS test
+WORKDIR /app
+COPY --from=build /app /app
+RUN chmod +x mvnw
+CMD ["./mvnw", "test", "-P", "test", "-q"] \ No newline at end of file
diff --git a/README.md b/README.md
index ade89f4..7e170e4 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,55 @@
# Markr - Marking as a Service
-**Szymon Szukalski's Submission to the Stile Coding Challenge - July 2024** \ No newline at end of file
+**Szymon Szukalski's Submission to the Stile Coding Challenge - July 2024**
+
+## Running the Project
+
+This project uses Docker for building, testing, and running the application. Below are the instructions to incorporate
+this project into your build system using Docker.
+
+### Prerequisites
+
+- Docker (version 20.10 or later)
+- Docker Compose (version 1.29 or later)
+
+### Build
+
+To build the Docker image for the application, run the following command:
+
+```shell
+docker compose build
+```
+
+This command will build the application image using the Dockerfile defined in the project.
+
+### Test
+
+To run the tests using Docker, use the following command:
+
+```shell
+docker compose run --rm markr_tests
+```
+
+This command will build the Docker image (if not already built), start a container for testing, and run the tests. The
+--rm flag ensures that the test container is removed after the tests complete.
+
+### Run
+
+To run the application, use the following command:
+
+```shell
+docker compose up postgres markr
+```
+
+This command will start the application and its dependencies (like PostgreSQL) as defined in the docker-compose.yml
+file.
+
+### Cleanup
+
+To stop the running containers and remove them along with associated volumes, use:
+
+```shell
+docker compose down -v
+```
+
+This command will stop and remove the containers and any associated volumes. \ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 0f45dc0..cb7bc7e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -11,9 +11,11 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data
- markr_service:
- build: .
- container_name: markr_service
+ markr:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ container_name: skasio_markr
ports:
- "8080:8080"
depends_on:
@@ -23,5 +25,20 @@ services:
SPRING_DATASOURCE_USERNAME: markr_prod
SPRING_DATASOURCE_PASSWORD: CpfzDA3nR3jH9Ky4
+ markr_tests:
+ build:
+ context: .
+ dockerfile: Dockerfile.test
+ container_name: skasio_markr_tests
+ environment:
+ SPRING_DATASOURCE_URL: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
+ SPRING_DATASOURCE_USERNAME: markr_test
+ SPRING_DATASOURCE_PASSWORD: DekqFAQnRIjH2Kz1
+ SPRING_JPA_DATABASE_PLATFORM: org.hibernate.dialect.H2Dialect
+ SPRING_JPA_HIBERNATE_DDL_AUTO: update
+ SPRING_JPA_SHOW_SQL: false
+ SPRING_PROFILES_ACTIVE: test
+ command: ./mvnw test -P test -q
+
volumes:
postgres_data:
diff --git a/pom.xml b/pom.xml
index 55b3297..0422efd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,11 @@
</dependency>
<dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
@@ -73,7 +78,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <scope>runtime</scope>
+ <scope>test</scope>
</dependency>
</dependencies>
@@ -83,7 +88,22 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <showWarnings>false</showWarnings>
+ </configuration>
+ </plugin>
</plugins>
</build>
-</project>
+ <profiles>
+ <profile>
+ <id>test</id>
+ <properties>
+ <spring.profiles.active>test</spring.profiles.active>
+ </properties>
+ </profile>
+ </profiles>
+</project> \ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 3600371..e838ed8 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,4 +1,6 @@
spring.application.name=markr
+logging.level.root=warn
+logging.level.org.springframework.web=warn
# PostgreSQL Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/markr
spring.datasource.username=markr_prod
diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties
index 87666a1..3c690d8 100644
--- a/src/test/resources/application-test.properties
+++ b/src/test/resources/application-test.properties
@@ -1,3 +1,5 @@
+logging.level.root=warn
+logging.level.org.springframework.web=info
# H2 Configuration
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driver-class-name=org.h2.Driver