Ajout d'un volume pour le fichier de configuration pour permettre la persistence des paramètres

This commit is contained in:
FyloZ 2021-05-30 16:24:16 -04:00
parent faa98ec9c4
commit 3724b3bcea
7 changed files with 28 additions and 17 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
gradle/
build/
logs/
config/
data/
dokka/
dist/

View File

@ -81,4 +81,4 @@ deploy:
script:
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker stop $DEPLOYED_CONTAINER_NAME || true && docker rm $DEPLOYED_CONTAINER_NAME || true"
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY && docker pull $CI_REGISTRY_IMAGE_BACKEND"
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker run -d -p $PORT:$PORT --name=$DEPLOYED_CONTAINER_NAME -v $DATA_VOLUME:/usr/bin/cre/data -e spring_profiles_active=$SPRING_PROFILES $CI_REGISTRY_IMAGE_BACKEND"
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker run -d -p $PORT:$PORT --name=$DEPLOYED_CONTAINER_NAME -v $DATA_VOLUME:/usr/bin/cre/data -v $CONFIG_VOLUME:/usr/bin/cre/config -e spring_profiles_active=$SPRING_PROFILES $CI_REGISTRY_IMAGE_BACKEND"

View File

@ -17,5 +17,6 @@ ENV spring_datasource_username=root
ENV spring_datasource_password=pass
VOLUME /usr/bin/cre/data
VOLUME /usr/bin/cre/config
ENTRYPOINT ["java", "-jar", "ColorRecipesExplorer.jar"]

View File

@ -1,7 +1,9 @@
package dev.fyloz.colorrecipesexplorer.config
import dev.fyloz.colorrecipesexplorer.config.properties.CreProperties
import dev.fyloz.colorrecipesexplorer.model.ConfigurationType
import dev.fyloz.colorrecipesexplorer.model.configuration
import dev.fyloz.colorrecipesexplorer.service.files.create
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.io.File
@ -10,19 +12,21 @@ import java.io.FileOutputStream
import java.time.LocalDateTime
import java.util.*
const val CONFIGURATION_FILE_PATH = "config.properties"
const val CONFIGURATION_FILE_COMMENT = "---Color Recipes Explorer configuration---"
@Configuration
class ConfigurationsInitializer {
class ConfigurationsInitializer(
private val creProperties: CreProperties
) {
@Bean
fun fileConfiguration() = FileConfiguration()
fun fileConfiguration() = FileConfiguration("${creProperties.configDirectory}/$CONFIGURATION_FILE_PATH")
}
const val FILE_CONFIGURATION_PATH = "config.properties"
const val FILE_CONFIGURATION_COMMENT = "---Color Recipes Explorer configuration---"
class FileConfiguration {
class FileConfiguration(private val configFilePath: String) {
val properties = Properties().apply {
with(File(FILE_CONFIGURATION_PATH)) {
if (!this.exists()) this.createNewFile()
with(File(configFilePath)) {
if (!this.exists()) this.create()
FileInputStream(this).use {
this@apply.load(it)
}
@ -45,8 +49,8 @@ class FileConfiguration {
}
fun save() {
FileOutputStream(FILE_CONFIGURATION_PATH).use {
properties.store(it, FILE_CONFIGURATION_COMMENT)
FileOutputStream(configFilePath).use {
properties.store(it, CONFIGURATION_FILE_COMMENT)
}
}

View File

@ -2,9 +2,14 @@ package dev.fyloz.colorrecipesexplorer.config.properties
import org.springframework.boot.context.properties.ConfigurationProperties
const val DEFAULT_DATA_DIRECTORY = "data"
const val DEFAULT_CONFIG_DIRECTORY = "config"
const val DEFAULT_DEPLOYMENT_URL = "http://localhost"
@ConfigurationProperties(prefix = "cre.server")
class CreProperties {
var workingDirectory: String = "data"
var deploymentUrl: String = "http://localhost"
var dataDirectory: String = DEFAULT_DATA_DIRECTORY
var configDirectory: String = DEFAULT_CONFIG_DIRECTORY
var deploymentUrl: String = DEFAULT_DEPLOYMENT_URL
var cacheGeneratedFiles: Boolean = false
}

View File

@ -100,7 +100,7 @@ class FileServiceImpl(
.firstOrNull { this.contains(it) }
?.let { throw InvalidFilePathException(this, it) }
return FilePath("${creProperties.workingDirectory}/$this")
return FilePath("${creProperties.dataDirectory}/$this")
}
private fun prepareWrite(path: String, overwrite: Boolean, op: File.() -> Unit) {

View File

@ -14,7 +14,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue
private val creProperties = CreProperties().apply {
workingDirectory = "data"
dataDirectory = "data"
deploymentUrl = "http://localhost"
}
private const val mockFilePath = "existingFile"
@ -31,7 +31,7 @@ private class FileServiceTestContext {
every { isFile } returns true
every { toPath() } returns mockFilePathPath
}
val mockFileFullPath = spyk(FilePath("${creProperties.workingDirectory}/$mockFilePath")) {
val mockFileFullPath = spyk(FilePath("${creProperties.dataDirectory}/$mockFilePath")) {
every { file } returns mockFile
with(fileService) {
@ -266,7 +266,7 @@ class FileServiceTest {
with(fileService) {
val fullFilePath = mockFilePath.fullPath()
assertEquals("${creProperties.workingDirectory}/$mockFilePath", fullFilePath.path)
assertEquals("${creProperties.dataDirectory}/$mockFilePath", fullFilePath.path)
}
}
}