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

Setup product catalog service #2

Merged
merged 1 commit into from
Sep 11, 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
31 changes: 31 additions & 0 deletions .github/workflows/catalog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI/CD pipeline for product catalog service

on:
push:
branches:
- main
- develop
- feature/**
pull_request:
branches:
- main
- develop
- feature/**

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: oracle
java-version: 21
- name: Setup Task
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GH_TOKEN }}
- name: Test product catalog service
run: task catalog:test
41 changes: 40 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
.idea/
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Gradle ###
.gradle/
Binary file modified .gradle/8.5/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.5/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.5/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.5/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.5/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# eshop

Event driven microservice-based c2c ecommerce platform

[![Catalog Pipeline](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml/badge.svg)](https://github.com/dksifoua/eshop/actions/workflows/catalog.yaml)
19 changes: 19 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 3

tasks:
catalog:clean:
desc: Clean product catalog service build
cmd: ./gradlew catalog:clean
silent: true

catalog:run:
desc: Run product catalog service
cmd: ./gradlew catalog:bootRun
silent: true

catalog:test:
desc: Test product catalog service
cmds:
- task: catalog:clean
- ./gradlew catalog:test
silent: true
43 changes: 43 additions & 0 deletions catalog-service/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'io.dksifoua.eshop'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:mongodb'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
useJUnitPlatform()
}
10 changes: 10 additions & 0 deletions catalog-service/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.8"
services:
mongodb:
image: mongo:latest
environment:
- MONGO_INITDB_DATABASE=catalog
- MONGO_INITDB_ROOT_PASSWORD=secret
- MONGO_INITDB_ROOT_USERNAME=root
ports:
- "27017:27017"
1 change: 1 addition & 0 deletions catalog-service/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'catalog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.dksifoua.eshop.catalog;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CatalogServiceApplication {

public static void main(String[] args) {
SpringApplication.run(CatalogServiceApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.dksifoua.eshop.catalog;

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

@Component
public class DefaultHandler {

public Mono<ServerResponse> handle() {
return ServerResponse.ok().body(Mono.just("Hello world!!!"), String.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.dksifoua.eshop.catalog.configuration;

import io.dksifoua.eshop.catalog.DefaultHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class RouterConfiguration {

@Bean
public RouterFunction<ServerResponse> handler(DefaultHandler handler) {
return RouterFunctions.route()
.path("/default", builder -> builder.GET(request -> handler.handle()))
.build();
}
}
3 changes: 3 additions & 0 deletions catalog-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
application:
name: catalog-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.dksifoua.eshop.catalog;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;

@Import(TestcontainersConfiguration.class)
@SpringBootTest
class CatalogServiceApplicationTests {

@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.dksifoua.eshop.catalog;

import org.springframework.boot.SpringApplication;

public class TestCatalogServiceApplication {

public static void main(String[] args) {
SpringApplication.from(CatalogServiceApplication::main).with(TestcontainersConfiguration.class).run(args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.dksifoua.eshop.catalog;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
class TestcontainersConfiguration {

@Bean
@ServiceConnection
MongoDBContainer mongoDbContainer() {
return new MongoDBContainer(DockerImageName.parse("mongo:latest"));
}

}
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
rootProject.name = 'eshop'

include('catalog-service')
Loading