Catalogue - Roboshop Project
The cataloge code
{
"MaxCount": 1,
"MinCount": 1,
"ImageId": "ami-0089b8e98cd95257d",
"InstanceType": "t3.micro",
"EbsOptimized": true,
"NetworkInterfaces": [
{
"DeviceIndex": 0,
"AssociatePublicIpAddress": true,
"SubnetId": "subnet-086a045ade7eae99f",
"Groups": [
"sg-0c2e3fdd288a74d3a"
]
}
],
"TagSpecifications": [
{
"ResourceType": "instance",
"Tags": [
{
"Key": "Name",
"Value": "catalogue"
}
]
},
{
"ResourceType": "spot-instances-request",
"Tags": [
{
"Key": "Name",
"Value": "catalogue"
}
]
}
],
"InstanceMarketOptions": {
"MarketType": "spot",
"SpotOptions": {
"InstanceInterruptionBehavior": "stop",
"SpotInstanceType": "persistent"
}
},
"PrivateDnsNameOptions": {
"HostnameType": "ip-name",
"EnableResourceNameDnsARecord": true,
"EnableResourceNameDnsAAAARecord": false
}
}
Configuring Catalogue
The Catalogue microservice is responsible for serving the list of items that display in the RoboShop application.
As per the developer's preference, Node.js has been selected as the development language, with Node.js version greater than 18. To set up the Node.js environment, we need to first set up the Node.js repository by running the following command:
curl -sL https://rpm.nodesource.com/setup_lts.x | bash
After setting up the repository, we can proceed with the installation of Node.js by running the command:
yum install nodejs -y
Next, we need to configure the application. Since the application does not have an RPM package, we will have to configure it manually.
As per standard practice, applications should run as non-root users. Therefore, we need to create a user for the Catalogue service by running the command:
useradd roboshop
We also need to create a standard application directory by running the command:
mkdir /app
We can download the application code to the newly created directory by running the command:
curl -o /tmp/catalogue.zip https://roboshop-artifacts.s3.amazonaws.com/catalogue.zip
cd /app
unzip /tmp/catalogue.zip
After downloading the application code, we need to download the application's dependencies by running the command:
cd /app
npm install
Next, we need to set up a new service in SystemD so that systemctl can manage this service. We can do this by creating a service file at the following path:
/etc/systemd/system/catalogue.service
We can use the following template for the Catalogue service:
[Unit]
Description=Catalogue Service
[Service]
User=roboshop
Environment=MONGO=true
Environment=MONGO_URL="mongodb://<MONGODB-SERVER-IPADDRESS>:27017/catalogue"
ExecStart=/bin/node /app/server.js
SyslogIdentifier=catalogue
[Install]
WantedBy=multi-user.target
We must ensure that we replace the <MONGODB-SERVER-IPADDRESS> placeholder with the IP address of the MongoDB server. After creating the service file, we must reload the SystemD daemon to detect the new service by running the command:
systemctl daemon-reload
Finally, we can start the Catalogue service by running the following commands:
systemctl enable catalogue
systemctl start catalogue
To load the schema for the application, we must first install the MongoDB client by setting up the MongoDB repository and running the following command:
yum install mongodb-org-shell -y
After installing the MongoDB client, we can load the schema by running the following command:
mongo --host <MONGODB-SERVER-IPADDRESS> </app/schema/catalogue.js
Finally, we must update the frontend configuration by updating the IP address of the Catalogue server in the /etc/nginx/default.d/roboshop.conf configuration file.