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

Environment variables are not injected properly at runtime in next.js #843

Closed
Aschefr opened this issue Aug 2, 2024 · 28 comments
Closed
Labels
bug Something isn't working

Comments

@Aschefr
Copy link

Aschefr commented Aug 2, 2024

Hi,

First I want to thanks you all for providing this solution for free and I hope to see the project continue to grow.

Now, the issue I have is that I just created a VM running Ubuntu server LTS (on a proxmox machine, then tried again on my Unraid server). The VM is clean, nothing installed yet except Docker ofc.

I did a git clone https://github.com/evroon/bracket (because the provided command "git clone git@github.com:evroon/bracket.git" doesn't work) and started the docker compose with the provided command.

When I got to localhost:3000 I see the landing page asking me to login.

I put the provided default credentials :
Username: test@example.org Password: aeGhoe1ahng2Aezai0Dei6Aih6dieHoo.

But nothing happens and a notification in the bottom right appears saying "Internal server error".

As i'm no expert in Linux, I was wandering if I missed any step or this is just because I used the wrong distro or something ?

Thanks for reading.

@Aschefr
Copy link
Author

Aschefr commented Aug 18, 2024

Update : I saw that the GIT was updated few days ago, so I re-did this procedure, and now it works I can login fine. Thanks !

@Aschefr
Copy link
Author

Aschefr commented Aug 18, 2024

Hm. After restarting the OS, same error again. I really don't understand whats going-on....

Last log info for each dockers:
Postgre: 2024-08-18 10:58:59.513 UTC [1] LOG: database system is ready to accept connections

Backend: [2024-08-18 11:00:10 +0000] [8] [INFO] Application startup complete.

Frontend: Ready in 4.1s

No errors that I can see after I tried to login.

@ClausRogisch
Copy link

ClausRogisch commented Aug 27, 2024

same here. cloned master from git and not able to log in with provided credentials.
did the docker compose but login results in "internal server error"

@evroon
Copy link
Owner

evroon commented Aug 28, 2024

So you are both on linux?

It might be solved by #814, you can try if this docker-compose.yml works:

https://github.com/djpiper28/bracket/blob/patch-2/docker-compose.yml

The default Docker network is sometimes protected, for example on windows apparently.

@evroon
Copy link
Owner

evroon commented Aug 28, 2024

Now I merged the PR, so could you try again on master after doing git pull?

@Aschefr
Copy link
Author

Aschefr commented Aug 28, 2024

Still doesn't work, and I can see multiple error.
Here is the result of what I did in the console:

asche@ubuntu-server-vm:~$ ls
bracket  snap
asche@ubuntu-server-vm:~$ sudo rm bracket/ -r
asche@ubuntu-server-vm:~$ git clone https://github.com/evroon/bracket
Cloning into 'bracket'...
remote: Enumerating objects: 19118, done.
remote: Counting objects: 100% (4872/4872), done.
remote: Compressing objects: 100% (1294/1294), done.
remote: Total 19118 (delta 3567), reused 4081 (delta 2999), pack-reused 14246 (from 1)
Receiving objects: 100% (19118/19118), 9.58 MiB | 6.90 MiB/s, done.
Resolving deltas: 100% (11190/11190), done.
asche@ubuntu-server-vm:~$ cd bracket/
asche@ubuntu-server-vm:~/bracket$ sudo docker-compose up
[+] Running 3/0
 ✔ Container bracket-frontend    Created                                                                                                                                  0.0s
 ✔ Container bracket-postgres-1  Created                                                                                                                                  0.0s
 ✔ Container bracket-backend     Created                                                                                                                                  0.0s
Attaching to bracket-backend, bracket-frontend, bracket-postgres-1
bracket-frontend    |
bracket-frontend    | # Script to replace `NEXT_PUBLIC_*` environment variables because they're set at build-time but we want to set them at runtime in `docker-compose.yml`
bracket-frontend    | # Define an array of environment variable names
bracket-frontend    | env_vars=("NEXT_PUBLIC_API_BASE_URL" "NEXT_PUBLIC_HCAPTCHA_SITE_KEY")
bracket-frontend    |
bracket-frontend    | echo "Checking that we have variables..."
bracket-frontend    | # Iterate over the array and perform checks
bracket-frontend    | for var in "${env_vars[@]}"; do
bracket-frontend    |   test -n "${!var}"
bracket-frontend    | done
bracket-frontend    |
bracket-frontend    | # Iterate over the array and perform substitutions
bracket-frontend    | for var in "${env_vars[@]}"; do
bracket-frontend    |   find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_PLACEHOLDER_$var#${!var}#g"
bracket-frontend    | done
bracket-frontend    |
bracket-frontend    | Checking that we have variables...
bracket-postgres-1  |
bracket-postgres-1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
bracket-postgres-1  |
bracket-postgres-1  |
bracket-postgres-1  | 2024-08-28 15:07:39.781 UTC [1] LOG:  starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
bracket-postgres-1  | 2024-08-28 15:07:39.781 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
bracket-postgres-1  | 2024-08-28 15:07:39.783 UTC [1] LOG:  listening on IPv6 address "::", port 5432
bracket-postgres-1  | 2024-08-28 15:07:39.794 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
bracket-postgres-1  | 2024-08-28 15:07:39.813 UTC [28] LOG:  database system was shut down at 2024-08-28 15:06:53 UTC
bracket-postgres-1  | 2024-08-28 15:07:39.848 UTC [1] LOG:  database system is ready to accept connections
bracket-backend     | [2024-08-28 15:07:43 +0000] [1] [INFO] Starting gunicorn 22.0.0
bracket-backend     | [2024-08-28 15:07:43 +0000] [1] [INFO] Listening at: http://0.0.0.0:8400 (1)
bracket-backend     | [2024-08-28 15:07:43 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
bracket-backend     | [2024-08-28 15:07:43 +0000] [8] [INFO] Booting worker with pid: 8
bracket-backend     | [2024-08-28 15:07:49,757] [bracket] [INFO] Current env: DEVELOPMENT
bracket-backend     | [2024-08-28 15:07:53 +0000] [8] [INFO] Started server process [8]
bracket-backend     | [2024-08-28 15:07:53 +0000] [8] [INFO] Waiting for application startup.
bracket-postgres-1  | 2024-08-28 15:07:53.743 UTC [32] FATAL:  could not write init file
bracket-backend     | [2024-08-28 15:07:53 +0000] [8] [ERROR] Traceback (most recent call last):
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/starlette/routing.py", line 732, in lifespan
bracket-backend     |     async with self.lifespan_context(app) as maybe_state:
bracket-backend     |   File "/usr/local/lib/python3.10/contextlib.py", line 199, in __aenter__
bracket-backend     |     return await anext(self.gen)
bracket-backend     |   File "/app/bracket/app.py", line 40, in lifespan
bracket-backend     |     await database.connect()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/databases/core.py", line 112, in connect
bracket-backend     |     await self._backend.connect()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/databases/backends/postgres.py", line 74, in connect
bracket-backend     |     self._pool = await asyncpg.create_pool(**kwargs)
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 403, in _async__init__
bracket-backend     |     await self._initialize()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 430, in _initialize
bracket-backend     |     await first_ch.connect()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 128, in connect
bracket-backend     |     self._con = await self._pool._get_new_connection()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 502, in _get_new_connection
bracket-backend     |     con = await connection.connect(
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connection.py", line 2329, in connect
bracket-backend     |     return await connect_utils._connect(
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 991, in _connect
bracket-backend     |     conn = await _connect_addr(
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 828, in _connect_addr
bracket-backend     |     return await __connect_addr(params, True, *args)
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 876, in __connect_addr
bracket-backend     |     await connected
bracket-backend     | asyncpg.exceptions.InternalServerError: could not write init file
bracket-backend     |
bracket-backend     |
bracket-backend     | [2024-08-28 15:07:53 +0000] [8] [ERROR] Application startup failed. Exiting.
bracket-backend     | [2024-08-28 15:07:53 +0000] [8] [INFO] Worker exiting (pid: 8)
bracket-backend     | [2024-08-28 15:07:54 +0000] [1] [ERROR] Worker (pid:8) exited with code 3
bracket-backend     | [2024-08-28 15:07:54 +0000] [1] [ERROR] Shutting down: Master
bracket-backend     | [2024-08-28 15:07:54 +0000] [1] [ERROR] Reason: Worker failed to boot.
bracket-backend exited with code 0
bracket-postgres-1  | 2024-08-28 15:07:59.934 UTC [33] FATAL:  could not write init file
bracket-backend     | [2024-08-28 15:08:02 +0000] [1] [INFO] Starting gunicorn 22.0.0
bracket-backend     | [2024-08-28 15:08:02 +0000] [1] [INFO] Listening at: http://0.0.0.0:8400 (1)
bracket-backend     | [2024-08-28 15:08:02 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
bracket-backend     | [2024-08-28 15:08:02 +0000] [8] [INFO] Booting worker with pid: 8
bracket-backend     | [2024-08-28 15:08:09,128] [bracket] [INFO] Current env: DEVELOPMENT
bracket-backend     | [2024-08-28 15:08:12 +0000] [8] [INFO] Started server process [8]
bracket-backend     | [2024-08-28 15:08:12 +0000] [8] [INFO] Waiting for application startup.
bracket-postgres-1  | 2024-08-28 15:08:13.155 UTC [34] FATAL:  could not write init file
bracket-backend     | [2024-08-28 15:08:13 +0000] [8] [ERROR] Traceback (most recent call last):
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/starlette/routing.py", line 732, in lifespan
bracket-backend     |     async with self.lifespan_context(app) as maybe_state:
bracket-backend     |   File "/usr/local/lib/python3.10/contextlib.py", line 199, in __aenter__
bracket-backend     |     return await anext(self.gen)
bracket-backend     |   File "/app/bracket/app.py", line 40, in lifespan
bracket-backend     |     await database.connect()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/databases/core.py", line 112, in connect
bracket-backend     |     await self._backend.connect()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/databases/backends/postgres.py", line 74, in connect
bracket-backend     |     self._pool = await asyncpg.create_pool(**kwargs)
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 403, in _async__init__
bracket-backend     |     await self._initialize()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 430, in _initialize
bracket-backend     |     await first_ch.connect()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 128, in connect
bracket-backend     |     self._con = await self._pool._get_new_connection()
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/pool.py", line 502, in _get_new_connection
bracket-backend     |     con = await connection.connect(
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connection.py", line 2329, in connect
bracket-backend     |     return await connect_utils._connect(
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 991, in _connect
bracket-backend     |     conn = await _connect_addr(
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 828, in _connect_addr
bracket-backend     |     return await __connect_addr(params, True, *args)
bracket-backend     |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/asyncpg/connect_utils.py", line 876, in __connect_addr
bracket-backend     |     await connected
bracket-backend     | asyncpg.exceptions.InternalServerError: could not write init file
bracket-backend     |
bracket-backend     | [2024-08-28 15:08:13 +0000] [8] [ERROR] Application startup failed. Exiting.
bracket-backend     |
bracket-backend     | [2024-08-28 15:08:13 +0000] [8] [INFO] Worker exiting (pid: 8)
bracket-backend     | [2024-08-28 15:08:13 +0000] [1] [ERROR] Worker (pid:8) exited with code 3
bracket-backend     | [2024-08-28 15:08:13 +0000] [1] [ERROR] Shutting down: Master
bracket-backend     | [2024-08-28 15:08:13 +0000] [1] [ERROR] Reason: Worker failed to boot.
bracket-backend exited with code 0
bracket-backend     | [2024-08-28 15:08:18 +0000] [1] [INFO] Starting gunicorn 22.0.0
bracket-backend     | [2024-08-28 15:08:18 +0000] [1] [INFO] Listening at: http://0.0.0.0:8400 (1)
bracket-backend     | [2024-08-28 15:08:18 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
bracket-backend     | [2024-08-28 15:08:18 +0000] [8] [INFO] Booting worker with pid: 8
bracket-backend     | [2024-08-28 15:08:25,357] [bracket] [INFO] Current env: DEVELOPMENT
bracket-backend     | [2024-08-28 15:08:29 +0000] [8] [INFO] Started server process [8]
bracket-backend     | [2024-08-28 15:08:29 +0000] [8] [INFO] Waiting for application startup.
bracket-backend     | [2024-08-28 15:08:31,817] [bracket] [INFO] Running migrations
bracket-backend     | [2024-08-28 15:08:31 +0000] [8] [INFO] Application startup complete.
bracket-postgres-1  | 2024-08-28 15:08:39.895 UTC [47] FATAL:  could not write init file
bracket-frontend    | Starting Nextjs
bracket-frontend    |
bracket-frontend    | echo "Starting Nextjs"
bracket-frontend    | exec "$@"
bracket-frontend    |
bracket-frontend    | yarn run v1.22.19
bracket-frontend    | $ next start
bracket-frontend    |   ▲ Next.js 14.2.2
bracket-frontend    |   - Local:        http://localhost:3000
bracket-frontend    |
bracket-frontend    |  ✓ Starting...
bracket-frontend    |
bracket-frontend    |  ✓ Ready in 3.3s

The website shows up but can't login, same error.

@evroon
Copy link
Owner

evroon commented Aug 28, 2024

could not write init file suggests your disk is full, is that the case?

@Aschefr
Copy link
Author

Aschefr commented Aug 28, 2024

No, it is not full.
It's a freshed installed VM of Ubuntu Server LTS. 10Gb of free space which is enough for bracket I suppose.
I'm guessing I have a user right thing going on, but can't really figure-out how to fix it as I already run the docker a sudo.

EDIT : if you want to replicate ths issue I have, just install Ubuntu Server LTS last version on a VM or a NUC, and try follow your install guide of bracket. This should output the same results. I also have tried on Debian server with the same results.

EDIT2 : Oh man, you might have been right, turns out Ubuntu takes up a lot of space, I need to investigate more.
EDIT3 : All right I spun up a brand new Ubuntu VM with 80G of vdisk space, same error.

[+] Running 6/6
✔ Network bracket_bracket_lan Created 0.1s
✔ Network bracket_default Created 0.1s
✔ Volume "bracket_bracket_pg_data" Created 0.0s
✔ Container bracket-postgres-1 Started 2.5s
✔ Container bracket-frontend Started 2.5s
✔ Container bracket-backend Started 0.1s

@Aschefr
Copy link
Author

Aschefr commented Aug 30, 2024

Maybe a new lead:
Error in the browser console is:

Blocage d’une requête multiorigine (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur http://localhost:8400/token. Raison : échec de la requête CORS. Code d’état : (null).

(french sorry, but it kinda speak for itself)

So it seems like there is a "localhost" to replace with the IP of the server. But where do to that ?
EDIT : I've already try to replace it in the line "NEXT_PUBLIC_API_BASE_URL: http://localhost:8400" of the docker-compose file. Same error.

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

Hmm could you try opening http://localhost:8400/ping in the browser? And could you copy paste the output of docker ps -a here?

It should be correct that it's localhost right, or are you not opening the frontend in the browser as http://localhost:3000 but some other url?

@Aschefr
Copy link
Author

Aschefr commented Aug 30, 2024

I'm opening the frontend with the server's IP : http://192.168.20.112:3000
For sure that's the issue right ?

EDIT: The docker is running on a headless server

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

Ah yes that's the issue indeed

EDIT : I've already try to replace it in the line "NEXT_PUBLIC_API_BASE_URL: http://localhost:8400" of the docker-compose file. Same error.

Ah this is a bug, I fixed it now in #878. Somehow this didn't work anymore, now it should work again, could you try again with the latest version on master?

@Aschefr
Copy link
Author

Aschefr commented Aug 30, 2024

I've sudo rm -r the folder and clone again the git.
After editing the docker-compose file to edit the address with the one of the server and started the docker compose.
But still no luck, same error in the browser console.

image

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

Can you also pull the latest version of the docker container?
I think:
docker pull ghcr.io/evroon/bracket-frontend

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

The docker compose file downloads the image from GitHub so you need to manually download it again to update

@Aschefr
Copy link
Author

Aschefr commented Aug 30, 2024

Still no luck. same error in browser
Maybe that I'm doing something wrong, so I prefer sending you a screenshot:

image

Extract of the docker-compose file:
image

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

Looks alright, so in the browser network tab, it still shows localhost instead of the IP address of the environment variable?

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

And if you do this:

could you try opening http://localhost:8400/ping in the browser? And could you copy paste the output of docker ps -a here?

@evroon
Copy link
Owner

evroon commented Aug 30, 2024

Ohh I forgot to mention but you also have to set the CORS_ORIGINS environment variable for the backend correctly, with the ip address of the frontend, so whatever you write in the browser as url to access the frontend

@Aschefr
Copy link
Author

Aschefr commented Aug 30, 2024

Yes, browser network tab, still shows localhost instead of the IP address of the environment variable.

And if you do this:

could you try opening http://localhost:8400/ping in the browser? And could you copy paste the output of docker ps -a here?

Well I would love to, but have to replace "localhost" with 192.168.20.112 right ?

About CORS_ORIGINS, in ci.env file ? Or also in the docker compose ?

@SirThunder88
Copy link

SirThunder88 commented Sep 3, 2024

I'm in the same boat, debian12 fresh server/docker install. I've tried both dev and production guides, changed both mentions of localhost to the IP of the docker vm in the docker compose file, still can't login using default credentials with the same 'server error'

@SirThunder88
Copy link

SirThunder88 commented Sep 3, 2024

backend isn't starting up fully, monitoring i'm seeing this loop:

bracket-backend          | [2024-09-03 19:48:47 +0000] [1] [INFO] Starting gunicorn 22.0.0
bracket-backend          | [2024-09-03 19:48:47 +0000] [1] [INFO] Listening at: http://0.0.0.0:8400 (1)
bracket-backend          | [2024-09-03 19:48:47 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
bracket-backend          | [2024-09-03 19:48:47 +0000] [8] [INFO] Booting worker with pid: 8
bracket-backend          | [2024-09-03 19:48:48,788] [bracket] [INFO] Current env: PRODUCTION
bracket-backend          | [2024-09-03 19:47:45 +0000] [8] [INFO] Started server process [8]
bracket-backend          | [2024-09-03 19:47:45 +0000] [8] [INFO] Waiting for application startup.
bracket-backend          | [2024-09-03 19:47:45,917] [bracket] [INFO] Running migrations
bracket_prod-postgres-1  | 2024-09-03 19:47:45.956 UTC [210] ERROR:  index "ix_users_email" does not exist
bracket_prod-postgres-1  | 2024-09-03 19:47:45.956 UTC [210] STATEMENT:  
bracket_prod-postgres-1  |      DROP INDEX ix_users_email
bracket-backend          | [2024-09-03 19:47:45 +0000] [8] [ERROR] Traceback (most recent call last):
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
bracket-backend          |     self.dialect.do_execute(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
bracket-backend          |     cursor.execute(statement, parameters)
bracket-backend          | psycopg2.errors.UndefinedObject: index "ix_users_email" does not exist
bracket-backend          | 
bracket-backend          | 
bracket-backend          | The above exception was the direct cause of the following exception:
bracket-backend          | 
bracket-backend          | Traceback (most recent call last):
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/starlette/routing.py", line 732, in lifespan
bracket-backend          |     async with self.lifespan_context(app) as maybe_state:
bracket-backend          |   File "/usr/local/lib/python3.10/contextlib.py", line 199, in __aenter__
bracket-backend          |     return await anext(self.gen)
bracket-backend          |   File "/app/bracket/app.py", line 44, in lifespan
bracket-backend          |     alembic_run_migrations()
bracket-backend          |   File "/app/bracket/utils/alembic.py", line 12, in alembic_run_migrations
bracket-backend          |     command.upgrade(get_alembic_config(), "head")
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/command.py", line 406, in upgrade
bracket-backend          |     script.run_env()
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/script/base.py", line 582, in run_env
bracket-backend          |     util.load_python_file(self.dir, "env.py")
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 95, in load_python_file
bracket-backend          |     module = load_module_py(module_id, path)
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 113, in load_module_py
bracket-backend          |     spec.loader.exec_module(module)  # type: ignore
bracket-backend          |   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
bracket-backend          |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
bracket-backend          |   File "/app/alembic/env.py", line 47, in <module>
bracket-backend          |     run_migrations_online()
bracket-backend          |   File "/app/alembic/env.py", line 39, in run_migrations_online
bracket-backend          |     context.run_migrations()
bracket-backend          |   File "<string>", line 8, in run_migrations
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
bracket-backend          |     self.get_context().run_migrations(**kw)
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/runtime/migration.py", line 628, in run_migrations
bracket-backend          |     step.migration_fn(**kw)
bracket-backend          |   File "/app/alembic/versions/274385f2a757_add_on_delete_cascade_to_users_x_clubs.py", line 20, in upgrade
bracket-backend          |     op.drop_index("ix_users_email", table_name="users")
bracket-backend          |   File "<string>", line 8, in drop_index
bracket-backend          |   File "<string>", line 3, in drop_index
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/operations/ops.py", line 1128, in drop_index
bracket-backend          |     return operations.invoke(op)
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/operations/base.py", line 442, in invoke
bracket-backend          |     return fn(self, operation)
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/operations/toimpl.py", line 120, in drop_index
bracket-backend          |     operations.impl.drop_index(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/ddl/impl.py", line 410, in drop_index
bracket-backend          |     self._exec(schema.DropIndex(index, **kw))
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/alembic/ddl/impl.py", line 210, in _exec
bracket-backend          |     return conn.execute(construct, params)
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1385, in execute
bracket-backend          |     return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/sql/ddl.py", line 80, in _execute_on_connection
bracket-backend          |     return connection._execute_ddl(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1477, in _execute_ddl
bracket-backend          |     ret = self._execute_context(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
bracket-backend          |     self._handle_dbapi_exception(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
bracket-backend          |     util.raise_(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
bracket-backend          |     raise exception
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
bracket-backend          |     self.dialect.do_execute(
bracket-backend          |   File "/home/bracket/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
bracket-backend          |     cursor.execute(statement, parameters)
bracket-backend          | sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) index "ix_users_email" does not exist
bracket-backend          | 
bracket-backend          | [SQL: 
bracket-backend          | DROP INDEX ix_users_email]
bracket-backend          | (Background on this error at: https://sqlalche.me/e/14/f405)
bracket-backend          | 
bracket-backend          | [2024-09-03 19:47:45 +0000] [8] [ERROR] Application startup failed. Exiting.
bracket-backend          | [2024-09-03 19:47:45 +0000] [8] [INFO] Worker exiting (pid: 8)
bracket-backend          | [2024-09-03 19:47:46 +0000] [1] [ERROR] Worker (pid:8) exited with code 3
bracket-backend          | [2024-09-03 19:47:46 +0000] [1] [ERROR] Shutting down: Master
bracket-backend          | [2024-09-03 19:47:46 +0000] [1] [ERROR] Reason: Worker failed to boot.
bracket-backend exited with code 3

@luiscachog
Copy link

Hi,

I have the same issue when I configure an IP address instead of localhost, here is my docker-compose.yml file:

services:
  bracket-backend:
    container_name: bracket-backend
    hostname: bracket-backend
    environment:
      ENVIRONMENT: DEVELOPMENT
      PG_DSN: postgresql://REDACTED:REDACTED@192.168.1.155:5432/bracket_db
      JWT_SECRET: 'REDACTED'
      ADMIN_EMAIL: 'REDACTED'
      ADMIN_PASSWORD: 'REDACTED'
      AUTO_RUN_MIGRATIONS: true
      CORS_ORIGIN: '*'
      ALLOW_INSECURE_HTTP_SSO: false
    image: ghcr.io/evroon/bracket-backend:latest
    networks:
      - bracket_lan
    ports:
      - 8400:8400
    restart: unless-stopped
    volumes:
      - backend-static:/app/static

  bracket-frontend:
    container_name: bracket-frontend
    hostname: bracket-frontend
    environment:
      - NEXT_PUBLIC_API_BASE_URL=http://192.168.1.155:8400
      - NEXT_PUBLIC_HCAPTCHA_SITE_KEY=REDACTED
      - NODE_ENV=production
    image: ghcr.io/evroon/bracket-frontend:latest
    ports:
      - 8014:3000
    restart: unless-stopped

volumes:
  backend-static:

networks:
  bracket_lan:
    driver: bridge

Noticed that I offload the PostgreSQL from the compose file as I have an instance already running.

The error that I've seen on the browser inspector is:

POST http://localhost:8400/token net::ERR_CONNECTION_REFUSED

Firewall is open and can do the "ping" request:

$ curl http://192.168.1.155:8400/ping
"ping"

Still can't login.

@evroon
Copy link
Owner

evroon commented Sep 4, 2024

I can indeed reproduce the issue now, should have tried it earlier.
I always thought it was a networking issue, but it seems the way to inject environment variables at runtime doesn't work.
We need to overwrite the values of environment variables in the build directory after building the frontend, because in Next.js the variables are substituted at buildtime and not read at runtime: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser, which is very annoying.

I am still looking at how other projects fix this problem, but I tried this morning and couldn't solve it yet.

btw @SirThunder88 your problem is unrelated, you can open a separate discussion if you want help with that.

@evroon evroon added the bug Something isn't working label Sep 4, 2024
@evroon evroon changed the title First setup (docker), unable to login "Internal server error" Environment variables are not injected properly at runtime in next.js Sep 4, 2024
@SirThunder88
Copy link

I can indeed reproduce the issue now, should have tried it earlier. I always thought it was a networking issue, but it seems the way to inject environment variables at runtime doesn't work. We need to overwrite the values of environment variables in the build directory after building the frontend, because in Next.js the variables are substituted at buildtime and not read at runtime: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser, which is very annoying.

I am still looking at how other projects fix this problem, but I tried this morning and couldn't solve it yet.

btw @SirThunder88 your problem is unrelated, you can open a separate discussion if you want help with that.

Thank you for the response. the example I provided was just one of the attempts using the production script, I could not get any of them (quick start/dev/prod) to work with the default un/pass. I'll just be cool with any of them working so I can trial the software for an upcoming event that it may work for. If the fix for this issue doesn't also address what I'm experiencing I'll open another issue

@evroon
Copy link
Owner

evroon commented Sep 5, 2024

I have made a fix for the problem with the environment variables here: #886
I have tried it multiple times, and for me it works properly now.
Could one of you pull the new docker image (v1.5.3) and see if it's fixed for you as well?

@Aschefr
Copy link
Author

Aschefr commented Sep 6, 2024

Looks good on my side !
Thank you for this fix !

@evroon
Copy link
Owner

evroon commented Sep 6, 2024

Good to hear! Then I'll close this, feel free to open new issues

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
None yet
Development

No branches or pull requests

5 participants