-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Set up test, dev, and production environments
- Loading branch information
Showing
19 changed files
with
273 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
/build/ | ||
|
||
# Etc | ||
/.env | ||
/test | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
pluginManagement { | ||
plugins { | ||
kotlin("jvm") version "1.9.21" | ||
} | ||
} | ||
plugins { | ||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" | ||
} | ||
rootProject.name = "backend" |
22 changes: 22 additions & 0 deletions
22
src/dev/java/com/sellbycar/marketplace/DevelopmentLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.sellbycar.marketplace; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.File; | ||
|
||
@Slf4j | ||
public class DevelopmentLauncher { | ||
|
||
public static void main(String[] args) { | ||
checkDocker(); | ||
MarketplaceApplication.main(args); | ||
} | ||
|
||
private static void checkDocker() { | ||
File dockerSocket = new File("/var/run/docker.sock"); | ||
if (!dockerSocket.exists()) { | ||
log.error("Install and run Docker to boot the development environment."); | ||
Runtime.getRuntime().exit(1); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/dev/java/com/sellbycar/marketplace/config/DatabaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.sellbycar.marketplace.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
public class DatabaseConfig { | ||
|
||
@SuppressWarnings({"rawtypes"}) | ||
private final PostgreSQLContainer<?> container = new PostgreSQLContainer("postgres:latest") | ||
.withUsername("development") | ||
.withPassword("development") | ||
.withDatabaseName("development"); | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
container.start(); | ||
DriverManagerDataSource dataSource = new DriverManagerDataSource(); | ||
dataSource.setUrl(container.getJdbcUrl()); | ||
dataSource.setUsername(container.getUsername()); | ||
dataSource.setPassword(container.getPassword()); | ||
return dataSource; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/dev/java/com/sellbycar/marketplace/config/MailConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sellbycar.marketplace.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
import java.util.Properties; | ||
|
||
@Configuration | ||
public class MailConfig { | ||
|
||
@SuppressWarnings({"resource"}) | ||
private final GenericContainer<?> container = new GenericContainer<>("oryd/mailslurper:latest-smtps") | ||
.withExposedPorts(1025); | ||
|
||
@Bean | ||
public JavaMailSender javaMailSender() { | ||
container.start(); | ||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); | ||
mailSender.setHost(container.getHost()); | ||
mailSender.setPort(container.getMappedPort(1025)); | ||
Properties properties = mailSender.getJavaMailProperties(); | ||
properties.put("mail.smtp.auth", "false"); | ||
properties.put("mail.smtp.starttls.enable", "false"); | ||
return mailSender; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Jwt | ||
jwt.secret.access=xEyI5DO1025mQmmyHuKefeZ/Fm4q5p7oXCIRa2D3eioxBjJB4F4p3ea88PRpXj3jx9q6sdoeAJfOfyFXtS6/MQ== | ||
jwt.secret.refresh=x4zh8N0eX0T5GHORFFuuU2hC0gdBrFrPE15DpCBoznkNE55kqUK1N6m0x3gvg5bgqecAoWn0rOpYJN+md3owXQ== | ||
|
||
# Log | ||
logging.level.org.springframework.web=INFO | ||
spring.output.ansi.enabled=always | ||
|
||
spring.mail.username= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/resources/META-INF/additional-spring-configuration-metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"properties": [ | ||
{ | ||
"name": "server.url", | ||
"type": "java.lang.String", | ||
"description": "URL of the server." | ||
}, | ||
{ | ||
"name": "jwt.secret.access.expirationMs", | ||
"type": "java.lang.Long", | ||
"description": "JWT secret access expiration in milliseconds." | ||
}, | ||
{ | ||
"name": "jwt.secret.refresh.expirationMs", | ||
"type": "java.lang.Long", | ||
"description": "JWT secret refresh expiration in milliseconds." | ||
}, | ||
{ | ||
"name": "jwt.secret.access", | ||
"type": "java.lang.String", | ||
"description": "JWT secret access." | ||
}, | ||
{ | ||
"name": "jwt.secret.refresh", | ||
"type": "java.lang.String", | ||
"description": "JWT secret refresh." | ||
}, | ||
{ | ||
"name": "server.frontend.host", | ||
"type": "java.lang.String", | ||
"description": "Frontend server host." | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Database | ||
spring.datasource.url=${DB_SOURCE} | ||
spring.datasource.username=${DB_USER} | ||
spring.datasource.password=${DB_PASSWORD} | ||
|
||
spring.mail.host=${EMAIL_HOST} | ||
spring.mail.port=587 | ||
spring.mail.username=${YOUR_EMAIL} | ||
spring.mail.password=${EMAIL_PASSWORD} | ||
spring.mail.protocol=smtp | ||
spring.mail.properties.mail.smtp.auth=true | ||
spring.mail.properties.mail.smtp.starttls.enable=true | ||
|
||
# Server | ||
server.url=https://api.etachka-marketplace.space | ||
server.description=REST API eTachka Marketplace | ||
server.frontend.host=https://etachka-marketplace.space | ||
|
||
# Jwt | ||
jwt.secret.access=${JWT_TOKEN_SECRET_ACCESS} | ||
jwt.secret.refresh=${JWT_TOKEN_SECRET_REFRESH} | ||
|
||
# Log | ||
logging.level.org.springframework.web=INFO | ||
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n | ||
logging.file.name=logs/LogFile.log | ||
|
||
# Sentry | ||
sentry.dsn=${SENTRY_DSN} | ||
sentry.traces-sample-rate=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,25 @@ | ||
# Database settings | ||
# Database | ||
spring.datasource.driver-class-name=org.postgresql.Driver | ||
spring.datasource.url=${DB_SOURCE} | ||
spring.datasource.username=${DB_USER:root} | ||
spring.datasource.password=${DB_PASSWORD:root} | ||
spring.jpa.database=postgresql | ||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.show-sql=true | ||
spring.jpa.hibernate.ddl-auto=validate | ||
|
||
# Migrations | ||
spring.flyway.baselineOnMigrate=true | ||
|
||
#Swagger Settings | ||
# Swagger | ||
springdoc.swagger-ui.use-root-path=true | ||
springdoc.paths-to-match=/**/v1/**, /api/** | ||
|
||
# Front source | ||
front.host=${FRONT_HOST} | ||
|
||
#HTTPS | ||
# Server | ||
server.ssl.enabled=false | ||
server.port=${PORT:8080} | ||
server.url=http://localhost:${PORT:8080} | ||
server.description= | ||
server.frontend.host=localhost | ||
|
||
# Mail sender settings | ||
spring.mail.host=${EMAIL_HOST} | ||
spring.mail.port=587 | ||
spring.mail.username=${YOUR_EMAIL} | ||
spring.mail.password=${EMAIL_PASSWORD} | ||
spring.mail.protocol=smtp | ||
spring.mail.properties.mail.smtp.auth=true | ||
spring.mail.properties.mail.smtp.starttls.enable=true | ||
|
||
# Jwt Settings | ||
jwt.secret.access.expirationMs=9000000 | ||
jwt.secret.refresh.expirationMs=540000000 | ||
jwt.secret.access=${JWT_TOKEN_SECRET_ACCESS} | ||
jwt.secret.refresh=${JWT_TOKEN_SECRET_REFRESH} | ||
|
||
# Image settings | ||
# Servlet | ||
spring.servlet.multipart.max-file-size=10MB | ||
spring.servlet.multipart.max-request-size=10MB | ||
|
||
# log pattern | ||
logging.level.org.springframework.web=INFO | ||
logging.pattern.file= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" | ||
logging.file.name=logs/LogFile.log | ||
spring.output.ansi.enabled=detect | ||
|
||
# Sentry | ||
sentry.dsn=${SENTRY_DSN:} | ||
sentry.traces-sample-rate=1.0 | ||
# JWT | ||
jwt.secret.access.expirationMs=9000000 | ||
jwt.secret.refresh.expirationMs=540000000 |
40 changes: 40 additions & 0 deletions
40
src/test/java/com/sellbycar/marketplace/MarketplaceApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.sellbycar.marketplace; | ||
|
||
import com.sellbycar.marketplace.util.ContainerUtil; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
@SpringBootTest | ||
@Testcontainers | ||
class MarketplaceApplicationTest { | ||
|
||
@Container | ||
public static PostgreSQLContainer<?> postgres = ContainerUtil.createPostgres(); | ||
@Container | ||
public static GenericContainer<?> mailslurper = ContainerUtil.createMailslurper(); | ||
|
||
@DynamicPropertySource | ||
static void configureProperties(DynamicPropertyRegistry registry) { | ||
// Database | ||
registry.add("spring.datasource.url", postgres::getJdbcUrl); | ||
registry.add("spring.datasource.username", postgres::getUsername); | ||
registry.add("spring.datasource.password", postgres::getPassword); | ||
registry.add("spring.mail.host", mailslurper::getHost); | ||
registry.add("spring.mail.port", () -> mailslurper.getMappedPort(1025)); | ||
registry.add("spring.mail.username", () -> ""); | ||
registry.add("spring.mail.protocol", () -> "smtp"); | ||
registry.add("spring.mail.smtp.auth", () -> false); | ||
registry.add("spring.mail.smtp.starttls.enable", () -> false); | ||
} | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
src/test/java/com/sellbycar/marketplace/MarketplaceApplicationTests.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.