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: Production Docker Installation Fails #3243

Open
palisadoes opened this issue Feb 18, 2025 · 54 comments
Open

NoMongo: Production Docker Installation Fails #3243

palisadoes opened this issue Feb 18, 2025 · 54 comments
Assignees
Labels
bug Something isn't working

Comments

@palisadoes
Copy link
Contributor

Describe the bug

  1. Follow the steps in the installation guide, or the video
    1. https://docs-api.talawa.io/docs/installation/#production-environment-setup
    2. https://github.com/PalisadoesFoundation/talawa-api/blob/develop-postgres/docs/docs/docs/getting-started/installation.md
  2. The app fails to start

To Reproduce

  • See above

Expected behavior

  • The app starts like in the YouTube video

Actual behavior

  • See above

Screenshots

  1. Failure messages
    Image
    Image

Additional details

  1. Use this command to initialize all the volumes, in the event of failures.
    docker compose down --rmi all --volumes
    
  2. Other commands may be required too.

Potential internship candidates

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

@palisadoes palisadoes added the bug Something isn't working label Feb 18, 2025
@github-actions github-actions bot added the unapproved Unapproved for Pull Request label Feb 18, 2025
@VanshikaSabharwal
Copy link

Please assign

@palisadoes palisadoes removed the unapproved Unapproved for Pull Request label Feb 18, 2025
@VanshikaSabharwal
Copy link

I am able to reproduce this error

@palisadoes
Copy link
Contributor Author

palisadoes commented Feb 22, 2025

@VanshikaSabharwal

The error has changed. Possibly due to recent PRs. The app progresses further then fails.

Steps

  1. Run this first to gracefully shutdown and destroy images
    docker compose down --rmi all --volumes
    
  2. The only error that is repeated is this one. It seems related to pnpm not being able to be found.
    Image
  3. Running the docker ps command gives this showing talawa-api-1 repeatedly starting:
    $ docker ps --format '{{.Names}}\t\t{{.Status}}'
    
    talawa-caddy-1          Up 4 minutes
    talawa-api-1            Restarting (127) 5 seconds ago
    talawa-cloudbeaver-1            Up 5 minutes (healthy)
    talawa-postgres-test-1          Up 5 minutes (healthy)
    talawa-minio-1          Up 5 minutes (healthy)
    talawa-postgres-1               Up 5 minutes (healthy)
    talawa-minio-test-1             Up 5 minutes (healthy)
  4. If you were running devcontainers before, you'll need to run these commands to completely remove all traces of docker. It helps to make a clean installation.
    docker compose down
    docker stop $(docker ps -q)
    docker rm -f $(docker ps -a -q)
    docker rmi $(docker images -q)
    docker volume prune -f
    

@JaiPannu-IITI
Copy link

@palisadoes

https://palisadoes-foundation.slack.com/archives/CSWH4PN0M/p1738240831597849

Sir this error is not due to recent PR's, I faced this when I just started using talawa API.

To fix this run start server in corepack enabled environment, I remember maybe this fixed this, do you want me to debug this ?

@VanshikaSabharwal
Copy link

As you can see i am already working on this issue.

@VanshikaSabharwal
Copy link

I hve already assigned this issue. Kindly ensure that the terms and conditions of Palisadoes are upheld.

I would truly appreciate your assistance in this matter.

@JaiPannu-IITI
Copy link

@VanshikaSabharwal Yes please continue your work, I am referring to my latest PR

@VanshikaSabharwal
Copy link

Can you please share you PR link?

@JaiPannu-IITI
Copy link

JaiPannu-IITI commented Feb 22, 2025

I believe that has nothing to do with this, also it has been reverted for now, refer to this message please

https://palisadoes-foundation.slack.com/archives/CSWH4PN0M/p1738240831597849

@VanshikaSabharwal
Copy link

@JaiPannu-IITI there is no problem even if the error has changed. I'll fix it. @palisadoes was just mentioning the error.

@VanshikaSabharwal
Copy link

If you want to debug you can come and assist me. You can contact me on slack.

@VanshikaSabharwal
Copy link

Also about the error occuring i saw one issue is consistent from beginning the MINIO setup one. And other issues are not consistent. Docker is vast and there can be issues even if the version is different.

@JaiPannu-IITI
Copy link

JaiPannu-IITI commented Feb 22, 2025

@VanshikaSabharwal It's really fine carry on with the task, don't panic you have all the time you want to fix this it's assigned to you. I didn't see this in the beginning I didn't wanted to be rude was just trying to make clear that adding pnpm to all shells has nothing to do with this

@VanshikaSabharwal
Copy link

Yes @JaiPannu-IITI Thanks

@palisadoes
Copy link
Contributor Author

For some reason, pnpm isn't being installed in the container.

Look at the startup console messages to see where the api-1 messages start.

Another option would be to see how you can log messages related to container initialization behind the scenes within docker versus externally via stdio/stderr to the screen.

@xoldd
Copy link
Contributor

xoldd commented Feb 22, 2025

@palisadoes pnpm is a package manager, a package manager is only required in non production environments, therefore it is not included in the production docker image of talawa api

@palisadoes
Copy link
Contributor Author

@palisadoes pnpm is a package manager, a package manager is only required in non production environments, therefore it is not included in the production docker image of talawa api

@xoldd

What could be causing this error? The most recent error messages are related to pnpm.

@JaiPannu-IITI
Copy link

@palisadoes
Line number 12 in file compose.testing.yaml -> command: pnpm run_tests when removed takes away pnpm not found error

How this makes sense?

Image

@JaiPannu-IITI
Copy link

@palisadoes use this docker-compose -f compose.yaml up since it is loading test yaml file with docker compose up.

It will show some progress

@JaiPannu-IITI
Copy link

@palisadoes Node is not getting installed in production environment, fnm is trying to use default

@JaiPannu-IITI
Copy link

JaiPannu-IITI commented Feb 22, 2025

@VanshikaSabharwal

  1. Configure docker to use compose.yaml instead of test yaml in production.
  2. fix fnm to use a node lts.

This should fix docker compose up. (if any other problem don't arise)

@VanshikaSabharwal
Copy link

Yes @JaiPannu-IITI i am updating the dockerfile and trying to remove this error. I am installing pnpm but it shows the same error

@VanshikaSabharwal
Copy link

@JaiPannu-IITI it should but it is not getting started that is the issue we have to fix. Why is it not getting started

@VanshikaSabharwal
Copy link

I tried your approach but it is not working

@VanshikaSabharwal
Copy link

Have you tries it locally for yourself? If yes please share ss

@JaiPannu-IITI
Copy link

Image

@VanshikaSabharwal
Copy link

Are you able to visit http://localhost:4000 and http://localhost:4000/graphql/

@JaiPannu-IITI
Copy link

JaiPannu-IITI commented Feb 22, 2025

Clear docker volumes and rebuild before using docker-compose -f compose.yaml up

  1. docker-compose down --rmi all --volumes --remove-orphans
  2. docker system prune -a --volumes
  3. docker-compose build --no-cache
  4. docker-compose -f compose.yaml up

New issue will be node version by fnm.

That even makes sense, pnpm issue is just misleading

@VanshikaSabharwal
Copy link

Can we connect on slack?

@JaiPannu-IITI
Copy link

Sure

@VanshikaSabharwal
Copy link

Great Yes i am texting you

@xoldd
Copy link
Contributor

xoldd commented Feb 22, 2025

New issue will be node version by fnm.

Fnm is not used in anywhere except the devcontainer docker build stage.

Image

All other docker build stages are based off of base docker build stage which itself is created from the official node.js docker image which already contains node.js and corepack. Corepack is used to install pnpm in the non_production, production_dependencies and production_code docker build stages.

Image

production docker build stage does not use corepack to install pnpm, instead it copies the relevant stuff from production_dependencies and production_code build stages.

Each step in a docker image's build cycle contributes to its final size. All this is done so that the size of the production image is as minimal as possible. By copying the relevant stuff from other build stages into the production build stage, the number of steps docker has to take in the production build stage is immensely reduced. Therefore outputting the production image for talawa api with the minimal possible size.

@xoldd
Copy link
Contributor

xoldd commented Feb 22, 2025

You guys are probably having a problem with your /.env file. You might be trying to run the production container of talawa api with environment variables of /envFiles/.env.ci or /envFiles/.env.devcontainer in your /.env file. Your /.env file must contain the environment variables in /envFiles/.env.production when you're trying to run the production container.

It all works for me when I follow the video that is uploaded on youtube for the latest commit on develop-postgres branch.

@VanshikaSabharwal
Copy link

Okay what is the solution to this. @xoldd

@VanshikaSabharwal
Copy link

Can you please share link of that video? @xoldd

@xoldd
Copy link
Contributor

xoldd commented Feb 22, 2025

Can you please share link of that video? @xoldd

It is on talawa docs.

@VanshikaSabharwal
Copy link

Is it this one. https://www.youtube.com/watch?v=10Zi2srGPHM

@palisadoes
Copy link
Contributor Author

Clear docker volumes and rebuild before using docker-compose -f compose.yaml up

1. docker-compose down --rmi all --volumes --remove-orphans

2. docker system prune -a --volumes

3. docker-compose build --no-cache

4. docker-compose -f compose.yaml up

New issue will be node version by fnm.

That even makes sense, pnpm issue is just misleading

The video shows this:

docker compose up

Why use compose.yaml?

@VanshikaSabharwal
Copy link

I did what you suggested @JaiPannu-IITI but i still see the same error.

Image

@JaiPannu-IITI
Copy link

now api is not starting, before it was failing, some difference.

@JaiPannu-IITI
Copy link

Clear docker volumes and rebuild before using docker-compose -f compose.yaml up

1. docker-compose down --rmi all --volumes --remove-orphans

2. docker system prune -a --volumes

3. docker-compose build --no-cache

4. docker-compose -f compose.yaml up

New issue will be node version by fnm.
That even makes sense, pnpm issue is just misleading

The video shows this:

docker compose up

Why use compose.yaml?

Sir I am sure that pnpm error will come when docker is setup using compose.testing.yaml but in production environment since it does not have pnpm,

Ideally we should use compose.yaml to setup api in production, I totally agree with @xoldd that production env clearly mentions COMPOSE_FILE=./compose.yaml in 71st line, but still somehow compose.testing.yaml is being used.

@JaiPannu-IITI
Copy link

Try to force compose.yaml and you'll se that pnpm disappears completely from logs and environment as expected.

But then when we get error that node is not available

After fixing that too, comes worse, api exits with code 0 directly, no logs !!

@JaiPannu-IITI
Copy link

JaiPannu-IITI commented Feb 22, 2025

I have not tested but I can predict that the command like pnpm start_development_server which is used to run api in container in development, this has something equivalent (not this) for production which might not be executed after container is run.

Also I haven't gone through that video, I just recreated the issue as above and tried to fix that, maybe some pipeline is already set to run api in production which is not updated In docs.

@xoldd
Copy link
Contributor

xoldd commented Feb 22, 2025

but still somehow compose.testing.yaml is being used

@JaiPannu-IITI either delete your existing talawa api image or rebuild it using production build stage

@VanshikaSabharwal
Copy link

Yes @JaiPannu-IITI i told you the same on slack.

Try to force compose.yaml and you'll se that pnpm disappears completely from logs and environment as expected.

But then when we get error that node is not available

After fixing that too, comes worse, api exits with code 0 directly, no logs !!

@VanshikaSabharwal
Copy link

@xoldd Id possible can you make another video and let us know if the app is working because i tried this but still i see the error

but still somehow compose.testing.yaml is being used

@JaiPannu-IITI either delete your existing talawa api image or rebuild it using production build stage

@JaiPannu-IITI
Copy link

but still somehow compose.testing.yaml is being used

@JaiPannu-IITI either delete your existing talawa api image or rebuild it using production build stage

Already done.

@xoldd
Copy link
Contributor

xoldd commented Feb 22, 2025

it works for peter now, he can explain the rest of the stuff

also envFiles/.env.deploy is incorrect as it is using values of envFiles/.env.devcontainer instead of envFiles/.env.production

@VanshikaSabharwal
Copy link

Okkay @xoldd Thanks for your guidance

@JaiPannu-IITI
Copy link

Alright @xoldd , glad to hear

@palisadoes
Copy link
Contributor Author

@xoldd assisted in getting this fixed. There were mistakes made and mutual assumptions made that contributed the the issue.

The various containers are designed to operate separately so that their services can be hosted on any combination of suitable hosted remote servers or SaaS providers.

This means that some passwords will need to be manually set to match, some are more obvious than others.

  1. MINIO_ROOT_PASSWORD and API_MINIO_SECRET_KEY must match
  2. API_POSTGRES_PASSWORD and POSTGRES_PASSWORD

You have to use the .env.production file as the starting point.

The documentation has been updated

This file works and will replace env.deploy. We'll randomize the passwords on the deployment server.

########## talawa api ##########

API_ADMINISTRATOR_USER_EMAIL_ADDRESS=administrator@example.com
API_ADMINISTRATOR_USER_NAME=Administrator
API_ADMINISTRATOR_USER_PASSWORD=password
API_BASE_URL=http://127.0.0.1:4000
API_COMMUNITY_FACEBOOK_URL=https://facebook.com
API_COMMUNITY_GITHUB_URL=https://github.com
API_COMMUNITY_INACTIVITY_TIMEOUT_DURATION=900
API_COMMUNITY_INSTAGRAM_URL=https://instagram.com
API_COMMUNITY_LINKEDIN_URL=https://linkedin.com
API_COMMUNITY_NAME=The Palisadoes Foundation
API_COMMUNITY_REDDIT_URL=https://reddit.com
API_COMMUNITY_SLACK_URL=https://www.palisaodes.org/slack
API_COMMUNITY_WEBSITE_URL=https://docs.talawa.com
API_COMMUNITY_X_URL=https://x.com
API_COMMUNITY_YOUTUBE_URL=https://youtube.com
API_HOST=0.0.0.0
API_IS_APPLY_DRIZZLE_MIGRATIONS=true
API_IS_GRAPHIQL=false
API_IS_PINO_PRETTY=false
API_JWT_EXPIRES_IN=2592000000
API_JWT_SECRET=dd06f326a810d9c7dd67b1428a4caef558d9e730d25e5440945f82948a56d96cd6f972222768cd2d77c28ad833f4a4a475a9828f87ac0ac3ec94df276fe24736
API_LOG_LEVEL=info
API_MINIO_ACCESS_KEY=talawa
API_MINIO_END_POINT=minio
API_MINIO_PORT=9000
API_MINIO_SECRET_KEY=REPLACE_WITH_RANDOM_PASSWORD
API_MINIO_USE_SSL=false
API_PORT=4000
API_POSTGRES_DATABASE=talawa
API_POSTGRES_HOST=postgres
API_POSTGRES_PASSWORD=REPLACE_WITH_RANDOM_PASSWORD
API_POSTGRES_PORT=5432
API_POSTGRES_SSL_MODE=false
API_POSTGRES_USER=talawa
# https://vitest.dev/config/#watch
CI=false
# https://blog.platformatic.dev/handling-environment-variables-in-nodejs#heading-set-nodeenvproduction-for-all-environments
NODE_ENV=production

########## docker compose `api` container service ##########

API_GID=1000
API_UID=1000

########## docker compose `caddy` container service ##########

CADDY_HTTP_MAPPED_PORT=8080
CADDY_HTTPS_MAPPED_PORT=8443
CADDY_HTTP3_MAPPED_PORT=8443
CADDY_TALAWA_API_DOMAIN_NAME=localhost
CADDY_TALAWA_API_EMAIL=talawa@example.com
CADDY_TALAWA_API_HOST=api
CADDY_TALAWA_API_PORT=4000

########## docker compose `minio` container service ##########

MINIO_BROWSER=off
MINIO_ROOT_PASSWORD=REPLACE_WITH_RANDOM_PASSWORD
MINIO_ROOT_USER=talawa

########## docker compose `postgres` container service ##########

POSTGRES_DB=talawa
POSTGRES_PASSWORD=REPLACE_WITH_RANDOM_PASSWORD
POSTGRES_USER=talawa

########## docker compose ##########

COMPOSE_FILE=./compose.yaml
COMPOSE_PROFILES=api,caddy,minio,postgres
COMPOSE_PROJECT_NAME=talawa

@VanshikaSabharwal VanshikaSabharwal mentioned this issue Feb 22, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

4 participants