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

676 libms commander error on windows #888

Merged
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
31493e2
changes test to be independent of the files order
nichlaes Aug 20, 2024
5f3273e
Update lib-ms.yml
nichlaes Aug 20, 2024
a3c0d83
Update lib-ms.yml
nichlaes Aug 20, 2024
11b82d8
adds windows path restraint
nichlaes Aug 23, 2024
8c4f5ef
Merge branch '676-libms-commander-error-on-windows' of https://github…
nichlaes Aug 23, 2024
89418d8
commented out failing tests on action
nichlaes Aug 23, 2024
68ee7c3
bumped version to 0.4.6
nichlaes Aug 26, 2024
36a6e3c
adds docker compose to docs
nichlaes Aug 26, 2024
f423c56
windows path needs to be relative
nichlaes Aug 26, 2024
acc3798
lint fixes
nichlaes Aug 26, 2024
fb7ded8
Revert "windows path needs to be relative"
nichlaes Sep 2, 2024
1e3dba1
Revert "adds windows path restraint"
nichlaes Sep 2, 2024
5b95d9c
adds absolute path support for windows
nichlaes Sep 3, 2024
587d14d
updated packages
nichlaes Sep 4, 2024
d0e0e71
fixed lint errors
nichlaes Sep 4, 2024
e383420
adds cases for cloudCMD and pm2
nichlaes Sep 9, 2024
b49264f
fixed linting
nichlaes Sep 9, 2024
32360de
Revert "commented out failing tests on action"
nichlaes Sep 9, 2024
3e33a08
adds delay for server to get ready when running on github
nichlaes Sep 11, 2024
229a403
increased sleep
nichlaes Sep 11, 2024
f4fe9dc
removed paths error
nichlaes Sep 11, 2024
fe1da46
debug error actions
nichlaes Sep 11, 2024
3bf3a49
error only if env are not set
nichlaes Sep 11, 2024
c25dfc3
changed test url
nichlaes Sep 11, 2024
632cf1d
verify url works
nichlaes Sep 11, 2024
69e97c8
testing tests
nichlaes Sep 11, 2024
a6dde57
tests without pm2
nichlaes Sep 11, 2024
0e39a8c
installs jest
nichlaes Sep 11, 2024
b329235
.
nichlaes Sep 11, 2024
ce7ce03
changed port and order
nichlaes Sep 12, 2024
e858e5f
changed order
nichlaes Sep 12, 2024
d98549a
ignores bootstrap.ts
nichlaes Sep 12, 2024
ea69a01
fixed deprecated func
nichlaes Sep 12, 2024
15d3745
removes temp tests
nichlaes Sep 12, 2024
d359c6d
adds check for server running
nichlaes Sep 13, 2024
18326ee
set working directory
nichlaes Sep 16, 2024
7a9a2aa
updated docs
nichlaes Sep 16, 2024
182e8cb
code climate fix
nichlaes Sep 16, 2024
f33f257
removes console log
nichlaes Sep 16, 2024
5f8368f
adds local compose file
nichlaes Sep 16, 2024
0b555a3
specify code block language
nichlaes Sep 16, 2024
05d0f01
Improves DEVELOPER.md
prasadtalasila Sep 16, 2024
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
63 changes: 42 additions & 21 deletions .github/workflows/lib-ms.yml
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ on:
paths:
- 'servers/lib/**'
workflow_dispatch:
paths:
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
- 'servers/lib/**'

jobs:
test-lib-ms:
name: Test library microservice
runs-on: ubuntu-latest
defaults:
run:
working-directory: servers/lib

steps:
- name: Checkout
Expand All @@ -27,47 +28,67 @@ jobs:
cache: "yarn"
cache-dependency-path: "**/yarn.lock"

# - name: Install pm2
# run: |
# npm install -g pm2
- name: Install pm2 and jest
run: |
npm install -g pm2
npm install -g jest

- name: Run the linting checks
run: |
cd servers/lib
yarn install
yarn syntax

- name: Build the lib microservice
run: |
cd servers/lib
yarn install
yarn build

- name: Run all tests
env:
PORT: 4001
LOCAL_PATH: ${{ github.workspace }}/files
MODE: local
LOG_LEVEL: debug
APOLLO_PATH: /lib
run: |
cd servers/lib
yarn install
yarn build
yarn test:all

- name: Start http mode
env:
PORT: 4001
PORT: 4003
LOCAL_PATH: ${{ github.workspace }}/files
MODE: local
LOG_LEVEL: debug
APOLLO_PATH: /lib
run: |
yarn install
yarn build
yarn start:pm2

- name: Check server is running
env:
PORT: 4003
uses: nick-fields/retry@v3
with:
timeout_seconds: 10
max_attempts: 4
command: "curl -f -LI http://localhost:${{ env.PORT }}/lib/files"

- name: Run http test
env:
PORT: 4003
LOCAL_PATH: ${{ github.workspace }}/files
MODE: local
LOG_LEVEL: debug
APOLLO_PATH: /lib
run: |
yarn test:http-github

# - name: Run http mode tests
# run: |
# cd servers/lib
# yarn install
# yarn build
# yarn test:http-github
# env:
# PORT: 4002
# LOCAL_PATH: ${{ github.workspace }}/files
# MODE: local
# LOG_LEVEL: debug
# APOLLO_PATH: /lib
- name: Stop http mode
run: |
yarn stop:pm2

- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
52 changes: 52 additions & 0 deletions servers/lib/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ The URL endpoint for this microservice is located at: `localhost:PORT/lib`

The [API](./API.md) page shows sample queries and responses.

## Manual testing

As of now, some features require manual testing or attention.

### CloudCMD (a npm package dependency)

Due to how CloudCMD works,
it is required to manually test with `LOCAL_PATH` both as an
prasadtalasila marked this conversation as resolved.
Show resolved Hide resolved
absolute path and local path.

| OS | Absolute Path | Relative Path |
| ------- | ----------------------------- | ------------- |
| Windows | C:\DTaaS\files | ..\\..\files |
| Linux | /Users/<Username>/DTaaS/files | ../../files |

### PM2

the pm2 might not close spawned processes correctly,
therefore please use the following command to kill a process.
`pm2 del <id>`.

**NOTE:** to see the processes spawned by pm2 use `pm2 list`

## :package: :ship: Packages

### Docker images
Expand Down Expand Up @@ -86,6 +109,35 @@ with publishing **libms npm package** in local computer.
Application of the advice given on that page for **libms** will require
running the following commands.

## Use in Docker Environment

### Adjust Configuration (Optional)

The microservices require configuration and the docker version
of the microservices uses the configuration
file available in `config/.env.default`.
If you would like to adjust the configuration, please change this file.

### Use

The commands to start and stop the appliation are:

**NOTE**: the docker compose file is located in the `servers/lib` directory.

```bash
docker compose -f compose.lib.dev.yml up -d
```

This command brings up the lib docker container and makes
the website available at <http://localhost:4001>.
The `config/.env.default` file is used as the microservice configuration.
If the configuration values are changed, please restart the container.

```bash
docker compose -f compose.lib.yml down
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
docker compose -f compose.lib.yml up -d
```

### Publish

```bash
Expand Down
31 changes: 31 additions & 0 deletions servers/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,37 @@ your Github username and the password is your Github
In order for the npm to download the package, your personal access token
needs to have _read:packages_ scope.

## Use in Docker Environment

### Adjust Configuration (Optional)

The microservices require configuration,
see the [Configure](#gear-configure) section for more info.

The docker version of the microservices uses the configuration
prasadtalasila marked this conversation as resolved.
Show resolved Hide resolved
file available in `config/.env.default`.
If you would like to adjust the configuration, please change this file.

### Use

The commands to start and stop the appliation are:

```bash
git clone https://github.com/INTO-CPS-Association/DTaaS.git
cd servers/lib
docker compose -f compose.lib.yml up -d
```

This command brings up the lib docker container and makes
the website available at <http://localhost:4001>.
The `config/.env.default` file is used as the microservice configuration.
If the configuration values are changed, please restart the container.

```bash
docker compose -f compose.lib.yml down
docker compose -f compose.lib.yml up -d
```

## :gear: Configure

The microservices requires config specified in INI format.
Expand Down
11 changes: 11 additions & 0 deletions servers/lib/compose.lib.dev.yml
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'
services:
libms:
build:
context: ../../
dockerfile: ./docker/libms.dockerfile
restart: unless-stopped
volumes:
- ./files:/dtaas/libms/files
nichlaes marked this conversation as resolved.
Show resolved Hide resolved
ports:
- "4001:4001"
3 changes: 2 additions & 1 deletion servers/lib/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"node_modules",
"./dist",
"../src/app.module.ts",
"../src/main.ts"
"../src/main.ts",
"../src/bootstrap.ts"
],
"modulePathIgnorePatterns": ["config"],
"coverageDirectory": "<rootDir>/coverage/",
Expand Down
12 changes: 6 additions & 6 deletions servers/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@into-cps-association/libms",
"version": "0.4.5",
"version": "0.4.6",
"description": "microservices that handles request by fetching and returning the file-names and folders of given directory",
"author": "[email protected]",
"contributors": [
Expand All @@ -11,21 +11,21 @@
"private": false,
"license": "SEE LICENSE IN <LICENSE.md>",
"scripts": {
"build": "npx tsc",
"build": "tsc",
"clean": "npx rimraf build node_modules coverage dist src.svg test.svg",
"format": "prettier --ignore-path ../.gitignore --write \"**/*.{ts,tsx,css,scss}\"",
"graph": "npx madge --image src.svg src && npx madge --image test.svg test",
"start": "node dist/src/main.js",
"start:pm2": "pm2 start pm2.config.js",
"stop:pm2": "pm2 delete libms",
"syntax": "npx eslint . --fix",
"syntax": "eslint . --fix",
"pretest": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/README.md",
"posttest": "npx rimraf ../../files/user2/tools/README.md",
"test:all": "npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage",
"test:e2e": "npx cross-env LOCAL_PATH=test/data jest --config ./test/jest-e2e.json --coverage",
"test:http": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms-test",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command, when executed on git-bash of Windows 11, is giving the following error.

$ yarn test:http
yarn run v1.22.19
$ yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage --coverageThreshold="{}" && pm2 delete libms-test
$ tsc
[PM2] Starting C:\Users\au598657\git\DTaaS\servers\lib\dist\src\main.js in fork_mode (1 instance)
[PM2] Done.
┌────┬───────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name          │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼───────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ libms-test    │ default     │ 0.4.6   │ fork    │ 28440    │ 0s     │ 0    │ online    │ 9.3%     │ 54.8mb   │ au598657 │ disabled │
└────┴───────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
  console.log
    {
      path: '/',
      files: [
        {
          name: 'common',
          size: '0b',
          date: '08.04.2024',
          owner: 0,
          mode: 'rw- rw- rw-',
          type: 'directory'
        },
        {
          name: 'template',
          size: '0b',
          date: '18.06.2024',
          owner: 0,
          mode: 'rw- rw- rw-',
          type: 'directory'
        },
        {
          name: 'user1',
          size: '0b',
          date: '11.12.2023',
          owner: 0,
          mode: 'rw- rw- rw-',
          type: 'directory'
        },
        {
          name: 'user2',
          size: '0b',
          date: '11.12.2023',
          owner: 0,
          mode: 'rw- rw- rw-',
          type: 'directory'
        },
        {
          name: 'README.md',
          size: '180b',
          date: '11.12.2023',
          owner: 0,
          mode: 'rw- rw- rw-',
          type: 'file'
        },
        {
          name: 'test.txt',
          size: '12b',
          date: '11.09.2024',
          owner: 0,
          mode: 'rw- rw- rw-',
          type: 'file'
        }
      ]
    }

      at Object.<anonymous> (test/cloudcmd/cloudcmd.spec.ts:27:13)

 PASS  test/cloudcmd/cloudcmd.spec.ts (10.616 s)
  cloudcmd test for the application
    √ should return the correct directory that is set as root (103 ms)
    √ should return the content of a file that is uplaoded to cloudcmd  (5 ms)
    √ should upload a file to cloudcmd (30 ms)

---------------------------|---------|----------|---------|---------|-------------------
File                       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------|---------|----------|---------|---------|-------------------
All files                  |       0 |        0 |       0 |       0 |
 src                       |       0 |        0 |       0 |       0 |
  bootstrap.ts             |       0 |        0 |       0 |       0 | 1-36
  types.ts                 |       0 |      100 |       0 |       0 | 1-91
 src/cloudcmd              |       0 |        0 |       0 |       0 |
  cloudcmd.ts              |       0 |        0 |       0 |       0 | 2-40
 src/files                 |       0 |      100 |     100 |       0 |
  files.module.ts          |       0 |      100 |     100 |       0 | 1-9
 src/files/resolvers       |       0 |      100 |       0 |       0 |
  files.resolver.ts        |       0 |      100 |       0 |       0 | 1-21
 src/files/services        |       0 |        0 |       0 |       0 |
  files-service.factory.ts |       0 |        0 |       0 |       0 | 1-20
  local-files.service.ts   |       0 |        0 |       0 |       0 | 1-62
---------------------------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        17.925 s
Ran all test suites matching /test\\cloudcmd/i.
[PM2] Applying action deleteProcessId on app [libms-test](ids: [ 0 ])
[PM2] [libms-test](0) ✓
┌────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Done in 22.34s.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nichlaes has problem been resolved?

Copy link
Collaborator Author

@nichlaes nichlaes Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prasadtalasila Is that an error? Is it not just the console.log?

"test:http-nocov": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage=false && pm2 delete libms-test",
"test:http-github": "yarn build && yarn start:pm2 && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms",
"test:http-github": "jest test/cloudcmd --coverage --coverageThreshold=\"{}\"",
"test:int": "npx cross-env LOCAL_PATH=test/data jest ../test/integration --coverage",
"test:nocov": "yarn test:http-nocov && npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage=false",
"test:unit": "npx cross-env LOCAL_PATH=test/data jest ../test/unit --coverage"
Expand Down Expand Up @@ -59,8 +59,8 @@
"@types/jest": "^29.5.12",
"@types/node": "20.12.5",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"cross-fetch": "^4.0.0",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand Down
2 changes: 1 addition & 1 deletion servers/lib/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function bootstrap(options?: BootstrapOptions) {
path: options?.config ?? '.env',
override: true,
});
if (configFile.error) {
if (configFile.error && process.env.LOCAL_PATH === undefined) {
// eslint-disable-next-line no-console
console.error(configFile.error);
if (options.runHelp) {
Expand Down
12 changes: 10 additions & 2 deletions servers/lib/src/cloudcmd/cloudcmd.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { INestApplication } from '@nestjs/common';
import { Server } from 'socket.io';
import * as cloudcmd from 'cloudcmd';
import { join } from 'path';
import { join, relative } from 'path';

const isWindowsAbsolutePath = (filesPath: string) => filesPath.includes(':');

const runCloudCMD = (
app: INestApplication,
Expand All @@ -13,7 +15,13 @@ const runCloudCMD = (
configPath: join(process.cwd(), optionsPath),
});

configManager('root', filesPath);
if (isWindowsAbsolutePath(filesPath)) {
const workDir = process.cwd();
const relativePath = relative(workDir, filesPath);
configManager('root', relativePath);
} else {
configManager('root', filesPath);
}

const server = app.getHttpServer();

Expand Down
2 changes: 1 addition & 1 deletion servers/lib/src/files/services/local-files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class LocalFilesService implements IFilesService {

return LocalFilesService.formatResponse(name, content);
} catch (error) {
throw new InternalServerErrorException('Error reading file');
throw new InternalServerErrorException('Error reading file', error);
}
}

Expand Down
7 changes: 4 additions & 3 deletions servers/lib/test/cloudcmd/cloudcmd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ describe('cloudcmd test for the application', () => {
console.log(response.data);
/* eslint-enable no-console */
expect(response.data.path).toEqual('/');
expect(response.data.files[0].name).toEqual('common');
expect(response.data.files[1].name).toEqual('user1');
expect(response.data.files[2].name).toEqual('user2');
const fileNames = response.data.files.map((file) => file.name);
expect(fileNames).toContain('common');
expect(fileNames).toContain('user1');
expect(fileNames).toContain('user2');
}, 10000);

it('should return the content of a file that is uplaoded to cloudcmd ', async () => {
Expand Down
2 changes: 1 addition & 1 deletion servers/lib/test/unit/files-service.factory.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ describe('FilesServiceFactory', () => {

it('should throw an error when MODE is invalid', () => {
jest.spyOn(configService, 'get').mockReturnValue('invalid');
expect(() => serviceFactory.create()).toThrowError(`Invalid MODE: invalid`);
expect(() => serviceFactory.create()).toThrow(`Invalid MODE: invalid`);
});
});
Loading
Loading