Skip to content

Commit

Permalink
feat: migrate project to NestJS. (#149)
Browse files Browse the repository at this point in the history
* feat: migrate project to NestJS.

* feat: update github-actions

- lint project
- update tests
- update github-actions

* fix: fix scripts

* fix: update script permissions

* fix: make scripts executable

* chore: add docs and test permissions

* feat: add tests for location search

* feat: add Dockerfile

* feat: add e2e tests

* fix: fix tests

* fix: fix scripts and Dockerfile

Signed-off-by: 35C4n0r <jaykumar20march@gmail.com>

* fix: fix city.service.spec.ts test.

Signed-off-by: 35C4n0r <jaykumar20march@gmail.com>

---------

Signed-off-by: 35C4n0r <jaykumar20march@gmail.com>
  • Loading branch information
35C4n0r authored Jul 22, 2024
1 parent 319458b commit 15ab9c1
Show file tree
Hide file tree
Showing 69 changed files with 24,447 additions and 1,578 deletions.
File renamed without changes.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
31 changes: 13 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@ on:
jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 20.x ]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: ./geoip # Set the path to your project root directory

- name: Setup Bun
uses: oven-sh/setup-bun@v1
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
bun-version: 1.0.23


- name: Install dependencies
run: ./setup.sh
working-directory: ./geoip/server # Set the working directory to your project root

- name: Run bun test
run: bun test
working-directory: ./geoip/server # Set the working directory to your project root
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- run: npm i
- run: ./setup.sh
- run: npm run test
- run: npm run test:e2e
58 changes: 29 additions & 29 deletions .github/workflows/update-mmdb.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# name: Download and Commit File

# on:
# schedule:
# - cron: '0 12 * * 0' # This will run the action daily at midnight
# workflow_dispatch: # This allows manual triggering

# jobs:
# download-and-commit:
# runs-on: ubuntu-latest

# permissions:
# # Give the default GITHUB_TOKEN write permission to commit and push the
# # added or changed files to the repository.
# contents: write

# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
# - name: Download File
# run: |
# sudo apt install wget2 -y
# wget2 -O server/db.mmdb https://mmdbcdn.posthog.net

# - name: Commit and Push
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_message: Update db.mmdb
#name: Download and Commit File
#
#on:
# schedule:
# - cron: '0 12 * * 0' # This will run the action daily at midnight
# workflow_dispatch: # This allows manual triggering
#
#jobs:
# download-and-commit:
# runs-on: ubuntu-latest
#
# permissions:
# # Give the default GITHUB_TOKEN write permission to commit and push the
# # added or changed files to the repository.
# contents: write
#
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
#
# - name: Download File
# run: |
# sudo apt install wget2 -y
# wget2 -O server/db.mmdb https://mmdbcdn.posthog.net
#
# - name: Commit and Push
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_message: Update db.mmdb
54 changes: 47 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
node_modules
# compiled output
/dist
/node_modules

src/config/env
src/geojson-data/indian_village_boundaries
src/geojson-data/*json

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

.idea
.DS_store
server/.DS_Store
/server/geojson-data/indian_village_boundaries
/server/geojson-data/*json
/server/parsed_geojson
/server/scripts/combined.log
/server/scripts/error.log
/server/combined.log
src/.DS_Store
/src/parsed_geojson
/src/scripts/combined.log
/src/scripts/error.log
/src/combined.log
/src/geojson-data/
/src/geoquery.in.data/
db.mmdb
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
78 changes: 78 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#FROM node:18.16.1-alpine
#
#COPY setup.sh
#
#RUN apk add --no-cache bash
#RUN npm i -g @nestjs/cli typescript ts-node
#
#COPY package*.json /tmp/app/
#RUN cd /tmp/app && npm install
#
#COPY . /usr/src/app
#RUN cp -a /tmp/app/node_modules /usr/src/app
#COPY ./wait-for-it.sh /opt/wait-for-it.sh
#COPY ./startup.dev.sh /opt/startup.dev.sh
#RUN sed -i 's/
#//g' /opt/wait-for-it.sh
#RUN sed -i 's/
#//g' /opt/startup.dev.sh
#
#WORKDIR /usr/src/app
#RUN cp env-example .env
#RUN npx prisma generate
#RUN npm run build
#
#CMD ["/opt/startup.dev.sh"]
#
#EXPOSE 3000


#FROM node:18.16.1-alpine
#
#WORKDIR /usr/src/app
#
#COPY . .
#
#RUN apt-get update && apt-get install -y curl && apt-get install -y git
#CMD /bin/bash
#COPY ./package*.json ./
#RUN ./setup.sh
#
#ENV NODE_ENV production
#CMD ["npm", "i"]
#CMD [ "npm", "run", "start:dev" ]
#
#EXPOSE 3000


FROM node:20.11.0-alpine

# Set the working directory
WORKDIR /usr/src/app

# Install curl and git using apk
RUN apk update && apk add --no-cache curl git

RUN #npm config set registry http://registry.npmjs.org/

# Copy package files first for better caching of npm install
COPY ./package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Run any additional setup script
RUN chmod +x ./setup.sh
RUN ./setup.sh

# Set environment variable
ENV NODE_ENV production

# Expose the application port
EXPOSE 3000

# Start the application
CMD ["npm", "run", "start:dev"]
21 changes: 21 additions & 0 deletions Dockerfile.devcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:18.16.1-alpine

RUN apk add --no-cache bash
RUN npm i -g @nestjs/cli typescript ts-node

COPY package*.json /tmp/app/
RUN cd /tmp/app && npm install

COPY . /usr/src/app
RUN cp -a /tmp/app/node_modules /usr/src/app
COPY ./wait-for-it.sh /opt/wait-for-it.sh
COPY ./startup.dev.sh /opt/startup.dev.sh
RUN sed -i 's/\r//g' /opt/wait-for-it.sh
RUN sed -i 's/\r//g' /opt/startup.dev.sh

WORKDIR /usr/src/app
RUN cp env-example.devcontainer .env
RUN npx prisma generate
RUN npm run build

CMD ["/opt/startup.dev.sh"]
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
Our [vision](./vision.md).

### Example
See code example in the [server](./server/app.js) folder.
See code example in the [server](./src/main.ts) folder.

### Setup Server

Run `./setup.sh`. This script will install bun and download required files to setup server
Install Dependencies
```sh
npm i
```

Run `./setup.sh`. This script will download all the necessary files
```sh
cd server
./setup.sh
```

Start Server
```sh
bun app.js
npm run start
```

### Docker Container Setup and Usage Guide
Expand All @@ -36,18 +40,15 @@ Once Docker is installed, follow the steps below to set up and run the Docker co
```bash
git clone https://github.com/ChakshuGautam/geoquery.in
```
2. Change working dir to `server`
```bash
cd geoquery.in/server
```
4. Build the Docker image using the provided Dockerfile with the following command:

2. Build the Docker image using the provided Dockerfile with the following command:

```bash
docker build . -t geoquery
```
> Note: After adding your user to the Docker group, you can run Docker commands without using `sudo`. If you haven't added your user to the Docker group, remember to use `sudo` before Docker commands.
5. Run the Docker container using the following command:
3. Run the Docker container using the following command:
```bash
docker run -d geoquery
Expand Down
Binary file removed bun.lockb
Binary file not shown.
23 changes: 23 additions & 0 deletions docker-compose.ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
postgres:
image: postgres:15.3-alpine
expose:
- 5432:5432
environment:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}

shadow-postgres:
image: postgres:15.3-alpine
expose:
- 5431:5432
environment:
POSTGRES_USER: ${SHADOW_DATABASE_USERNAME}
POSTGRES_PASSWORD: ${SHADOW_DATABASE_PASSWORD}
POSTGRES_DB: ${SHADOW_DATABASE_NAME}

api:
build:
context: .
dockerfile: e2e.Dockerfile
Loading

0 comments on commit 15ab9c1

Please sign in to comment.