From 81a49c8d751c12b4a91ff6467247aca2d0c13ce2 Mon Sep 17 00:00:00 2001 From: fed <charles-francis.damedey@savoirfairelinux.com> Date: Mon, 29 May 2023 17:09:11 -0400 Subject: [PATCH] misc: add Dockerfile GitLab: #1 Change-Id: If58557b5d9679a74d00a6dca497f26789c747a12 --- Dockerfile | 16 +++++++++ README.md | 90 +++++++++++++++++++++++++++++++++++++++++++++--- api/package.json | 3 +- documentation.md | 2 +- 4 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5aa7bac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Stage 1: Base Image +FROM node:18-alpine as base +WORKDIR /api +COPY package*.json ./ +RUN npm install +COPY . . +ENV DATA_DIRECTORY=/data + +# Stage 2: Final Image for running the server +FROM base as server +EXPOSE 3000 +CMD ["npm", "run", "start"] + +# Stage 3: Final Image for running the tests +FROM base as test +CMD ["npm", "run", "test"] \ No newline at end of file diff --git a/README.md b/README.md index 5f50be6..750046c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,98 @@ -# Plugin Store +# Plugins Store The idea is to provide the user a quick way to discover and install plugins via the plugin store. +# Prerequisites + ++ npm ++ Node.js 18.16+ ++ Docker + +# Installation of Node.js 18.16 + +how to install Node.js 18.16 with nvm + +`$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash` + +`$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash` + +`$ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"\n[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm` + +`$ command -v nvm` + +how to install Node.js 18.16 with nvm + +`$ nvm install 18.16.0` + +# Scripts + +run the server + +`$ npm run start` + +lint + +`$ npm run lint` + +fix the linting + +`$ npm run fix` + +run tests and see code coverage + +`$ npm run test` + +# Send API requests + +### Get all plugins + +`$ curl -X GET http://localhost:3000/` + +### Get a plugin's details + +`$ curl -X GET http://localhost:3000/details/AudioFilter` + +### Download a plugin by its id + +`$ curl -X GET http://localhost:3000/download/AudioFilter.jpl` + # Contributing -We have a set of ESLint rules that define clear syntax rules (web/.eslintrc.json). You will need the following tools: +We have a set of ESLint rules that define clear syntax rules (/.eslintrc.json). You will need the following tools: -* ESLint (The pluggable linting utility for JavaScript and JSX) https://eslint.org/ +* ESLint (https://eslint.org/) We will not accept patches introducing non-ESLint-compliant code. -## Linting via pre-commit hook +# Docker + +To install Docker please read this manual: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository + +The Docker needs a data directory to store the plugins. You need a /data/ folder in your repo. The API will look for the plugins in this folder. This is a temporary situation until we have a database implemented. + +Build a docker image: + +`docker build -t server-image --target server .` + + +Run the docker container: + +`docker run -p 3000:3000 -ti server-image` + + +To stop the container do CTRL + C in the terminal. + +To run tests in the docker container + +Build the test image: + +`docker build -t test-image --target test .` + +Run the test image: + +`docker run test-image` + +# Linting via pre-commit hook Set up the pre-commit hook: diff --git a/api/package.json b/api/package.json index 4d31773..5b15b9d 100644 --- a/api/package.json +++ b/api/package.json @@ -7,7 +7,8 @@ "start": "ts-node index.ts", "build": "tsc", "lint": "eslint . --ext .ts", - "fix": "eslint . --ext .ts --fix" + "fix": "eslint . --ext .ts --fix", + "build": "tsc" }, "author": "", "license": "ISC", diff --git a/documentation.md b/documentation.md index 55d8f3d..a776380 100644 --- a/documentation.md +++ b/documentation.md @@ -15,7 +15,7 @@ The endpoint to retrieve the list of plugins needs to support a per-page query p ### Code Example ```http -GET /plugins/ +GET ``` Successful response: -- GitLab