Skip to content

Commit

Permalink
Merge pull request #13 from AntonBabychP1T/order-feature
Browse files Browse the repository at this point in the history
Add docker to project
  • Loading branch information
AntonBabychP1T authored Dec 21, 2023
2 parents f93d251 + 5454d9b commit 1298bb9
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MYSQL_USER=admin123
MYSQL_PASSWORD=password
MYSQL_DATABASE=book_store
MYSQL_ROOT_PASSWORD=password
MYSQL_LOCAL_PORT=3307
MYSQL_DOCKER_PORT=3306

SPRING_LOCAL_PORT=8088
SPRING_DOCKER_PORT=8080
DEBUG_PORT=5005

JWT_EXPIRATION_TIME=5000000
JWT_SECRET=p1tbookstoreappsomerandomsymholstokey1231488p1t
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Builder stage
FROM openjdk:17-jdk-alpine as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

# Final stage
FROM openjdk:17-jdk-alpine
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
EXPOSE 8080
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.8"

services:
mysqldb:
image: mysql
restart: unless-stopped
env_file: ./.env
ports:
- $MYSQL_LOCAL_PORT:$MYSQL_DOCKER_PORT
environment:
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: $MYSQL_DATABASE
MYSQL_USER: $MYSQL_USER
MYSQL_PASSWORD: $MYSQL_PASSWORD

app:
depends_on:
- mysqldb
restart: on-failure
image: book-store-app
build: .
env_file: ./.env
ports:
- $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT
- $DEBUG_PORT:$DEBUG_PORT
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:3306/$MYSQL_DATABASE?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC",
"spring.datasource.username" : "$MYSQL_USER",
"spring.datasource.password" : "$MYSQL_PASSWORD",
"spring.datasource.driver-class-name" : "com.mysql.cj.jdbc.Driver",
"spring.jpa.hibernate.ddl-aut" : "validate",
"spring.jpa.show-sql" : "true",
"jwt.expiration" : "$JWT_EXPIRATION_TIME",
"jwt_secret" : "$JWT_SECRET"
}'
JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BookStoreAppApplication {
public class Application {

public static void main(String[] args) {
SpringApplication.run(BookStoreAppApplication.class, args);
SpringApplication.run(Application.class, args);
}

}
10 changes: 7 additions & 3 deletions src/main/java/store/bookstoreapp/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand Down Expand Up @@ -36,12 +35,17 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
auth -> auth
.requestMatchers("api/auth/**", "api/error", "api/swagger-ui/**")
.requestMatchers(
"/api/auth/**",
"/api/error",
"/swagger-ui/**",
"/v3/api-docs/**",
"/swagger-resources/**"
)
.permitAll()
.anyRequest()
.authenticated()
)
.httpBasic(Customizer.withDefaults())
.sessionManagement(
session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(
Expand Down
6 changes: 0 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
spring.datasource.url=jdbc:mysql://localhost:3306/book_store
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true

jwt.expiration=1000000
jwt.secret=p1tbookstoreappsomerandomsymholstokey1231488p1t


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
databaseChangeLog:
- changeSet:
id: 1-add-shopping-cart-to-default-user
author: antonbabych
changes:
- insert:
tableName: shopping_cards
columns:
- column:
name: user_id
valueNumeric: 1
- column:
name: is_deleted
value: 0
- changeSet:
id: 2-add-shopping-cart-to-default-admin
author: antonbabych
changes:
- insert:
tableName: shopping_cards
columns:
- column:
name: user_id
valueNumeric: 2
- column:
name: is_deleted
value: 0
4 changes: 3 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ databaseChangeLog:
- include:
file: db/changelog/changes/12-create-order-table.yaml
- include:
file: db/changelog/changes/13-create-order-item-table.yaml
file: db/changelog/changes/13-create-order-item-table.yaml
- include:
file: db/changelog/changes/14-set-shopping-cart-to-existing-user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class BookStoreAppApplicationTests {

@Test
void contextLoads() {
void contextLoads(){
}

}

0 comments on commit 1298bb9

Please sign in to comment.