Skip to content

Commit

Permalink
feat: Make the Demo Work
Browse files Browse the repository at this point in the history
  • Loading branch information
lholmquist authored May 8, 2024
1 parent afaaebd commit 18a59c4
Show file tree
Hide file tree
Showing 139 changed files with 26,629 additions and 380 deletions.
25 changes: 25 additions & 0 deletions .devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
schemaVersion: 2.2.2
metadata:
name: coolstore-demo-node
components:
- name: tools
container:
image: registry.redhat.io/devspaces/udi-rhel8:3.13
endpoints:
- exposure: public
name: inventory-index
targetPort: 8080
- exposure: none
name: debug
targetPort: 5858
memoryLimit: 6Gi
memoryRequest: 4Gi
cpuLimit: 2000m
cpuRequest: 500m
mountSources: true
volumeMounts:
- name: npm
path: /home/user/.npm
- name: npm
volume:
size: 1G
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ typings/
.yarn-integrity

# dotenv environment variables file
.env
.env.test
# .env
# .env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand All @@ -128,8 +128,6 @@ typings/
# DynamoDB Local files
.dynamodb/

# Package json
package-lock.json

mvnw
mvnw.cmd
Expand All @@ -138,9 +136,14 @@ mvnw.cmd
*.iml
.project
.classpath
.dockerignore

.vscode/
.idea/


# End of https://www.gitignore.io/api/node,java,maven

tmp/
dist/

.DS_Store
5 changes: 0 additions & 5 deletions .idea/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

111 changes: 109 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,113 @@
# coolstore
This is an example demo showing a retail store consisting of several microservices based on NodeJS. Project is an effort to demonstrate different NodeShift features.
This is an example demo showing a retail store consisting of several microservices based on NodeJS.

![Architecture Screenshot](https://raw.githubusercontent.com/jbossdemocentral/coolstore-microservice/stable-ocp-3.11/docs/images/store.png "CoolStore Online Shop")
A Coolstore app where users can buy some cool merchandise.


- The UI is built with NodeJS and Angular. And the backend includes multiple Node.js services, such as
- *Inventory* , The stores inventory, how much items are available etc.
- *Catalog* , The products API
- *Cart*, Stores all users carts and intiates the order process by sending a message to Orders
- *Orders*, Completion and checking of orders
- *Payments*, Checks whether an payment is successfull given a certain Credit Card.

The demo is simple. Add an item to the cart. Checkout the item by going to the `Cart` tab. Add payment details. If the Card number starts with 4 the payment is successful else it will show status failed. this is a hard check in the payment service.

Once done, goto the `Orders` tab. The Order status should be `In Progress`, refresh after a couple of seconds and the status will appear as `COMPLETED` or `FAILED`. It takes a couple of seconds as their is a wait timer in Payment service + the whole process is done in a reactive and event driven way using Kafka and Quarkus.

![Architecture Screenshot](./docs/images/coolstore-ui.png)

## Run Locally

The whole demo application can be run locally for those using docker/podman.

Run the docker-compose.yml file in the `deploy` directory

```
podman compose up
```

## Cluster Setup

* Pre-Req: Have an Openshift cluster and log in using the `oc` client

* Change into the deploy directory

```
cd deploy
```

### Create Project/Namespace

oc new-project coolstore-dev

### Kafka Related

#### Install Kafka Operator

oc apply -f kafka-operator.yaml


#### Create instance

#### NEED TO WAIT ON THE OPERATOR READINESS FIRST

oc apply -f kafka-cluster-creation.yaml -n coolstore-dev

#### create topics

oc apply -f kafka-topics.yaml -n coolstore-dev

### Redis Cache

#### Create Redis Cache

oc create -f redis-deployment.yaml -n coolstore-dev

#### Create Service for Deployment

oc apply -f redis-service.yaml -n coolstore-dev



### Mongo DB Service

#### Create Configmap to hold init.js

oc create configmap mongo-db-init --from-file ./mongo-init.js -n coolstore-dev

#### Create the MongoDB Instance

oc create -f mongo-deployment.yaml -n coolstore-dev

#### Create MongoDB Service
oc apply -f mongo-service.yaml -n coolstore-dev


## Node.s Service Deployment

Each Node.js service has a npm script named `deploy` that uses the [Nodeshift cli](https://www.npmjs.com/package/nodeshift) to easily deploy your services to the cluster.

In each node application directory, run with:

```
npm run deploy
```

There is also a runnable script in the `deploy` directory that will deploy all the Node.js services in the correct order.

```
cd deploy/
./deploy-node-services.sh
```

## Run Locally

The whole demo application can be run locally for those using docker/podman.

Run the docker-compose.yml file in the `deploy` directory

```
podman compose up
```
7 changes: 7 additions & 0 deletions cart-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
./node_modules

Dockerfile

.dockerignore

docker-compose.yml
5 changes: 5 additions & 0 deletions cart-service/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
redis_host: 'localhost'
redis_port: '6379'

kafka_host: 'localhost'
kafka_port: '9092'
5 changes: 0 additions & 5 deletions cart-service/.idea/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions cart-service/.idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions cart-service/.idea/vcs.xml

This file was deleted.

30 changes: 30 additions & 0 deletions cart-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Install the app dependencies in a full UBI Node docker image
FROM registry.access.redhat.com/ubi8/nodejs-20:latest

# Copy package.json
COPY package*.json tsconfig.json .env ./
COPY src/ ./src

USER 0

# Install npm packages
RUN npm install

# Run the build command becuase Typescript
RUN npm run build

# PRUNE DEV Deps
RUN npm prune --omit=dev

# Copy the dependencies into a Slim Node docker image
FROM registry.access.redhat.com/ubi8/nodejs-20-minimal:latest

# Install app dependencies from the other container
COPY --from=0 /opt/app-root/src/node_modules /opt/app-root/src/node_modules
COPY --from=0 /opt/app-root/src/dist /opt/app-root/src/dist
COPY --from=0 /opt/app-root/src/package.json /opt/app-root/src/.env /opt/app-root/src/

ENV NODE_ENV production
EXPOSE 7074

CMD ["npm", "start"]
Loading

0 comments on commit 18a59c4

Please sign in to comment.