Skip to content

Commit

Permalink
Merge branch 'main' into recent_note_list_api
Browse files Browse the repository at this point in the history
  • Loading branch information
HyTekCoop committed Oct 21, 2023
2 parents 6e5fa6d + f9a4eac commit 5e9779b
Show file tree
Hide file tree
Showing 61 changed files with 8,910 additions and 5,777 deletions.
7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
!package.json
!package-lock.json
!tsconfig.json
!migrations
!init.sh
!yarn.lock
!.yarnrc.yml
!.yarn/releases

# Ignore unnecessary files inside allowed directories
**/*~
**/*.log
**/.DS_Store
**/.DS_Store
20 changes: 0 additions & 20 deletions .eslintrc

This file was deleted.

28 changes: 28 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

/* eslint-disable */
module.exports = {
'extends': [
'codex/ts',
],
'plugins': [ 'vitest' ],
'parserOptions': {
'project': 'tsconfig.json',
'tsconfigRootDir': __dirname,
'sourceType': 'module',
},
'rules': {
'@typescript-eslint/naming-convention': [
'error',
{
'selector': 'property',
'format': ['camelCase', 'PascalCase'],
'filter': {
// Allow "2xx" as a property name, used in the API response schema
'regex': '^(2xx)$',
'match': false,
},
},
],
'jsdoc/require-returns-type': "off"
},
};
4 changes: 2 additions & 2 deletions .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:

- name: Install dependencies
run: |
npm install
yarn install
- name: Run ESLint
run: npm run lint
run: yarn lint

build:
runs-on: ubuntu-22.04
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
app-config.local.yaml
docker-compose.yml
.idea
dist
database
Expand All @@ -22,6 +21,12 @@ pids
*.seed
*.pid.lock

# package manager
.yarn/*
!.yarn/releases
!.yarn/plugins
.pnp.*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.16.0
v20
874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.4.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarnPath: .yarn/releases/yarn-3.6.4.cjs
nodeLinker: node-modules
51 changes: 43 additions & 8 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Development

## Running in development mode
## Setup local database

To run application in development mode you need to run `npm run dev` command.
It will start application with `nodemon` and restart it on any changes in source code.

You can try to build and run it in local Docker:
You can install PostgreSQL local https://www.postgresql.org/download/ or use Docker (see `docker-compose.yml`):
```
version: "3.2"
services:
Expand All @@ -14,13 +11,51 @@ services:
dockerfile: Dockerfile
context: .
ports:
- "127.0.0.1:3000:3000"
- 127.0.0.1:1337:1337
volumes:
- ./app-config.yaml:/usr/app/app-config.yaml
restart: unless-stopped
postgres:
image: postgres
environment:
POSTGRES_USER: codex
POSTGRES_DB: notes
POSTGRES_PASSWORD: postgres
ports:
- 127.0.0.1:5432:5432
volumes:
- ./database:/var/lib/postgresql/data
```

To run it execute: `docker compose up -d postgres` where `-d` is used for background run.
If you have outdated version of docker, try use `docker-compose` instead of `docker compose` (https://docs.docker.com/compose/).

To flush the database, just delete the `database` folder and restart the container:
```
rm -rf database
docker compose down
docker compose up -d postgres
```

## Running application in development mode

To run application in development mode you need to run `yarn dev` command.
It will start application with `nodemon` and restart it on any changes in source code.

You can try to build and run it in local Docker with `docker compose up api` (you can add `-d` flag for a background run).

## Configuration

Default application configuration is stored in `app-config.yaml` file.
To override default configuration you can create `app-config.local.yaml` file and override any configuration value.
Default application configuration is stored in `app-config.yaml` file. This file is intended for docker configuration since it's using `dsn: 'postgres://postgres:example@postgres:5432/codex-notes'`.

To override default configuration you can create `app-config.local.yaml` file and override any configuration value locally.
You can also override settings in docker by overriding `app-config.local.yaml` via volumes:
```
volumes:
- ./app-config.yaml:/usr/app/app-config.yaml
- ./app-config.local.yaml:/usr/app/app-config.local.yaml
```

## Logging

Expand Down
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
FROM node:18-alpine AS deps
FROM node:20-alpine AS deps

RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn/releases ./.yarn/releases
RUN yarn install

FROM node:18-alpine AS builder
FROM node:20-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN npm run build
RUN yarn build

FROM node:18-alpine AS runner
FROM node:20-alpine AS runner
WORKDIR /usr/app

COPY --from=builder /app/dist ./dist
COPY package.json ./
RUN npm install
COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn/releases ./.yarn/releases
RUN yarn install
COPY ./app-config.yaml .
COPY ./migrations ./migrations
COPY ./init.sh .

USER node
ENV NODE_ENV="production"
CMD ["node", "dist/index.js"]

CMD ["/bin/sh", "init.sh"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
## How to run

1. Install Node.js and npm
2. Install dependencies: `npm install`
2. Install dependencies: `yarn install`
3. Create config file for local overrides: `cp app-config.yaml app-config.local.yaml`
4. Build: `npm run build`
5. Run: `npm run start`
4. Build: `yarn build`
5. Run: `yarn start`

## Configuration

Expand Down
2 changes: 1 addition & 1 deletion app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ logging:
database: info

database:
dsn: 'postgres://postgres:pass@localhost:5432/codex-notes'
dsn: 'postgres://codex:postgres@postgres:5432/notes'

openai:
token: 'token'
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.2"
services:
api:
build:
dockerfile: Dockerfile
context: .
ports:
- 127.0.0.1:1337:1337
volumes:
- ./app-config.yaml:/usr/app/app-config.yaml
restart: unless-stopped

postgres:
image: postgres
environment:
POSTGRES_USER: codex
POSTGRES_DB: notes
POSTGRES_PASSWORD: postgres
ports:
- 127.0.0.1:5432:5432
volumes:
- ./database:/var/lib/postgresql/data
4 changes: 4 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
node dist/repository/storage/postgres/migrations/index.js -c app-config.yaml
node dist/index.js
Loading

0 comments on commit 5e9779b

Please sign in to comment.