This repository has been archived by the owner on Jul 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Promotions #11
Merged
Merged
Promotions #11
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Promotions Microservice CI/CD | ||
|
||
on: | ||
push: | ||
branches: [ promotions ] | ||
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/promotions/pnpm-lock.yaml | ||
- name: Install dependencies | ||
run: | | ||
cd ./services/promotions | ||
pnpm install --frozen-lockfile | ||
- name: Build | ||
run: | | ||
cd ./services/promotions | ||
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/promotions/pnpm-lock.yaml | ||
- name: Install dependencies | ||
run: | | ||
cd ./services/promotions | ||
pnpm install --frozen-lockfile | ||
- name: Execute tests | ||
run: | | ||
cd ./services/promotions | ||
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/promotions/Dockerfile | ||
push: true | ||
tags: pierrelbg/goodfood-promotions:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/promotions | ||
AMQP_URL=amqp://guest:guest@localhost | ||
|
||
PORT=50006 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
dist/ | ||
bin/ | ||
*.env* | ||
!*.env.example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ./promotions/ . | ||
|
||
# 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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Delivery Microservice | ||
|
||
| Informations | | ||
|--------------------------------------------------------------------| | ||
| **Port:** 50006 | | ||
| **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 | ||
|
||
- Promotions model: | ||
|
||
- `CreatePromotion`: Creates a new promotion in the system. | ||
- `GetPromotion`: Retrieves a promotion by its ID. | ||
- `UpdatePromotion`: Updates an existing promotion. | ||
- `DeletePromotion`: Deletes a promotion by its ID. | ||
- `GetPromotions`: Retrieves all promotions. | ||
- `ListPromotionsByRestaurant`: Retrieves all promotion for a given restaurant. | ||
|
||
## 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/promotions`) 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:50006`. | ||
|
||
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-promotions:1.0.0 -f ./promotions/Dockerfile . | ||
docker tag goodfood-promotions:1.0.0 pierrelbg/goodfood-promotions:1.0.0 | ||
docker push pierrelbg/goodfood-promotions:1.0.0 | ||
``` | ||
|
||
### Run | ||
|
||
Create the .env base on the .env.example. Then run the following command: | ||
|
||
``` | ||
docker run --env-file=.env goodfood-delivery:1.0.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@goodfood/delivery", | ||
"bin": "dist/index.js", | ||
"scripts": { | ||
"start": "node dist/index.js", | ||
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/server.ts", | ||
"build": "esbuild src/server.ts --bundle --platform=node --target=node18 --outfile=dist/index.js", | ||
"test": "echo 'tests are disabled'", | ||
"prisma:generate": "prisma generate", | ||
"postinstall": "npm run prisma:generate" | ||
}, | ||
"devDependencies": { | ||
"@types/amqplib": "^0.10.1", | ||
"prisma": "^5.0.0", | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"@grpc/grpc-js": "^1.8.18", | ||
"@grpc/proto-loader": "^0.7.8", | ||
"@prisma/client": "5.0.0", | ||
"amqplib": "^0.10.3", | ||
"dotenv": "^16.3.1", | ||
"esbuild": "^0.18.15", | ||
"nodemon": "^3.0.1", | ||
"path": "^0.12.7", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.2.0" | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.