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

Improve developer experience when working with traderx and k8s #232

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions README.md
matthewgardner marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ cd .corp

## Usage (K8s)

The following are instructions to build and deploy all TraderX apps to your local enviroment using [tilt](https://tilt.dev) and kustomize files.
The following are instructions to deploy all TraderX apps to your local enviroment using [tilt](https://tilt.dev) and kustomize files.

## Prerequistes
- Running [Docker](https://www.docker.com/products/docker-desktop/) or similar
Expand All @@ -183,13 +183,21 @@ Check your cluster is running using the epic tool `k9s` - https://k9scli.io/

### Start Tilt

This command will build and start all locally built applications and deploy them to your local K8s environment.
This command will deploy all the services to your local K8s environment.

```
cd ./gitops/local/
tilt up
matthewgardner marked this conversation as resolved.
Show resolved Hide resolved
```

### Local Developement

With all the services running you can then chose which ones you actively build locally.

If you go to your local [Tiltfile](./gitops/local/Tiltfile) you simply need to uncomment all the lines, or just for the respective applicaiton that you want to work on. Those applications will be built locally and deployed to your cluster instead of the host images.




# Getting Involved

Expand Down
2 changes: 1 addition & 1 deletion gitops/base/account-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
value: "18088"
- name: DATABASE_TCP_HOST
value: database
image: traderx/account-service
image: ghcr.io/finos/traderx/account-service
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18088
Expand Down
2 changes: 1 addition & 1 deletion gitops/base/database/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: database-app
image: traderx/database
image: ghcr.io/finos/traderx/database
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18082
Expand Down
2 changes: 1 addition & 1 deletion gitops/base/people-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
spec:
containers:
- name: people-service
image: traderx/people-service
image: ghcr.io/finos/traderx/people-service
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18089
Expand Down
24 changes: 23 additions & 1 deletion gitops/base/position-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,33 @@ spec:
value: database
- name: POSITION_SERVICE_PORT
value: "18090"
image: traderx/position-service
image: ghcr.io/finos/traderx/position-service
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18090
protocol: TCP
workingDir: /position-service

# Liveness Probe: Checks if the container is alive
livenessProbe:
httpGet:
path: /health/alive # The endpoint for the liveness probe
port: 18090 # Port to hit on the container
initialDelaySeconds: 10 # Delay before starting the probe after the container starts
periodSeconds: 10 # How often to run the probe (every 10 seconds)
timeoutSeconds: 5 # Timeout for the probe to respond
failureThreshold: 3 # If it fails 3 times, restart the container

# Readiness Probe: Checks if the container is ready to serve traffic
readinessProbe:
httpGet:
path: /health/ready # The endpoint for the readiness probe
port: 18090 # Port to hit on the container
initialDelaySeconds: 5 # Delay before starting the probe after the container starts
periodSeconds: 5 # How often to run the probe (every 5 seconds)
timeoutSeconds: 5 # Timeout for the probe to respond
successThreshold: 1 # Minimum number of successful probes to mark it as ready
failureThreshold: 3 # If it fails 3 times, the pod is marked as unready

restartPolicy: Always

4 changes: 2 additions & 2 deletions gitops/base/reference-data/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ spec:
- name: reference-data
env:
- name: REFERENCE_DATA_SERVICE_PORT
value: "18095"
image: traderx/reference-data
value: "18085"
image: ghcr.io/finos/traderx/reference-data
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18085
Expand Down
2 changes: 1 addition & 1 deletion gitops/base/trade-feed/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
app: trade-feed
spec:
containers:
- image: traderx/trade-feed
- image: ghcr.io/finos/traderx/trade-feed
imagePullPolicy: IfNotPresent
name: trade-feed
env:
Expand Down
2 changes: 1 addition & 1 deletion gitops/base/trade-processor/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: trade-processor-app
image: traderx/trade-processor
image: ghcr.io/finos/traderx/trade-processor
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18091
Expand Down
2 changes: 1 addition & 1 deletion gitops/base/trade-service/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
value: reference-data
- name: TRADE_FEED_HOST
value: trade-feed
image: traderx/trade-service
image: ghcr.io/finos/traderx/trade-service:latest
imagePullPolicy: IfNotPresent
name: trade-service
ports:
Expand Down
2 changes: 1 addition & 1 deletion gitops/base/web-front-end/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
app: web-front-end-angular
spec:
containers:
- image: traderx/web-front-end-angular
- image: ghcr.io/finos/traderx/web-front-end-angular:latest
imagePullPolicy: IfNotPresent
name: web-front-end-angular
env:
Expand Down
19 changes: 10 additions & 9 deletions gitops/local/Tiltfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
docker_build('traderx/database', './../../database/.')
docker_build('traderx/account-service', './../../account-service/.')
docker_build('traderx/people-service', './../../people-service/.')
docker_build('traderx/position-service', './../../position-service/.')
docker_build('traderx/reference-data', './../../reference-data/.')
docker_build('traderx/trade-feed', './../../trade-feed/.')
docker_build('traderx/trade-processor', './../../trade-processor/.')
docker_build('traderx/trade-service', './../../trade-service/.')
docker_build('traderx/web-front-end-angular', './../../web-front-end/angular/.')
# Uncomment lines to use locally built version
# docker_build('ghcr.io/finos/traderx/database', './../../database/.')
# docker_build('ghcr.io/finos/traderx/account-service', './../../account-service/.')
# docker_build('ghcr.io/finos/traderx/people-service', './../../people-service/.')
# docker_build('ghcr.io/finos/traderx/position-service', './../../position-service/.')
# docker_build('ghcr.io/finos/traderx/reference-data', './../../reference-data/.')
# docker_build('ghcr.io/finos/traderx/trade-feed', './../../trade-feed/.')
# docker_build('ghcr.io/finos/traderx/trade-processor', './../../trade-processor/.')
# docker_build('ghcr.io/finos/traderx/trade-service', './../../trade-service/.')
# docker_build('ghcr.io/finos/traderx/web-front-end-angular', './../../web-front-end/angular/.')
yaml = kustomize(('./traderx'))
print(yaml)
k8s_yaml(yaml)
14 changes: 10 additions & 4 deletions position-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

# [Choice] Java version (use -bullseye variants on local arm64/Apple Silicon): 11, 17, 11-bullseye, 17-bullseye, 11-buster, 17-buster
ARG VARIANT="21"
FROM mcr.microsoft.com/vscode/devcontainers/java:1-${VARIANT}
FROM mcr.microsoft.com/vscode/devcontainers/java:1-${VARIANT} AS build-stage

# Copy code
WORKDIR /position-service
COPY . .

EXPOSE 18090

# Build code
RUN ./gradlew build
ENTRYPOINT ./gradlew bootRun

FROM mcr.microsoft.com/openjdk/jdk:${VARIANT}-ubuntu
RUN mkdir /app
COPY --from=build-stage /position-service/build/libs/*.jar /app/position-service.jar
EXPOSE 18090
# ENTRYPOINT ./gradlew bootRun
ENTRYPOINT ["java","-jar","/app/position-service.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package finos.traderx.positionservice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import finos.traderx.positionservice.model.Position;
import finos.traderx.positionservice.service.PositionService;

@CrossOrigin("*")
@RestController
@RequestMapping(value="/health", produces="application/json")
public class HealthController {

@Autowired
PositionService positionService;


@GetMapping("/ready")
public ResponseEntity isReady() {
List<Position> retVal = this.positionService.getAllPositions();
return ResponseEntity.ok(retVal.size()>0);
}

@GetMapping("/alive")
public ResponseEntity<Boolean> isAlive() {
return ResponseEntity.ok(true);
}


@ExceptionHandler(Exception.class)
public ResponseEntity<String> generalError(Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
}