Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using pnpm, compose watch #3

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.gitignore
.github
*.md
dist
tests
node_modules
14 changes: 0 additions & 14 deletions .eslintignore

This file was deleted.

8 changes: 0 additions & 8 deletions .eslintrc.json

This file was deleted.

10 changes: 0 additions & 10 deletions .github/actions/lint/action.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/actions/test/action.yml

This file was deleted.

58 changes: 21 additions & 37 deletions .github/workflows/pull_request.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,29 @@ name: Pull request checks
on: [pull_request]

jobs:
lint:
name: Lint
unit-tests:
name: unit Tests
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v3
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
- name: Install repository
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
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
version: 9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: "18"
- uses: ./.github/actions/lint
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Install dependencies
run: pnpm install

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
- name: Run test
run: pnpm test
50 changes: 0 additions & 50 deletions .github/workflows/push_master.workflow.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2015"
},
"module": {
"type": "commonjs"
},
"exclude": [
"node_modules",
"dist"
]
}
43 changes: 23 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
# Builder stage
FROM kuzzleio/kuzzle-runner:18 AS builder
FROM kuzzleio/kuzzle-runner:20 AS base

WORKDIR /var/app
ARG KUZZLE_ENV="local"
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

COPY . .
COPY . /app
WORKDIR /app

FROM base AS dev-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

RUN npm install
RUN npm run build
RUN npm prune --production
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

# Final image
FROM node:18-bullseye-slim
FROM base AS build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile && pnpm run build

ARG KUZZLE_ENV="local"
ARG KUZZLE_VAULT_KEY=""
FROM node:20-slim AS prod

WORKDIR /app

# Uncomment if you want to use the Kuzzle Vault
# See https://docs.kuzzle.io/core/2/guides/advanced/secrets-vault
# ARG KUZZLE_VAULT_KEY
# ENV KUZZLE_VAULT_KEY=$KUZZLE_VAULT_KEY
# ENV KUZZLE_SECRETS_FILE="/var/app/secrets.enc.json"
ARG KUZZLE_ENV="local"

ENV NODE_ENV=production

COPY --from=builder /var/app/dist /var/app
COPY --from=builder /var/app/node_modules /var/app/node_modules
COPY --from=builder /var/app/package.json /var/app/package.json
COPY --from=builder /var/app/package-lock.json /var/app/package-lock.json
COPY --from=builder /var/app/environments/${KUZZLE_ENV}/kuzzlerc /var/app/.kuzzlerc
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist
COPY --from=build /app/environments/${KUZZLE_ENV}/kuzzlerc /app/.kuzzlerc

WORKDIR /var/app
EXPOSE 7512

CMD [ "node", "app.js" ]
CMD [ "node", "dist/app.js" ]
36 changes: 9 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,28 @@ Check out our [support plans](https://kuzzle.io/pricing/).
## Installation and run

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

# Usage

```bash
docker compose up -d
docker compose watch
```

## Use the framework

Your first Kuzzle application is inside the `app.ts` file.

For example, you can add a new [API Controller](https://docs.kuzzle.io/core/2/guides/develop-on-kuzzle/api-controllers):
Your first Kuzzle application is inside the `app.ts` file. This will be the entry point of your application.

```ts
import { Backend } from 'kuzzle';

const app = new Backend('playground');

app.controller.register('greeting', {
actions: {
sayHello: {
handler: async request => `Hello, ${request.input.args.name}`
}
}
});

app.start()
.then(() => {
app.log.info('Application started');
})
.catch(console.error);
```
import { MyApplication } from "./lib/MyApplication";

Now try to call your new API action by:
- opening the generated URL in your browser: http://localhost:7512/_/greeting/say-hello?name=Yagmur
- using Kourou: `npx kourou greeting:sayHello --arg name=Yagmur`
const app = new MyApplication();

app.start();
```

Learn how to [Write an Application](https://docs.kuzzle.io/core/2/guides/getting-started/write-application/).

Expand Down Expand Up @@ -103,7 +85,7 @@ Our teams will be able to meet your needs in terms of expertise and multi-techno
* Follow us on [twitter](https://twitter.com/kuzzleio) to get latest news
* Register to our monthly [newsletter](http://eepurl.com/bxRxpr) to get highlighed news
* Visit our [blog](https://blog.kuzzle.io/) to be informed about what we are doing
* Come chat with us on [Discord](http://join.discord.kuzzle.io)
* Come chat with us on [Discord](https://join.discord.kuzzle.io)
* Ask technical questions on [stack overflow](https://stackoverflow.com/search?q=kuzzle)

## License
Expand Down
25 changes: 14 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
version: "3"

services:
api:
image: kuzzleio/kuzzle-runner:18
command: sh /var/app/start.sh api
volumes:
- .:/var/app
- ~/.npmrc:/root/.npmrc
build:
dockerfile: Dockerfile
context: .
target: dev-deps
command: pnpm watch
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
Expand All @@ -30,6 +24,15 @@ services:
timeout: 5s
interval: 5s
retries: 30
develop:
watch:
- action: sync+restart
path: ./lib
target: /app/lib
ignore:
- node_modules/
- action: rebuild
path: package.json

redis:
image: redis:5
Expand Down
13 changes: 0 additions & 13 deletions ergol.config.json

This file was deleted.

7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
},
extensionsToTreatAsEsm: [".ts", ".tsx"],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
};
8 changes: 0 additions & 8 deletions jest.config.ts

This file was deleted.

Loading