Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/build
/.idea
.gradle
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM openjdk:17-jdk-slim-buster

# Set the working directory to /app
WORKDIR /cake-manager

# Copy the build output from the host machine to the container
COPY build/libs/cake-manager-*.jar app.jar

# Expose port 8080
EXPOSE 8080

# Run the command to start the Spring Boot application when the container starts
CMD ["java", "-jar", "app.jar"]
31 changes: 31 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pipeline {
agent any
environment {
// Update below details to push the image to docker repository
DOCKER_REGISTRY = ""
DOCKER_IMAGE_NAME = "cake-manager"
DOCKER_IMAGE_TAG = "latest"
USERNAME = "<username>"
PASSWORD = "<password>"
}
stages {
stage("Build") {
steps {
sh "./gradlew build"
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ."
}
}
stage("Test") {
steps {
sh "./gradlew test"
}
}
stage("Deploy") {
steps {
sh "docker login -u ${USERNAME} -p ${PASSWORD} ${DOCKER_REGISTRY}"
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}"
sh "docker-compose up -d"
}
}
}
}
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Overview

### Endpoints
Cake-Manager service have the following functionalities:
1. Add a new cake
2. Update an existing cake
3. Delete an existing cake
4. Get an existing cake
5. Get all cakes

Application uses H2 InMemory database. Data updates will be cleared when the application is restarted.

### User access
Application uses InMemoryUserDetail for application authentication and authorisation.

1. Below user can only access get APIs (Get All Cakes and Get Cake By Id)
```
username: 'user',
password: 'password',
roles: 'USER'
```

2. Admin user have access to get, create, update, delete APIs
```
username: 'admin',
password: 'password',
roles: ('USER', 'ADMIN')
```

### API Documentation
[Swagger UI](http://localhost:8080/swagger-ui/index.html)

### Running the application

1. Initial static data: Application loads the static data from json file to H2 database at the application startup [cakes.json](src%2Fmain%2Fresources%2Fstatic%2Fcakes.json)

2. Run application locally in terminal

```./gradlew bootRun```

3. Run the application in a docker container locally

```docker-compose up -d```

4. Build the application using Jenkinsfile. Currently there are 3 stages setup in Jenkinsfile Build, Test and Deploy.
Docker registry details and user credentials for docker registry needs updatating in Jenkinsfile to execute the deploy stage.
51 changes: 51 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.3'
id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.waracle'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}


repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.flywaydb:flyway-core'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'

compileOnly 'org.projectlombok:lombok'
compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}

tasks.named('test') {
useJUnitPlatform()
}

jar {
enabled = false
}

bootJar {
enabled = true
}
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'
services:
app:
platform: linux/amd64
build: .
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:h2:mem:testdb
SPRING_DATASOURCE_USERNAME: sa
SPRING_DATASOURCE_PASSWORD: password
SPRING_H2_CONSOLE_ENABLED: "true"
SPRING_H2_CONSOLE_PATH: /h2-console
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading