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

Does not set DATABASE_URL when an env var containing "DATABASE_URL" is present #334

Open
turicas opened this issue Dec 12, 2024 · 0 comments

Comments

@turicas
Copy link

turicas commented Dec 12, 2024

Description of problem

If a custom environment variable EXTERNAL_DATABASE_URL is set and no DATABASE_URL exists for the app, dokku-postgres will not create the DATABASE_URL when linking (will use another name). I think dokku-postgres checks for an environment variable containing DATABASE_URL in its name, instead of specifically checking for a variable named DATABASE_URL exactly.

Steps to Reproduce

Execute the following commands:

export APP_NAME=testapp
export DB_NAME=pg_testapp
dokku apps:create $APP_NAME

# First test (success) - if no env vars containing `DATABASE_URL` are present, the variable is created correctly
dokku postgres:create $DB_NAME -i postgres -I 16-bookworm --shm-size 2g
dokku postgres:link $DB_NAME $APP_NAME  # Creates DATABASE_URL

# Second test (fail)
dokku postgres:unlink $DB_NAME $APP_NAME
dokku config:set $APP_NAME EXTERNAL_DATABASE_URL=something
dokku postgres:link $DB_NAME $APP_NAME  # Creates DOKKU_POSTGRES_AQUA_URL

Actual Results

root@mymachine:~ 
# export APP_NAME=testapp
root@mymachine:~ 
# export DB_NAME=pg_testapp
root@mymachine:~ 
# dokku apps:create $APP_NAME
-----> Creating testapp...
-----> Creating new app virtual host file...
root@mymachine:~ 
# dokku postgres:create $DB_NAME -i postgres -I 16-bookworm --shm-size 2g
       Waiting for container to be ready
       Creating container database
       Securing connection to database
=====> Postgres container created: pg_testapp
=====> pg_testapp postgres service information
       Config dir:          /var/lib/dokku/services/postgres/pg_testapp/data
       Config options:                               
       Data dir:            /var/lib/dokku/services/postgres/pg_testapp/data
       Dsn:                 postgres://postgres:5605d910b8ec2e4cf1888febfbc7fa94@dokku-postgres-pg-testapp:5432/pg_testapp
       Exposed ports:       -                        
       Id:                  d4fd85937c9ba0207e8f021af8814775ea273782d903e48055d48d29f3cd39cf
       Internal ip:         172.17.0.26              
       Initial network:                              
       Links:               -                        
       Post create network:                          
       Post start network:                           
       Service root:        /var/lib/dokku/services/postgres/pg_testapp
       Status:              running                  
       Version:             postgres:16-bookworm     
root@mymachine:~ 
# dokku postgres:link $DB_NAME $APP_NAME
-----> Setting config vars
       DATABASE_URL:  postgres://postgres:5605d910b8ec2e4cf1888febfbc7fa94@dokku-postgres-pg-testapp:5432/pg_testapp
-----> Restarting app testapp
 !     App image (dokku/testapp:latest) not found
root@mymachine:~ 
# dokku postgres:unlink $DB_NAME $APP_NAME
-----> Unsetting DATABASE_URL
-----> Restarting app testapp
 !     App image (dokku/testapp:latest) not found
root@mymachine:~ 
# dokku config:set $APP_NAME EXTERNAL_DATABASE_URL=something
-----> Setting config vars
       EXTERNAL_DATABASE_URL:  something
-----> Restarting app testapp
 !     App image (dokku/testapp:latest) not found
root@mymachine:~ 
# dokku postgres:link $DB_NAME $APP_NAME
-----> Setting config vars
       DOKKU_POSTGRES_AQUA_URL:  postgres://postgres:5605d910b8ec2e4cf1888febfbc7fa94@dokku-postgres-pg-testapp:5432/pg_testapp
-----> Restarting app testapp
 !     App image (dokku/testapp:latest) not found

Expected Results

The very last postgres:link should set the env var named DATABASE_URL instead of DOKKU_POSTGRES_AQUA_URL.

Environment Information

dokku report APP_NAME output

Not applicable.

How (deb/make) and where (AWS, VirtualBox, physical, etc.) was Dokku installed?:

From dokku's Debian repository.

Additional information

dokku version 0.35.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant