Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rolljee committed Oct 9, 2023
1 parent 54c2661 commit c900b77
Show file tree
Hide file tree
Showing 21 changed files with 11,399 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# JS generated files from TS
dist/**/*

app.js
app.d.ts
app.js.map
lib/**/*.d.ts
lib/**/*.js.map
lib/**/*.js


# tests
features/**/*.js
form/
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": ["kuzzle"],
"extends": [
"plugin:kuzzle/default",
"plugin:kuzzle/node",
"plugin:kuzzle/typescript"
]
}
11 changes: 11 additions & 0 deletions .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Backend - ESLint
description: Run ESLint for backend
runs:
using: "composite"
steps:
- name: run backend lint
shell: bash
run: |
cd backend
npm ci
npm run lint
10 changes: 10 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Backend - Functional Tests
description: Run Functional Tests for backend
runs:
using: "composite"
steps:
- name: Run backend functional test
shell: bash
run: |
npm ci
npm run test
47 changes: 47 additions & 0 deletions .github/workflows/pull_request.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Pull request checks

on: [pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v3
with:
node-version: "18"
- uses: ./.github/actions/lint

functional-tests:
name: Functional Tests
runs-on: ubuntu-22.04
needs: [lint]
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v3
with:
node-version: "18"
- uses: ./.github/actions/test
50 changes: 50 additions & 0 deletions .github/workflows/push_master.workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Push checks

on:
push:
branches:
- master

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v3
with:
node-version: "18"
- uses: ./.github/actions/lint

functional-tests:
name: Functional Tests
runs-on: ubuntu-22.04
needs: [lint]
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v3
with:
node-version: "18"
- uses: ./.github/actions/test
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Node
*.log
node_modules/

# Other
.DS_STORE
*#
*~

# Build files
dist/**/*
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM kuzzleio/kuzzle-runner:16 as builder

ADD . /var/app

WORKDIR /var/app

RUN npm ci
RUN npm run build

FROM kuzzleio/kuzzle-runner:16 as prepare

WORKDIR /var/app
ENV NODE_ENV=production

COPY --from=builder /var/app/package*.json /var/app/.npmrc* /var/app/dist ./
RUN npm install --production

# Final image
FROM node:16-stretch-slim as production

ARG KUZZLE_VAULT_KEY
ENV KUZZLE_VAULT_KEY=$KUZZLE_VAULT_KEY

ENV NODE_ENV=production

WORKDIR /var/app

COPY --from=prepare /var/app/ ./

CMD [ "node", "app.js" ]
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# template-kuzzle-project
Official template for a new kuzzle project
# Kuzzle Application

_An application running with [Kuzzle](https://github.com/kuzzleio/kuzzle)_

## Installation and run

Requirement:
- Node.js = 18
- NPM = 10.1.0
- Docker
- Docker-Compose

First, install [Kourou](https://github.com/kuzzleio/kourou), the Kuzzle CLI: `npm install -g kourou`

# Usage

```bash
docker compose up -d
```
5 changes: 5 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MyApplication } from "./lib/MyApplication";

const app = new MyApplication();

app.start();
55 changes: 55 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: "3"

services:
api:
image: kuzzleio/kuzzle-runner:18
command: sh /var/app/start.sh api
volumes:
- .:/var/app
- ~/.npmrc:/root/.npmrc
depends_on:
redis:
condition: service_healthy
elasticsearch:
condition: service_healthy
ports:
- "7512:7512"
- "7511:7511"
- "7510:7510"
- "9229:9229"
- "1883:1883"
environment:
- kuzzle_services__storageEngine__client__node=http://elasticsearch:9200
- kuzzle_services__storageEngine__commonMapping__dynamic=true
- kuzzle_services__internalCache__node__host=redis
- kuzzle_services__memoryStorage__node__host=redis
- NODE_ENV=${NODE_ENV:-development}
- DEBUG=${DEBUG:-none}
healthcheck:
test: ["CMD", "curl", "-f", "http://api:7512/_healthcheck"]
timeout: 5s
interval: 5s
retries: 30

redis:
image: redis:5
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 30

elasticsearch:
image: kuzzleio/elasticsearch:7
volumes:
- "/tmp/snapshots:/tmp/snapshots"
ports:
- "9200:9200"
- "9300:9300"
healthcheck:
test: ["CMD", "curl", "-f", "http://elasticsearch:9200"]
interval: 5s
timeout: 5s
retries: 30
13 changes: 13 additions & 0 deletions ergol.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"killDelay": "5000",
"nodeArgs": [
"--inspect=0.0.0.0:9229",
"-r",
"ts-node/register"
],
"watch": [
"app.ts",
"lib",
"node_modules"
]
}
8 changes: 8 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
moduleDirectories: ["node_modules", "lib"],
moduleNameMapper: {
"^lib/(.*)$": "<rootDir>/lib/$1",
},
preset: "ts-jest",
testEnvironment: "node",
};
38 changes: 38 additions & 0 deletions lib/MyApplication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Backend } from "kuzzle";
import { PrometheusPlugin } from "kuzzle-plugin-prometheus";

export type MyApplicationConfig = {
someValue: string;

another: {
value: number;
};
};

export class MyApplication extends Backend {
public configuration: MyApplicationConfig;
private prometheusPlugin = new PrometheusPlugin();

get appConfig() {
return this.config.content.application as MyApplicationConfig;
}

constructor(config?: MyApplicationConfig) {
super("my-application");

if (config) {
this.configuration = config;
} else {
this.configuration = this.config.content
.application as MyApplicationConfig;
}

this.plugin.use(this.prometheusPlugin);
}

async start() {
await super.start();

this.log.info("Application started");
}
}
Empty file added lib/modules/index.ts
Empty file.
Loading

0 comments on commit c900b77

Please sign in to comment.