Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: ProjectGraph are now completely stored in DB #258

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/helm-chart/src/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ mongodb:
# MANDATORY: enable this "experimental" feature to create a secret for service binding
enabled: true

initdbScripts:
grant-role-to-server.js: |
use server
db.grantRolesToUser(
"server",
[
{ role: "dbAdmin", db: "server" }
],
{ w: "majority", wtimeout: 5000 }
);

## Embedded NGINX configuration (Bitnami Helm Chart)
nginx:
# If `enabled`, Bitnami's chart is installed.
Expand Down
7 changes: 6 additions & 1 deletion apps/server/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"build-native-sources": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": ["build", "-Dquarkus.package.type=native-sources"]
"task": [
"build",
"-Dquarkus.package.jar.enabled=false",
"-Dquarkus.native.enabled=true",
"-Dquarkus.native.sources-only=true"
]
},
"outputs": ["{projectRoot}/build/native-sources"]
},
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ quarkus:
http:
port: 8080
root-path: "/nx-cloud"
liquibase-mongodb:
change-log: db/change-log.yaml
migrate-at-start: true
mongodb:
database: nx-cloud-ce
smallrye-openapi:
Expand Down
2 changes: 1 addition & 1 deletion libs/server/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ tasks.withType<Test> {

configure<JacocoTaskExtension> {
excludeClassLoaders = listOf("*QuarkusClassLoader")
setDestinationFile(layout.buildDirectory.file("jacoco-quarkus.exec").get().asFile)
destinationFile = layout.buildDirectory.file("jacoco-quarkus.exec").get().asFile
}

tasks.jacocoTestReport {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
package org.nxcloudce.server.domain.run.model

/**
* Some type definitions can be found here:
* https://github.com/nrwl/nx/blob/master/packages/nx/src/config/project-graph.ts
* https://github.com/nrwl/nx/blob/master/packages/nx/src/config/workspace-json-project-json.ts
*/
data class ProjectGraph(
val nodes: Map<String, Project>?,
val dependencies: Map<String, List<Dependency>>?,
val nodes: Map<String, Project>,
val dependencies: Map<String, List<Dependency>>,
) {
data class Project(
val type: String,
val name: String,
val data: Data,
val data: ProjectConfiguration,
) {
data class Data(
data class ProjectConfiguration(
val root: String,
val sourceRoot: String?,
val metadata: Map<String, Any>?,
val targets: Map<String, Target>,
val targets: Map<String, TargetConfiguration>?,
val metadata: ProjectMetadata?,
) {
data class Target(
data class TargetConfiguration(
val executor: String?,
val command: String?,
val outputs: Collection<String>?,
val dependsOn: Collection<String>?,
val options: Map<String, Any>?,
val configurations: Any?,
val parallelism: Boolean?,
val inputs: Collection<Any>?,
val outputs: Collection<String>?,
val options: Any?,
val configurations: Map<String, Any>?,
val defaultConfiguration: String?,
val cache: Boolean?,
val parallelism: Boolean?,
val syncGenerators: Collection<String>?,
// missing `metadata?`
)

data class ProjectMetadata(
val description: String?,
val technologies: Collection<String>?,
val targetGroups: Map<String, Collection<String>>?,
// missing `owners?`
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,32 @@ class RunTest {
type = "application",
name = "apps/server",
data =
ProjectGraph.Project.Data(
ProjectGraph.Project.ProjectConfiguration(
root = "root",
sourceRoot = "root",
metadata = emptyMap(),
targets = emptyMap(),
metadata =
ProjectGraph.Project.ProjectConfiguration.ProjectMetadata(
description = null,
technologies = null,
targetGroups = null,
),
targets =
mapOf(
"apps/server" to
ProjectGraph.Project.ProjectConfiguration.TargetConfiguration(
executor = "nx",
command = "nx build apps/server",
outputs = null,
dependsOn = null,
inputs = null,
options = null,
configurations = null,
defaultConfiguration = null,
cache = null,
parallelism = null,
syncGenerators = null,
),
),
),
),
),
Expand Down
5 changes: 5 additions & 0 deletions libs/server/gateway/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ val javaVersion: String by project
val quarkusPlatformGroupId: String by project
val quarkusPlatformArtifactId: String by project
val quarkusPlatformVersion: String by project
val jacksonDatatypeJsr310Version: String by project
val ktlintVersion: String by project
val atriumVersion: String by project
val mockkVersion: String by project
val quarkusMockkVersion: String by project

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")

implementation(enforcedPlatform("$quarkusPlatformGroupId:$quarkusPlatformArtifactId:$quarkusPlatformVersion"))
implementation("io.quarkus:quarkus-kotlin")
implementation("io.quarkus:quarkus-mongodb-panache-kotlin")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonDatatypeJsr310Version")

implementation(project(":libs:server:domain"))
implementation(project(":libs:server:persistence"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.nxcloudce.server.technical.producer
package org.nxcloudce.server.gateway.infrastructure

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.nxcloudce.server.gateway.persistence

import com.fasterxml.jackson.databind.ObjectMapper
import org.bson.types.ObjectId
import org.nxcloudce.server.domain.run.model.*
import org.nxcloudce.server.domain.run.usecase.EndRunRequest
import org.nxcloudce.server.domain.workspace.model.WorkspaceId
import org.nxcloudce.server.persistence.entity.RunEntity

fun RunEntity.toDomain(): Run =
fun RunEntity.toDomain(objectMapper: ObjectMapper): Run =
Run {
id = RunId([email protected]())
workspaceId = WorkspaceId([email protected]())
Expand Down Expand Up @@ -48,39 +49,36 @@ fun RunEntity.toDomain(): Run =
projectGraph =
[email protected]?.let { projectGraph ->
ProjectGraph(
nodes = emptyMap(),
// projectGraph.nodes.let {
// it.mapValues { (_, node) ->
// ProjectGraph.Project(
// type = node.type,
// name = node.name,
// data =
// ProjectGraph.Project.Data(
// root = node.data.root,
// sourceRoot = node.data.sourceRoot,
// metadata = null,
// targets = emptyMap(),
// // TODO: can't map those two fields for now
// // https://github.com/clementguillot/nx-cloud-ce/issues/118
// // metadata = node.data.metadata,
// // targets =
// // node.data.targets.mapValues { (_, target) ->
// // ProjectGraph.Project.Data.Target(
// // executor = target.executor,
// // dependsOn = target.dependsOn,
// // options = target.options,
// // configurations = target.configurations,
// // parallelism = target.parallelism,
// // inputs = target.inputs,
// // outputs = target.outputs,
// // defaultConfiguration = target.defaultConfiguration,
// // cache = target.cache,
// // )
// // },
// ),
// )
// }
// },
projectGraph.nodes.let {
it.mapValues { (_, node) ->
ProjectGraph.Project(
type = node.type,
name = node.name,
data =
ProjectGraph.Project.ProjectConfiguration(
root = node.data.root,
sourceRoot = node.data.sourceRoot,
targets =
node.data.targets?.let { target ->
target.mapValues { (_, serializedTarget) ->
objectMapper.readValue(
serializedTarget,
ProjectGraph.Project.ProjectConfiguration.TargetConfiguration::class.java,
)
}
},
metadata =
node.data.metadata?.let { metadata ->
ProjectGraph.Project.ProjectConfiguration.ProjectMetadata(
description = metadata.description,
technologies = metadata.technologies,
targetGroups = metadata.targetGroups,
)
},
),
)
}
},
dependencies =
projectGraph.dependencies.let {
it.mapValues { (_, dependencies) ->
Expand All @@ -102,6 +100,7 @@ fun RunEntity.toDomain(): Run =
fun EndRunRequest.Run.toEntity(
status: RunStatus,
workspaceId: WorkspaceId,
objectMapper: ObjectMapper,
): RunEntity =
RunEntity(
id = null,
Expand Down Expand Up @@ -145,34 +144,33 @@ fun EndRunRequest.Run.toEntity(
projectGraph?.let { projectGraph ->
RunEntity.ProjectGraph(
nodes =
projectGraph.nodes!!.mapValues { (_, node) ->
projectGraph.nodes.mapValues { (_, node) ->
RunEntity.ProjectGraph.Project(
type = node.type,
name = node.name,
data =
RunEntity.ProjectGraph.Project.Data(
RunEntity.ProjectGraph.Project.ProjectConfiguration(
root = node.data.root,
sourceRoot = node.data.sourceRoot,
// metadata = node.data.metadata,
// targets =
// node.data.targets.mapValues { (_, target) ->
// RunEntity.ProjectGraph.Project.Data.Target(
// executor = target.executor,
// dependsOn = target.dependsOn,
// options = target.options,
// configurations = target.configurations,
// parallelism = target.parallelism,
// inputs = target.inputs,
// outputs = target.outputs,
// defaultConfiguration = target.defaultConfiguration,
// cache = target.cache,
// )
// },
targets =
node.data.targets?.let {
it.mapValues { (_, target) ->
objectMapper.writeValueAsString(target)
}
},
metadata =
node.data.metadata?.let {
RunEntity.ProjectGraph.Project.ProjectConfiguration.Metadata(
description = it.description,
technologies = it.technologies,
targetGroups = it.targetGroups,
)
},
),
)
},
dependencies =
projectGraph.dependencies!!.mapValues { (_, dependencies) ->
projectGraph.dependencies.mapValues { (_, dependencies) ->
dependencies.map { dependency ->
RunEntity.ProjectGraph.Dependency(
source = dependency.source,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.nxcloudce.server.gateway.persistence

import com.fasterxml.jackson.databind.ObjectMapper
import io.smallrye.mutiny.coroutines.asFlow
import io.smallrye.mutiny.coroutines.awaitSuspending
import jakarta.enterprise.context.ApplicationScoped
Expand All @@ -17,19 +18,20 @@ import java.time.LocalDateTime
@ApplicationScoped
class RunRepositoryImpl(
private val runPanacheRepository: RunPanacheRepository,
private val objectMapper: ObjectMapper,
) : RunRepository {
override suspend fun create(
run: EndRunRequest.Run,
status: RunStatus,
workspaceId: WorkspaceId,
): Run {
val entity = run.toEntity(status, workspaceId)
val entity = run.toEntity(status, workspaceId, objectMapper)

return runPanacheRepository.persist(entity).awaitSuspending().run { entity.toDomain() }
return runPanacheRepository.persist(entity).awaitSuspending().run { entity.toDomain(objectMapper) }
}

override fun findAllByCreationDateOlderThan(date: LocalDateTime): Flow<Run> =
runPanacheRepository.findAllByEndTimeLowerThan(date).asFlow().map { it.toDomain() }
runPanacheRepository.findAllByEndTimeLowerThan(date).asFlow().map { it.toDomain(objectMapper) }

override suspend fun delete(run: Run) = runPanacheRepository.deleteById(ObjectId(run.id.value)).awaitSuspending()
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,32 @@ class RunRepositoryImplTest {
type = "application",
name = "apps/server",
data =
ProjectGraph.Project.Data(
ProjectGraph.Project.ProjectConfiguration(
root = "root",
sourceRoot = "root",
metadata = emptyMap(),
targets = emptyMap(),
metadata =
ProjectGraph.Project.ProjectConfiguration.ProjectMetadata(
description = null,
technologies = null,
targetGroups = null,
),
targets =
mapOf(
"build" to
ProjectGraph.Project.ProjectConfiguration.TargetConfiguration(
executor = "@nx/angular:ng-packagr-lite",
command = null,
outputs = listOf("^build", "build"),
dependsOn = null,
inputs = listOf("production", "^production"),
options = null,
configurations = null,
defaultConfiguration = null,
cache = null,
parallelism = null,
syncGenerators = null,
),
),
),
),
),
Expand Down
1 change: 1 addition & 0 deletions libs/server/persistence/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation(enforcedPlatform("$quarkusPlatformGroupId:$quarkusPlatformArtifactId:$quarkusPlatformVersion"))
implementation("io.quarkus:quarkus-arc")
implementation("io.quarkus:quarkus-kotlin")
implementation("io.quarkus:quarkus-liquibase-mongodb")
implementation("io.quarkus:quarkus-mongodb-panache-kotlin")

testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test")
Expand Down
Loading