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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ci

on:
push:
branches:
- "master"

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/cakemanager:latest
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/target
/.idea
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1

FROM maven:3.9.3-amazoncorretto-20 AS builder
WORKDIR /app
COPY pom.xml ./
COPY src ./src

RUN mvn clean install

# Second stage: Minimal runtime environment
FROM eclipse-temurin:20-jre-jammy
WORKDIR /app

# copy jar from the first stage
COPY --from=builder /app/target/*.jar /app/app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Cake Manager Micro Service (fictitious)
=======================================

A summer intern started on this project but never managed to get it finished.
The developer assured us that some of the above is complete, but at the moment accessing the /cakes endpoint
returns a 404, so getting this working should be the first priority.

Requirements:
* By accessing /cakes, it should be possible to list the cakes currently in the system. JSON would be an acceptable response format.

* It must be possible to add a new cake.

* It must be possible to update an existing cake.

* It must be possible to delete an existing cake.

Comments:
* We feel like the software stack used by the original developer is quite outdated, it would be good to migrate the entire application to something more modern. If you wish to update the repo in this manner, feel free! An explanation of the benefits of doing so (and any downsides) can be discussed at interview.

* Any other changes to improve the repo are appreciated (implementation of design patterns, seperation of concerns, ensuring the API follows REST principles etc)

Bonus points:
* Add some suitable tests (unit/integration...)
* Add some Authentication / Authorisation to the API
* Continuous Integration via any cloud CI system
* Containerisation

---
Notes from Phill
==========
## Contents
<p>
<a href="#CICD">CICD</a> •
<a href="#starting-app">Starting app</a> •
<a href="#documentation">Documentation</a> •
<a href="#authentication">Authentication</a> •
<a href="#next-steps">Next steps</a>
</p>

## Methodology
I used TDD and 'The Double Loop' cycle which is described brilliantly here: https://jmauerhan.wordpress.com/talks/double-loop-tdd-bdd-done-right/

## CICD
* Github actions workflow is setup to automatically test and build the docker container. Then it is pushed to dockerhub which can be viewed here: https://hub.docker.com/r/phillipdenness1/cakemanager
* Flyway migration scripts run automatically on startup and populates the H2 DB with test data.

---
## Starting app

Choose 1 method below:
### Using docker-compose
```bash
# run docker compose
docker-compose up
```
#### OR
### Pull from dockerhub
```bash
docker run --publish 8080:8080 phillipdenness1/cakemanager:latest
```
#### OR
### Build and run docker
```bash
# Build the container
docker build --tag cakemanagerpd .
# Run the container
docker run --publish 8080:8080 cakemanagerpd
```
#### OR

### mvn
```bash
mvn spring-boot:run
```
---
## Documentation

### Swagger documentation
- http://localhost:8080/swagger-ui/index.html
- Endpoints are validated jakarta.validation annotations

### Postman export
- postman.cakemanager.json

## Monitoring
* Logback with Logstash encoder to support searchable logs
* Prometheus is available when running via docker-compose.
- Prometheus UI: http://localhost:9090/graph?
- find_all_counter_total, find_by_id_counter_total, save_counter_total, update_counter_total, delete_counter_total, unknown_error_counter_total, bad_request_counter_total

## Authentication
* Basic authentication is applied to secure endpoints
- Add header: `Authorization: Basic dXNlcjp1c2VyUGFzcw==`
- Username=user , password=userPass

## Next steps
* Add pagination and sorting to getAll endpoint
* Extend CICD to deploy to cloud
57 changes: 0 additions & 57 deletions README.txt

This file was deleted.

13 changes: 13 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
backend:
container_name: cakemanagerpd
build: .
ports:
- 8080:8080
prometheus:
image: 'prom/prometheus'
ports:
- '9090:9090'
command: '--config.file=/etc/prometheus/config.yml'
volumes:
- './prometheus.yml:/etc/prometheus/config.yml'
Loading