Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Final version
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreLbg committed Aug 20, 2023
1 parent 387d1d9 commit 7f902f4
Show file tree
Hide file tree
Showing 10 changed files with 56,345 additions and 1,083 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Notification Microservice CI/CD

on:
push:
branches: [ notification ]
pull_request:
branches: [ dev, main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "pnpm"
cache-dependency-path: services/notification/pnpm-lock.yaml
- name: Install dependencies
run: |
cd ./services/notification
pnpm install --frozen-lockfile
- name: Build
run: |
cd ./services/notification
pnpm build
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: pnpm/action-setup@v2
with:
version: latest
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "pnpm"
cache-dependency-path: services/notification/pnpm-lock.yaml
- name: Install dependencies
run: |
cd ./services/notification
pnpm install --frozen-lockfile
- name: Execute tests
run: |
cd ./services/notification
pnpm test
publish:
runs-on: ubuntu-latest
needs: [ build, test ]
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: ./services/
file: ./services/notification/Dockerfile
push: true
tags: pierrelbg/goodfood-notification:latest
2 changes: 2 additions & 0 deletions services/notification/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
38 changes: 38 additions & 0 deletions services/notification/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:18-alpine3.17 as builder

# Set working directory
WORKDIR /app

# Copy the application code
COPY ./notification/ .

# Install dependencies
RUN npm install

# Copy the proto files
COPY ./proto ./proto/

# Generate Prisma client
RUN npx prisma generate

# Build the application
RUN npm run build


# Create a new image with the application
FROM node:18-alpine3.17 as runner

# Set working directory
WORKDIR /app

# Copy the application package
COPY --from=builder /app/dist .
COPY --from=builder /app/prisma/ .
COPY --from=builder /app/proto/ /proto/
COPY --from=builder /app/node_modules/.prisma /.prisma

# Expose the gRPC port
EXPOSE 50006

# Start the server
CMD [ "node", "index.js"]
83 changes: 83 additions & 0 deletions services/notification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Notification Microservice

| Informations |
|--------------------------------------------------------------------|
| **Port:** 50022 |
| **Developer:** @PierreLgb |
| **Status:** In progress |
| **Last update:** 2023-07-20 |
| **Language:** NodeJS |
| **Dependencies:** TypeScript, Prisma, gRPC, Postgres |
| **Models:** (see [`prisma/schema.prisma`](./prisma/schema.prisma)) |

## gRPC Methods

- Notifications model:

- `CreateNotification`: Creates a new notification in the system.
- `GetNotification`: Retrieves a notification by its ID.
- `UpdateNotification`: Updates an existing notification.
- `DeleteNotification`: Deletes a notification by its ID.
- `GetNotifications`: Retrieves notifications for a given message type.

## Requirements

To run this microservice, you will need to have the following installed on your system:

- NodeJS (v18.12.0 or higher) (dev. with v18.12.0)
- Postgres (v15.2 or higher) (dev. with docker image `postgres:15.2`)

You can use the following tools to help you with the setup:

- You can use nvm to set your Node version using:
- `nvm use`.
- You can use docker to run your Postgres database using:
- `docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres`

## Getting started

### 1. Clone the repository and install dependencies

1. Clone the `goodfood` repository to your local machine.
2. Navigate to the service directory (`services/notification`) in your terminal.
3. Run `npm install` to install the necessary dependencies.
4. Create a `.env` file at the root of the project directory and add the environment variables values (
see `.env.example`).
5. Run `npm run start` to start the microservice.

You can now access the microservice at `http://localhost:50022`.

NB: If you want to run the microservice in development mode, you can run `npm run dev` instead.

### 2. Create and seed the database

Run the following command to create your Postgres database structure. This also creates the models tables that are
defined in [`prisma/schema.prisma`](./prisma/schema.prisma):

```
npx prisma migrate dev --name init
```

When `npx prisma migrate dev` is executed against a newly created database, seeding is also triggered. The seed file
in [`prisma/seed.ts`](./prisma/seed.ts) will be executed and your database will be populated with the sample data.

## Build and Run with Docker

### Build

To build the image you need to be in the **parent folder** of the service you want to build. Then run the following
command:

```
docker build -t goodfood-notification:1.0.0 -f ./notification/Dockerfile .
docker tag goodfood-notification:1.0.0 pierrelbg/goodfood-notification:1.0.0
docker push pierrelbg/goodfood-notification:1.0.0
```

### Run

Create the .env base on the .env.example. Then run the following command:

```
docker run --env-file=.env goodfood-notification:1.0.0
```
Loading

0 comments on commit 7f902f4

Please sign in to comment.