Skip to content

Commit

Permalink
chore(notes): modified docker file and port
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoSkorJjj committed Feb 22, 2024
1 parent 8abb02a commit dbe704c
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.vscode
**/*_password.txt
.DS_Store
node_modules
node_modules
163 changes: 95 additions & 68 deletions deployment/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,91 +1,118 @@
version: "3.8"

secrets:
kong_db_password:
file: ./kong_db_password.txt
# secrets:
# kong_db_password:
# file: ./kong_db_password.txt

x-common-env:
&common-env
KONG_PG_HOST: kong-database
KONG_PG_USER: kong
KONG_PG_PASSWORD_FILE: /run/secrets/kong_db_password
# x-common-env:
# &common-env
# KONG_PG_HOST: kong-database
# KONG_PG_USER: kong
# KONG_PG_PASSWORD_FILE: /run/secrets/kong_db_password

networks:
default:

volumes:
kong-data: {}
user-storage-db-volume: {}
# kong-data: {}
# user-storage-db-volume: {}
notes-db-volume: {}

services:
kong-gateway:
image: kong:latest
build: ../../kong-gateway
environment:
<<: *common-env
KONG_DATABASE: off
KONG_PLUGINS: bundled,authn-kong
KONG_DECLARATIVE_CONFIG: /etc/kong/kong.yml
ports:
- "8000:8000" # Proxy
# - "8001:8001" # Admin API
- "8443:8443" # Proxy SSL
- "8444:8444" # Admin API SSL
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 5s
retries: 5
secrets:
- kong_db_password
restart: on-failure
volumes:
- ../../kong-gateway/kong.yml:/etc/kong/kong.yml
- ../../kong-gateway/authn-kong:/usr/local/share/lua/5.1/kong/plugins/authn-kong
- ../../kong-gateway/protos:/usr/local/share/lua/5.1/kong/protos
# kong-gateway:
# image: kong:latest
# build: ../../kong-gateway
# environment:
# <<: *common-env
# KONG_DATABASE: off
# KONG_PLUGINS: bundled,authn-kong
# KONG_DECLARATIVE_CONFIG: /etc/kong/kong.yml
# ports:
# - "8000:8000" # Proxy
# # - "8001:8001" # Admin API
# - "8443:8443" # Proxy SSL
# - "8444:8444" # Admin API SSL
# healthcheck:
# test: ["CMD", "kong", "health"]
# interval: 10s
# timeout: 5s
# retries: 5
# secrets:
# - kong_db_password
# restart: on-failure
# volumes:
# - ../../kong-gateway/kong.yml:/etc/kong/kong.yml
# - ../../kong-gateway/authn-kong:/usr/local/share/lua/5.1/kong/plugins/authn-kong
# - ../../kong-gateway/protos:/usr/local/share/lua/5.1/kong/protos

user-storage-db:
image: postgres
volumes:
- user-storage-db-volume:/var/lib/postgresql/data
- ../sql_table/create_user_storage_table.sql:/docker-entrypoint-initdb.d/user_storage.sql
# user-storage-db:
# image: postgres
# volumes:
# - user-storage-db-volume:/var/lib/postgresql/data
# - ../sql_table/create_user_storage_table.sql:/docker-entrypoint-initdb.d/user_storage.sql
# environment:
# POSTGRES_DB: user_storage_db
# POSTGRES_USER: user_storage_user
# POSTGRES_PASSWORD: user_storage_password
# ports:
# - "5432:5432"
# healthcheck:
# test: ["CMD-SHELL", "pg_isready -U user_storage_user -d user_storage_db"]
# interval: 10s
# timeout: 5s
# retries: 5

notes-db:
image: mysql:latest
environment:
POSTGRES_DB: user_storage_db
POSTGRES_USER: user_storage_user
POSTGRES_PASSWORD: user_storage_password
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=my_notes_app
ports:
- "5432:5432"
- "3306:3306"
volumes:
- notes-db-volume:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U user_storage_user -d user_storage_db"]
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot"]
interval: 10s
timeout: 5s
retries: 5

user-redis:
image: redis:7.2-rc2-alpine3.18
command: redis-server --requirepass password
healthcheck:
test: [ "CMD", "redis-cli", "-a", "password", "--raw", "incr", "ping" ]
interval: 5s
timeout: 5s
retries: 5
# user-redis:
# image: redis:7.2-rc2-alpine3.18
# command: redis-server --requirepass password
# healthcheck:
# test: [ "CMD", "redis-cli", "-a", "password", "--raw", "incr", "ping" ]
# interval: 5s
# timeout: 5s
# retries: 5

user-storage-service:
build: ../../user-storage
image: user-storage-service:1.0
notes-service:
build: ../../notes
depends_on:
kong-gateway:
condition: service_healthy
user-storage-db:
# kong-gateway:
# condition: service_healthy
notes-db:
condition: service_healthy
ports:
- "50051:50051"
- "50052:50052"


frontend-client:
build: ../../client
image: client:1.0
depends_on:
kong-gateway:
condition: service_healthy
ports:
- "3001:3001"
# user-storage-service:
# build: ../../user-storage
# image: user-storage-service:1.0
# depends_on:
# kong-gateway:
# condition: service_healthy
# user-storage-db:
# condition: service_healthy
# ports:
# - "50051:50051"

# frontend-client:
# build: ../../client
# image: client:1.0
# depends_on:
# kong-gateway:
# condition: service_healthy
# ports:
# - "3001:3001"
9 changes: 7 additions & 2 deletions notes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.vscode
**/*_password.txt
.DS_Store
node_modules

.env
.env.local
.env.development.local

venv
__pycache__
15 changes: 9 additions & 6 deletions notes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app

# Copy the application files into the container at /app
COPY ./notes /app

# Install any needed packages specified in requirements.txt
# Copy only the requirements.txt first to leverage Docker cache
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Make port 50051 available to the world outside this container
EXPOSE 50051
# Copy the rest of the application
COPY . .

# It's a good practice to expose the port your app runs on.
# This does not actually publish the port but serves as documentation.
EXPOSE 50052

# Run note_upload_service.py when the container launches
CMD ["python", "./note_upload_service.py"]
CMD ["python3", "note_upload_service.py"]
2 changes: 1 addition & 1 deletion notes/note_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def retrieve_note(stub, note_id):
return response

def run():
with grpc.insecure_channel('localhost:50051') as channel:
with grpc.insecure_channel('localhost:50052') as channel:
stub = notes_pb2_grpc.NoteServiceStub(channel)

# Example usage: upload a PDF note
Expand Down
9 changes: 6 additions & 3 deletions notes/note_upload_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import notes_pb2
import notes_pb2_grpc
from concurrent import futures
from dotenv import load_dotenv

# Directly specify your AWS credentials (Not recommended for production use)
# s3_client = boto3.client(
# 's3',
# aws_access_key_id='AKIAXBWYNHCVA3KMXP4F',
# aws_secret_access_key='l2fqR/CFwofX3MhTC79cWjfuvikGDZg47lPRhZv6'
# aws_access_key_id='',
# aws_secret_access_key=''
# )
load_dotenv()

s3_client = boto3.client('s3')
bucket_name = 'eduhelper-s3notes-bucket'

Expand Down Expand Up @@ -97,7 +100,7 @@ def RetrieveNote(self, request, context):
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
notes_pb2_grpc.add_NoteServiceServicer_to_server(NoteServiceServicer(), server)
server.add_insecure_port('[::]:50051')
server.add_insecure_port('[::]:50052')
server.start()
server.wait_for_termination()

Expand Down
3 changes: 2 additions & 1 deletion notes/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
grpcio
grpcio-tools
boto3
mysql-connector-python
mysql-connector-python
python-dotenv
4 changes: 4 additions & 0 deletions user-storage/@types/myinfo-connector-v4-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ declare module 'myinfo-connector-v4-nodejs' {
// Adjusted to export MyInfoConnector as a default export
export default MyInfoConnector;
}
// declare module 'myinfo-connector-v4-nodejs' {
// const MyInfoConnector: any;
// export default MyInfoConnector;
// }
48 changes: 40 additions & 8 deletions user-storage/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
FROM node:slim
RUN apt update && apt install curl -y
# FROM node:slim
# RUN apt update && apt install curl -y

ENV NODE_ENV=development
# ENV NODE_ENV=development

WORKDIR /app
# WORKDIR /app

COPY package*.json ./
# COPY package*.json ./

# RUN npm install

# COPY . .

# EXPOSE 50051

RUN npm install
# CMD [ "npm", "run", "start" ]

FROM node:20.11.1-alpine3.19 AS build
WORKDIR /app
COPY package*.json ./
# --only allows the following: null, prod, and production
RUN npm ci
COPY . .
RUN npm run build
COPY protos ./dist/protos

FROM node:20.11.1-alpine3.19
ENV NODE_ENV production
WORKDIR /app
COPY .env .env
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
CMD ["node", "./dist/src/index.js"]

EXPOSE 50051
# FROM node:20.11.1-alpine3.19 AS build
# WORKDIR /app
# COPY package*.json ./
# RUN npm ci
# COPY . .
# RUN npm run build
# COPY protos ./dist/protos

CMD [ "npm", "run", "start" ]
# FROM node:20.11.1-alpine3.19
# ENV NODE_ENV development
# WORKDIR /app
# COPY --from=build /app/dist ./dist
# COPY --from=build /app/node_modules ./node_modules
# CMD ["node", "./dist/src/index.js"]
3 changes: 2 additions & 1 deletion user-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/index.ts"
"start": "ts-node src/index.ts",
"build": "tsc"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion user-storage/src/config/myinfo_config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MyInfoConfig } from "myinfo-connector-v4-nodejs";

const urlEnvironmentPrefix = process.env.NODE_ENV === "production" ? "" : `${process.env.URL_ENVIRONMENT_PREFIX}.`;
const urlEnvironmentPrefix = `${process.env.URL_ENVIRONMENT_PREFIX}.`;

export const APP_CONFIG = {
MYINFO_CLIENT_ID: process.env.MYINFO_CLIENT_ID,
Expand Down
3 changes: 2 additions & 1 deletion user-storage/src/server/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class GRPCServer {
return;
}

const pathToServiceDefinitions = path.resolve(__dirname, '../proto-services', `${protoName}.ts`);
const extension = process.env.NODE_ENV === 'production' ? 'js' : 'ts';
const pathToServiceDefinitions = path.resolve(__dirname, '../proto-services', `${protoName}.${extension}`);
const serviceDefinitions = await import(pathToServiceDefinitions);

let pathToProto = path.resolve(__dirname, '../../protos/', protoName);
Expand Down
2 changes: 1 addition & 1 deletion user-storage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand Down

0 comments on commit dbe704c

Please sign in to comment.