Skip to content

Commit

Permalink
working tests and actions update
Browse files Browse the repository at this point in the history
  • Loading branch information
NiHaiden committed Mar 19, 2024
1 parent 61b3c40 commit 826dff3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
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
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ plugins {
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 @@ -35,9 +36,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'com.github.dasniko:testcontainers-keycloak:3.2.0'
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'
Expand Down
13 changes: 13 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,18 @@ services:
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
15 changes: 13 additions & 2 deletions src/main/kotlin/tech/niklas/ariesbackend/queue/RabbitMQConfig.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
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 {
Expand All @@ -31,13 +35,20 @@ class RabbitMQConfig {
return connectionFactory
}

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

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

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


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ import org.springframework.stereotype.Component

@Component
class RabbitMQListener {
@RabbitListener(queues = arrayOf("docker.deploy"))
fun processMessage(message: String) {
println("Received message: $message")
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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")
Expand All @@ -15,7 +17,9 @@ class RabbitController(@Autowired private val rabbitTemplate: RabbitTemplate,
@GetMapping("/test")
fun sendMessage(): String {
val message: String = "Hello Rabbit!"
rabbitTemplate.convertAndSend(queue.name, message)
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!"
}
}

0 comments on commit 826dff3

Please sign in to comment.