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

NoMongo: Create a setup script for the develop-postgres branch #2688

Open
palisadoes opened this issue Nov 17, 2024 · 28 comments
Open

NoMongo: Create a setup script for the develop-postgres branch #2688

palisadoes opened this issue Nov 17, 2024 · 28 comments
Assignees
Labels

Comments

@palisadoes
Copy link
Contributor

Is your feature request related to a problem? Please describe.

  1. We need a setup script to configure the new develop-postgres branch.
  2. The functionality must be equivalent to the setup script in the develop branch

Describe the solution you'd like

PRs related to setup.ts require a high degree of manual verification by our reviewers and errors are frequent.

  1. We frequently add new configuration parameters to our code base.
  2. The changes mean that the setup.ts file is always being modified.
  3. Most PRs that modify this file introduce various types of failure.

Your job is to make the execution of the setup.ts file be:

  1. foolproof
  2. intuitive to use
  3. easier and simpler to use

A tech novice or new contributor should be able to install the API without issue.

For the successful completion of this issue:

  1. Write code to thoroughly test the setup.ts file without manually inputting responses to prompts, including:
    1. all relevant functions, methods and classes where applicable.
    2. all user prompts
  2. Ensure that running the tests is a part of our existing PR and Husky git commit workflows

This may mean making changes to the setup.ts file.

Describe alternatives you've considered

  • N/A

Approach to be followed (optional)

This issue may require the refactoring of this script file to make it:

  1. Easier to test
  2. Easier to maintain

Testing must verify that the:

  1. Default values for input are correct:
    1. When a parameter is already configured
    2. When a parameter is not configured
  2. Functionality when parameters are missing from the configuration is maintained
  3. Sequencing of the prompts is maintained
  4. Configuration parameters that rely on any external APIs (eg. database, mail) must be tested.
    1. The tests don't hang when testing these APIs whether or not the API connectivity is validated
  5. Preexisting comments in the test configuration file are maintained when the final configuration is saved
  6. Final configuration isn't saved until the last question is answered. In other words, hitting CTRL-C at any point before the last question will not affect the original configuration.
  7. Wording of the prompts in all scenarios is unchanged
  8. Test database loads without issue
  9. Previously correctly answered questions are not repeated
  10. Correct values are echoed when:
    1. entered,
    2. updated or
    3. previously found in the configuration
  11. Prompts correctly bypass sections that the user doesn't want to configure.
    1. For example, there are multiple SMTP and Redis configuration parameters.
      1. Optional parameter sections: If the person installing the API doesn't want to update SMTP parameters they should be skipped, otherwise prompted
      2. Mandatory parameter sections: If the person installing the API doesn't want to update configured mandatory Redis parameters, they should be skipped, otherwise prompted
  12. Input of mandatory parameters cannot be avoided if they are not previously configured

Plus any other tests that could avoid failure based on the PR comments for the issues below.

Other items to consider include:

  1. The test file must be located in the existing tests/ directory
  2. The test file has good readability
  3. Not making any changes to files in the .github directory

Additional context

These are issues where setup has been modified and in most cases have introduced more errors:

  1. API: Flawless Installation - Write Tests for setup.ts #1680

Potential internship candidates
Please read this if you are planning to apply for a Palisadoes Foundation internship

@github-actions github-actions bot added question Further information is requested test Testing application unapproved Unapproved for Pull Request labels Nov 17, 2024
@yuvi-mittal
Copy link

can i get assigned to this issue ?

@varshith257 varshith257 removed the unapproved Unapproved for Pull Request label Nov 18, 2024
@palisadoes
Copy link
Contributor Author

@xoldd

We will need a way for people to test the application by seeing what it can do. The loading of sample data via the setup script helps a lot. It also helps with the new contributors as they can get a better understanding of the features.

We really need this. How can you facilitate this with the coding you are doing?

Copy link

github-actions bot commented Dec 4, 2024

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Dec 4, 2024
@palisadoes
Copy link
Contributor Author

Unassigning. Inactivity.

@palisadoes palisadoes assigned palisadoes and unassigned yuvi-mittal Dec 4, 2024
@palisadoes palisadoes added the wip Work in Progress label Dec 4, 2024
@prayanshchh
Copy link
Contributor

prayanshchh commented Dec 14, 2024

I would like to work on this issue, but before assigning please check with @xoldd as, in projects channel he mentioned that postgres branch shouldn't be openly collaborated right now

@PurnenduMIshra129th
Copy link

@palisadoes plz assign me. If no one assigned.

@PratapRathi
Copy link

@palisadoes please assign this issue to me.

@palisadoes
Copy link
Contributor Author

This is on hold until the develop-postgres work starts

@prayanshchh
Copy link
Contributor

as develop-postgres work has started, can I work on this?

@palisadoes palisadoes assigned prayanshchh and unassigned palisadoes Jan 12, 2025
@palisadoes palisadoes removed wip Work in Progress question Further information is requested test Testing application labels Jan 12, 2025
@github-actions github-actions bot removed the no-issue-activity No issue activity label Jan 13, 2025
@xoldd
Copy link
Contributor

xoldd commented Jan 14, 2025

@palisadoes Currently there is no need of a setup script for develop-postgres. The steps that I had shown in the video, those are minimal amount of steps. Not everything can be automated.

@palisadoes
Copy link
Contributor Author

It's necessary for the user experience of all levels of developers and sysadmins.

Going through the videos it's clear that we need a basic setup script to define most essential variables to get the app working. These include:

  1. Administrator email address
  2. Passwords
  3. Necessary Domains
  4. Necessary URLs
  5. Secrets & tokens
  6. Whether the user wants access to igraphql (development)
  7. Database name
  8. Location of log files

We will also need the option to load the most basic data into the database such as:

  1. All Environments
    1. The creation of an initial organization so that user isn't faced with a blank screen on initial login
  2. Development / Demo Environment
    1. The importation of data that provides a representation of the power of the app.
    2. The test data could also be used in test suites

All these features have been extremely useful in the past in getting new contributors on board as fast as possible without hesitation.

A setup script is necessary.

@palisadoes palisadoes changed the title Create a setup script for the develop-postgres branch NoMongo: Create a setup script for the develop-postgres branch Jan 14, 2025
@varshith257
Copy link
Member

I think if we can bit play with the manual setup without setup script and familiar with current script can solve this issue easily

@prayanshchh
Copy link
Contributor

prayanshchh commented Jan 16, 2025

I think if we can bit play with the manual setup without setup script and familiar with current script can solve this issue easily

can u elaborate your approach so that I can implement that

@varshith257
Copy link
Member

I mean the flow of the setup script needs to be similar to the current MongoDB. And you can play with Postgres setup without any setup script so that you can get familiar with everything there and easily integrate them into setup script

@palisadoes
Copy link
Contributor Author

Yes, and make sure it has tests

@palisadoes
Copy link
Contributor Author

@prayanshchh

Background

  1. This comment lists the URLs for accessing the API: 1. NoMongo:Fixing the 404 error even after having a running talawa-api talawa-admin#3266 (comment)
  2. This is not documented in the INSTALLATION.md file
  3. Talawa-Admin expects the API to be listening on port 4000. The current configuration is 8080
  4. The content below is for envFiles/.env.devcontainer
    API_BASE_URL=http://127.0.0.1:8080
    API_HOST=0.0.0.0
    API_IS_GRAPHIQL=true
    API_PORT=8080
    CI=false
    NODE_ENV=production
    API_MAPPED_HOST_IP=127.0.0.1
    API_MAPPED_PORT=8080
    CADDY_HTTP_MAPPED_PORT=80
    CADDY_HTTPS_MAPPED_PORT=443
    CADDY_HTTP3_MAPPED_PORT=443
    CADDY_TALAWA_API_DOMAIN_NAME=localhost
    CADDY_TALAWA_API_HOST=api
    CADDY_TALAWA_API_PORT=8080
    CLOUDBEAVER_ADMIN_NAME=talawa
    CLOUDBEAVER_ADMIN_PASSWORD=password
    CLOUDBEAVER_MAPPED_HOST_IP=127.0.0.1
    CLOUDBEAVER_MAPPED_PORT=8978
    CLOUDBEAVER_SERVER_NAME=Talawa CloudBeaver Server
    CLOUDBEAVER_SERVER_URL=http://127.0.0.1:8978
    
  5. The content below is for envFiles/.env.devcontainer
    API_BASE_URL=http://127.0.0.1:8080
    API_HOST=0.0.0.0
    API_IS_GRAPHIQL=false
    API_PORT=8080
    CI=true
    NODE_ENV=production
    CADDY_HTTP_MAPPED_PORT=80
    CADDY_HTTPS_MAPPED_PORT=443
    CADDY_HTTP3_MAPPED_PORT=443
    CADDY_TALAWA_API_DOMAIN_NAME=localhost
    CADDY_TALAWA_API_HOST=api
    CADDY_TALAWA_API_PORT=8080
    
  6. The content below is for envFiles/.env.devcontainer
    API_BASE_URL=
    API_HOST=0.0.0.0
    API_IS_GRAPHIQL=false
    API_PORT=8080
    CI=false
    NODE_ENV=production
    CADDY_HTTP_MAPPED_PORT=80
    CADDY_HTTPS_MAPPED_PORT=443
    CADDY_HTTP3_MAPPED_PORT=443
    CADDY_TALAWA_API_DOMAIN_NAME=
    CADDY_TALAWA_API_HOST=api
    CADDY_TALAWA_API_PORT=8080
    

Other

  1. I've opened an issue to replace all references to 8080 with 4000 for Admin compatibility. Use 4000 in your work as the default and assume the .env files will be updated to that beforehand
    1. NoMongo: Update the envFiles/ configurations to be compatible with Talawa Admin #2860
  2. You don't need to make reference to the CADDY* parameters in the script

@prayanshchh
Copy link
Contributor

alright will start work on this

@prayanshchh
Copy link
Contributor

prayanshchh commented Jan 21, 2025

started work on setup script, here's what the plan is

create a .env file, with variables:

[email protected] (default)
API_ADMINISTRATOR_USER_PASSWORD=password  (default)
API_BASE_URL=http://127.0.0.1:4000 (default)
API_DEBUGGER_HOST=0.0.0.0  (default)
API_DEBUGGER_PORT=9229  (default)
API_HOST=0.0.0.0  (default)
API_IS_APPLY_DRIZZLE_MIGRATIONS=true  (default)
API_IS_GRAPHIQL=true  (default)
API_IS_PINO_PRETTY=true  (default)
API_JWT_EXPIRES_IN=2592000000  (default)
API_JWT_SECRET=b4896453be722d5ca94058a73f52b31c75980b485fa6d74d91f417a8059d8731  (default)
API_LOG_LEVEL=debug  (default)
API_MINIO_ACCESS_KEY=talawa  (default)
API_MINIO_END_POINT=minio  (default)
API_MINIO_PORT=9000  (default)
API_MINIO_SECRET_KEY=password  (default)
API_MINIO_TEST_END_POINT=minio-test  (default)
API_MINIO_USE_SSL=false  (default)
API_PORT=4000  (default)
API_POSTGRES_DATABASE=talawa  (default)
API_POSTGRES_HOST=postgres  (default)
API_POSTGRES_PASSWORD=password  (default)
API_POSTGRES_PORT=5432  (default)
API_POSTGRES_SSL_MODE=false  (default)
API_POSTGRES_TEST_HOST=postgres-test  (default)
API_POSTGRES_USER=talawa (default)
CI=false (default) (default)
NODE_ENV=production (default)

CLOUDBEAVER_ADMIN_NAME=talawa (default)
CLOUDBEAVER_ADMIN_PASSWORD=password (default)
CLOUDBEAVER_MAPPED_HOST_IP=127.0.0.1 (default)
CLOUDBEAVER_MAPPED_PORT=8978 (default)
CLOUDBEAVER_SERVER_NAME=Talawa CloudBeaver Server (default)
CLOUDBEAVER_SERVER_URL=http://127.0.0.1:8978 (default)

MINIO_BROWSER=on (default)
MINIO_API_MAPPED_HOST_IP=127.0.0.1 (default)
MINIO_API_MAPPED_PORT=9000 (default)
MINIO_CONSOLE_MAPPED_HOST_IP=127.0.0.1 (default)
MINIO_CONSOLE_MAPPED_PORT=9001 (default)
MINIO_ROOT_PASSWORD=password (default)
MINIO_ROOT_USER=talawa (default)

POSTGRES_DB=talawa (default)
POSTGRES_MAPPED_HOST_IP=127.0.0.1 (default)
POSTGRES_MAPPED_PORT=5432 (default)
POSTGRES_PASSWORD=password (default)
POSTGRES_USER=talawa (default)

the tests will check whether postgres, minio, cloubdbeaver and api is running or not

@palisadoes
Copy link
Contributor Author

@prayanshchh

To make things easier I think you should split this into sections. For example, only go into details if the user decides not to use the recommended defaults. This will make it much faster to setup.

Do you want to use the recommended default database settings? (Y)/N 
Do you want to use the recommended default database web management settings? (Y)/N 
Do you want to use the recommended default object storage settings? (Y)/N 

Do what you can to minimize the long list of questions that need to be asked. The quicker the setup, the better.

@prayanshchh
Copy link
Contributor

alright sir

@prayanshchh
Copy link
Contributor

prayanshchh commented Jan 22, 2025

Image

this is what I see when i try to run tests using npm run run_tests
home/prayansh-chhablani/prayansh-talawa-api/docs/tsconfig.json this file exists.
already ran npm install

@palisadoes
Copy link
Contributor Author

The docs/ directory needs to be excluded. It's docusaurus specific and is used to create the website docs-api.talawa.io

@prayanshchh
Copy link
Contributor

prayanshchh commented Jan 22, 2025

Image

added ignoreConfigErrors: true, will exclude work here? i think exclude only works to ignore test files but plugins like vite-tsconfig-paths operate on the project files as a whole, for now ignore config works

  1. we do have some test file, it doesn't pick it up
  2. we don't use nodemailer anywhere

should this be a different issue?

@palisadoes
Copy link
Contributor Author

  1. I meant vitest must not be applied to the docs/ directory
  2. There are test files in the tests/ directory. Something else is wrong.

@prayanshchh
Copy link
Contributor

I was able to understand how to run tests from the github actions
do we have the ability to just run a specific test if we want to, this was possible in develop, the current config uses docker compose for tests

@prayanshchh
Copy link
Contributor

prayanshchh commented Jan 24, 2025

another point, i created test file to test my setup script, I ran the the whole test suite using docker compose

api-1            | stdout | test/setup/administratorEmail.test.ts
api-1            | 
api-1            | Please make sure to register with this email before logging in.
api-1            | 
api-1            | 
api-1            | TAP version 13
api-1            | # Subtest: Setup -> askForAdministratorEmail
api-1            |     # Subtest: should prompt the user for an email and update the email env
api-1            |     not ok 1 - should prompt the user for an email and update the email env
api-1            |       ---
api-1            |       duration_ms: 9.032558
api-1            |       type: 'suite'
api-1            |       location: '/home/talawa/api/test/setup/administratorEmail.test.ts:6:34'
api-1            |       failureType: 'testCodeFailure'
api-1            |       error: "expected '[email protected]' to be '[email protected]' // Object.is equality"
api-1            |       code: 'ERR_TEST_FAILURE'
api-1            |       name: 'AssertionError'
api-1            |       expected: '[email protected]'
api-1            |       actual: '[email protected]'
api-1            |       operator: 'strictEqual'
api-1            |       stack: |-
api-1            |         SuiteContext.<anonymous> (/home/talawa/api/test/setup/administratorEmail.test.ts:13:62)
api-1            |         processTicksAndRejections (node:internal/process/task_queues:105:5)
api-1            |         Suite.createBuild (node:internal/test_runner/test:1270:7)
api-1            |       ...
api-1            |     1..1
api-1            | not ok 1 - Setup -> askForAdministratorEmail
api-1            |   ---
api-1            |   duration_ms: 18.176702
api-1            |   type: 'suite'
api-1            |   location: '/home/talawa/api/test/setup/administratorEmail.test.ts:5:32'
api-1            |   failureType: 'subtestsFailed'
api-1            |   error: '1 subtest failed'
api-1            |   code: 'ERR_TEST_FAILURE'
api-1            |   ...
api-1            |  ✓ test/setup/administratorEmail.test.ts (0 test)

it is clear that the test failed, but still I get this

Image

@palisadoes
Copy link
Contributor Author

Your failed test is probably exiting with a zero (0) exit code.

@prayanshchh prayanshchh mentioned this issue Jan 26, 2025
6 tasks
Copy link

github-actions bot commented Feb 4, 2025

This issue did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please check if the develop branch has fixed it and report again or close the issue.

@github-actions github-actions bot added the no-issue-activity No issue activity label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Status: Backlog
Development

No branches or pull requests

7 participants