- Docker
- Kubernetes
- Ingress-nginx controller (as load balancer service)
- skaffold
Shared code is just another git project which is added as git submodule and published as NPM public *@ngazicticketingapp/common Linke here
Set your local routing to custom ticketing.dev (this is ingress requirement). The host file is on the path "C:\Windows\System32\drivers\etc" (Windows)
Inside root directory, run:
kubectl create secret generic jwt-secret --from-literal=JWT_KEY=somesecretpasswordinkubernetes # to create secret JWT token signature in Kubernetes
kubectl create secret generic stripe-secret --from-literal=STRIPE_KEY=somesecretpasswordinkubernetes # to create secret Stripe token in Kubernetes, e.i. use "sk_test_51Kog8zFJPhsaxAKzeAakeguFNkjydu6iu2ReGl4JcSG5dZn1Z5Fzgu3AQ2VVBbxgSG5DChCuePiNrQr5pWQJqVMb00Pfb2DsiT" which is test implementation
kubectl get secrets # to check all the secrets
skaffold dev
- Users can list a ticket for an event (concert, sports) for sale
- Other users can purchase this ticket
- Any users can list tickets for sale and purchase tickets
- When a user tries to purchase, the ticket is "locked" for 15 minutes. The user has 15 minutes to enter their payment info
- While locked, no other user can purchase the ticket. After 15 minutes, the should "unlock"
- Ticket prices can be edited if they are not locked
We are creating a separate service to manage each type of resource:
- auth (everything related to user signup/signin/signout)
- tickets (ticket creation/editing. Knows whether a ticket can be updated)
- orders (order creation/editing)
- expiration (watches for orders to be created, cancels them after 15 minutes)
- payments (handles credit card payments. Cancels orders if payments fails, completes if payment succeeds)
- UserCreated
- UserUpdated
- OrderCreated
- OrderCancelled
- OrderExpired
- TicketCreated
- TicketUpdated
- ChargeCreated
- All error responses that we send out from any server should have this structure:
{
errors: {
message: string, field?:string
}[]
}
- The response status should be accordingly to the error
We'll inherit this abstract class for all our custom errors:
abstract class CustomError extends Error {
abstract statusCode: number;
constructor(message: string) {
super(message);
Object.setPrototypeOf(this, CustomError.prototype);
}
abstract serializeErrors(): { message: string; field?: string }[];
}
Use express-async-errors package
Sharing all services common secrets inside Kubernetes
I.e. create jwt signing key:
kubectl create secret generic jwt-secret --from-literal=JWT_KEY=jwt_signature_value
## checking the secrets
kubectl get secrets
This is example of CI/CD
- Create package.json, install deps
- Write Dockerfile
- Create index.ts to run project
- Build image, push to docker hub
- Write k8s file for deployment, service
- Update skaffold.yaml to do file sync for the service
- Write k8s file for MongoDB Deployment and service
kubectl config view
### Choose your config
kubectl config use-context <context name>
CI is done by Github actions for each microservice selectively,and for Infra folder. Also, test are run on creating pull request as well.
Note: do the final push of all images to docker hub for each service after the development is done!!!