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

LL-171 #71

Merged
merged 15 commits into from
Oct 28, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Workflow to test the connection to mongoDB on pushes to any branch

name: MongoDB Connect
name: Account Microservice

# Runs on push to any branch
on:
Expand Down Expand Up @@ -35,10 +35,7 @@ jobs:
node-version: '16.x'
- name: Test mongoDB connection
run: |
cd server
npm install
npm run build
npm run start
echo "Make account microservice unit test"
env:
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGO_INITDB_ROOT_USERNAME }}
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGO_INITDB_ROOT_PASSWORD }}
Expand Down
31 changes: 16 additions & 15 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
version: "3.8"

services:
server:
build: "server/"
command: "npx ts-node src/routes/github.ts"
account:
build: "src/account/"
command: "npm run account"
ports:
- "4000:4000"
- "8000:8000"
env_file: ".env"
client:
build: "client/"
command: "npm start"
ports:
- "3000:3000"
env_file: ".env"
# Requires server services to run before running client servers
depends_on:
- "server"
- "5000:5000"
env_file: "src/account/.env"
dns:
- "8.8.8.8"
# client:
# build: "client/"
# command: "npm start"
# ports:
# - "3000:3000"
# env_file: ".env"
# # Requires server services to run before running client servers
# depends_on:
# - "server"
29 changes: 4 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
{
"name": "luminosityleds",
"version": "0.1.0",
"description": "Illuminate individual expression and creativity",
"scripts": {
"build": "tsc -p ./src",
"account": "nodemon ./src/account/account.ts",
"device": "nodemon ./src/device/device.ts",
"server": "nodemon ./src/server/server.ts",
"notification": "nodemon ./src/notification/notification.ts",
"search": "nodemon ./src/search/search.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.11.9",
"axios": "^1.2.6",
"cors": "^2.8.5",
"cors-anywhere": "^0.4.4",
"express": "^4.18.2",
"lodash.get": "^4.4.2",
"mongoose": "^6.7.2",
"nodemon": "^2.0.20",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
"typescript-coverage-report": "^0.7.0"
},
"scripts": {
"ts-coverage": "typescript-coverage-report"
}
}
24 changes: 24 additions & 0 deletions src/account/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.env

npm-debug.log*
yarn-debug.log*
yarn-error.log*
22 changes: 18 additions & 4 deletions src/account/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
FROM node:16-bullseye
# Base image for account microservice. This image uses amd64 as the architecture
FROM amd64/node:16-bullseye

# Specifies root of file structure as working directory in docker image
WORKDIR /
RUN npm install -g express

# Copy files to root of file structure in docker image
COPY account.ts /
RUN ["node", "account.ts"]
EXPOSE 3001
COPY config.ts /
COPY IUserSchema.ts /
COPY package.json /

# Install all dependencies to run account microservice
RUN npm install

# Exposes port 5000 which is the same port specified in the express app in account.ts
EXPOSE 5000

# run the command specified in the package.json to start the account microservice
CMD ["npm", "run", "account"]
25 changes: 25 additions & 0 deletions src/account/IUserSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface IUserSchema {
creationDate: {
value: number;
};

deletionDate?: {
value: Number;
};

lastUpdated?: {
value: Number;
};

email: {
value: String;
};

name: {
value: String;
};

devicesLinked?: {
value: {};
};
}
61 changes: 61 additions & 0 deletions src/account/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Account Microservice
The scope of this microservice is defined in the following [epic](https://luminosity-led.atlassian.net/browse/LL-2).

## account.ts
This program defines the account microservice. The microservice uses an isolated express app which exposes the following routes.

### POST register
This route will register a new user in the MongoDB database.

## config.ts
This file defines the environment variables and initalized variables with blank values for the account microservice.

## IUserSchema.ts
This interface defines the structure of any object that uses the interface. It corresponds to the data that will get entered into the MongoDB database.

## package.json
This file defines the name, version, description, scripts, and dependencies of the account microservice.

### Development Scripts
Uses `nodemon` which restarts the service whenever there is a change made to `account.ts`.
#### How to Run
```bash
npm run devAccount
```

### Production Scripts
Uses `ts-node` which precompiles `account.ts` TypeScript code that can be run in a terminal.
#### How to Run
```bash
npm run account
```

## Dockerfile
Defines how the docker images for the account microservice will be created.
### How to Build Docker Image
```bash
docker build -t account:VERSION .
```
VERSION = the version of the account microservice
**Run the above command from the root of the src/account directory.**
### How to Run Docker Container
```bash
docker run --rm -t -e USR=USR -e PSW=PSW -e CLUS=CLUS -e DB=DB -e COL=COL --network="host" --dns=8.8.8.8 account:VERSION
```
**Run the above command from anywhere.**

USR = username for MongoDB

PSW = password for MongoDB

CLUS = cluster for MongoDB

DB = database for MongoDB

COL = collection for MongoDB

VERSION = the version of the account microservice

network means tell docker container to use localhost

dns means tell docker container to use google's public DNS
Loading
Loading