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

Merge the initial rabbit configuration #1

Merged
merged 3 commits into from
Mar 19, 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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
{
"name": "Aries-Backend DevContainer File for quick dev env setup",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/java:0-17",
"image": "mcr.microsoft.com/devcontainers/java:0-21",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "none",
"installGradle": "true",
"gradleVersion": "8.3",
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"dockerDashComposeVersion": "v2",
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
- name: Login to Docker Hub to push image
uses: docker/login-action@v2
with:
registry: cr.nkls.pw
username: ${{ secrets.NEXUS_USERNAME }}
password: ${{ secrets.NEXUS_PASSWORD }}
registry: oci.draco.sh
username: ${{ secrets.OCI_USERNAME }}
password: ${{ secrets.OCI_PASSWORD }}

- name: Build Docker Image and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
tags: cr.nkls.pw/aries-backend:latest-dev
tags: oci.draco.sh/aries/aries-backend:latest-dev
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'org.springframework.boot' version '3.1.0'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.jetbrains.kotlin.jvm' version '1.8.21'
id 'org.jetbrains.kotlin.plugin.spring' version '1.8.21'
id 'org.jetbrains.kotlin.plugin.jpa' version '1.8.21'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.21'
}

group = 'tech.niklas'
version = '0.0.1-alpha'
version = '0.0.10-alpha'
sourceCompatibility = '17'

configurations {
Expand All @@ -33,7 +34,15 @@ dependencies {
implementation 'me.paulschwarz:spring-dotenv:4.0.0'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-configuration-processor'
testImplementation 'com.github.dasniko:testcontainers-keycloak:3.2.0'
testImplementation 'org.springframework.amqp:spring-rabbit-test'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:rabbitmq'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:rabbitmq'
testImplementation 'org.testcontainers:postgresql'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
Expand Down
20 changes: 19 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- 'POSTGRES_PASSWORD=secret'
- 'POSTGRES_USER=myuser'
ports:
- '5433:5432'
- '5432:5432'
pgadmin:
image: dpage/pgadmin4
restart: always
Expand All @@ -17,5 +17,23 @@ services:
PGADMIN_DEFAULT_PASSWORD: Niklas12
volumes:
- pgadmin-data:/var/lib/pgadmin
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"

kafka:
image: 'bitnami/kafka:latest'
ports:
- '9092:9092'
environment:
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER

volumes:
pgadmin-data:
7 changes: 6 additions & 1 deletion docker-compose-example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

version: '2'

services:
Expand All @@ -25,5 +24,11 @@ services:
ports:
- '8089:8080'

rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"

volumes:
pgdata:
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import jakarta.persistence.*
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import org.hibernate.Hibernate

import java.io.Serial
@Entity
@Table(name = "dockeragents")
data class DockerAgent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ open class DockerService protected constructor(
@NotNull
@ManyToOne
@JoinColumn(name = "machineID")
var serviceMachine: DockerMachine
var serviceMachine: DockerMachine,


) {
override fun equals(other: Any?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tech.niklas.ariesbackend.model.dockerservice

import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
import tech.niklas.ariesbackend.model.DockerMachine
import tech.niklas.ariesbackend.model.DockerService
import tech.niklas.ariesbackend.model.types.DatabaseType
import tech.niklas.ariesbackend.model.types.ServiceType

@Entity
@DiscriminatorValue("website-service")
class WebsiteService(
serviceID: String?,
serviceName: String,
serviceType: ServiceType,
serviceMachine: DockerMachine,
serviceUrl: String
)
: DockerService(serviceID, serviceName, serviceType, serviceMachine)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package tech.niklas.ariesbackend.model.types

enum class DatabaseType(val databaseType: String) {
POSTGRESQL("postgres"),
MARIADB("mariadb")
MARIADB("mariadb"),
MONGODB("mongodb")
}
54 changes: 54 additions & 0 deletions src/main/kotlin/tech/niklas/ariesbackend/queue/RabbitMQConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package tech.niklas.ariesbackend.queue

import org.springframework.amqp.core.Queue
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory
import org.springframework.amqp.rabbit.connection.ConnectionFactory
import org.springframework.amqp.rabbit.core.RabbitTemplate
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter
import org.springframework.amqp.support.converter.MessageConverter
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary

@Configuration
class RabbitMQConfig {
@Value("\${spring.rabbitmq.host}")
private lateinit var host: String

@Value("\${spring.rabbitmq.port}")
private var port: Int = 0

@Value("\${spring.rabbitmq.username}")
private lateinit var username: String

@Value("\${spring.rabbitmq.password}")
private lateinit var password: String

@Bean
fun connectionFactory(): ConnectionFactory {
val connectionFactory = CachingConnectionFactory()
connectionFactory.setHost(host)
connectionFactory.setPort(port)
connectionFactory.username = username
connectionFactory.setPassword(password)
return connectionFactory
}

@Bean
fun jsonMessageConverter(): MessageConverter {
return Jackson2JsonMessageConverter()
}

@Bean
fun rabbitTemplate(connectionFactory: ConnectionFactory?): RabbitTemplate? {
return connectionFactory?.let { RabbitTemplate(it) }
}

@Bean
fun dockerDeploy(): Queue {
return Queue("docker.deploy", true)
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tech.niklas.ariesbackend.queue

import org.springframework.amqp.rabbit.annotation.RabbitListener
import org.springframework.stereotype.Component

@Component
class RabbitMQListener {
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class MachineController(@Autowired private val dockerMachineService: DockerMachi

@PatchMapping("/update/{id}")
fun updateMachine(@PathVariable @NotBlank id: String, @RequestBody dockerMachine: DockerMachine): DockerMachine {

return dockerMachineService.updateMachine(id, dockerMachine)
}
}
25 changes: 25 additions & 0 deletions src/main/kotlin/tech/niklas/ariesbackend/web/RabbitController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tech.niklas.ariesbackend.web

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.amqp.core.Queue
import org.springframework.amqp.rabbit.core.RabbitTemplate
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import tech.niklas.ariesbackend.model.DockerAgent

@RestController
@RequestMapping("/rabbit")
class RabbitController(@Autowired private val rabbitTemplate: RabbitTemplate,
@Autowired private val queue: Queue) {

@GetMapping("/test")
fun sendMessage(): String {
val message: String = "Hello Rabbit!"
val objectMapper: ObjectMapper = ObjectMapper()
val dockerAgent: DockerAgent = DockerAgent("xxx", "machine1", "secret123", "secret.aries.dev")
rabbitTemplate.convertAndSend(queue.name, objectMapper.writeValueAsString(dockerAgent))
return "Message sent successfully!"
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ spring.security.oauth2.client.registration.keycloak.client-id=${KC_CLIENT_ID}
spring.security.oauth2.client.registration.keycloak.client-secret=${KC_CLIENT_SECRET}
spring.security.oauth2.client.registration.keycloak.scope[3]=profile,email
spring.devtools.livereload.enabled=true
server.port=8081
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
server.port=8080
Loading