Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Tye on Podman with Postgres couldn't inject environment variables #1255

Open
thangchung opened this issue Dec 30, 2021 · 4 comments
Open

Tye on Podman with Postgres couldn't inject environment variables #1255

thangchung opened this issue Dec 30, 2021 · 4 comments

Comments

@thangchung
Copy link
Contributor

Describe the bug

With Podman, when we run the Postgres container (postgres:12-alpine), the container can start, but down immediately due to environment variables couldn't inject into -e param when run on tye. When checked a logs then I found

[postgres_1c29ada2-8]: docker run -d -e "PORT=5432" -e "PROXY_PORT=5432:5432" -e "POSTGRES_USER=myuser" -e "POSTGRES_PASSWORD=P@ssw0rd" -e "POSTGRES_DB=mydb" -e "CONNECTIONSTRINGS__POSTGRES=Server=10.0.2.2;Port=5432;User Id=myuser;Password=P@ssw0rd;" -e "APP_INSTANCE=postgres_1c29ada2-8" -e "CONTAINER_HOST=10.0.2.2" -p 5432:5432 --name postgres_1c29ada2-8 --restart=unless-stopped postgres:12-alpine
[postgres_1c29ada2-8]: 66a072b3f81ae09f20154ab572bfbf579937613f2f78827fa12da36f7bd6fc58
[postgres_1c29ada2-8]: Error: Database is uninitialized and superuser password is not specified.
[postgres_1c29ada2-8]: You must specify POSTGRES_PASSWORD to a non-empty value for the
[postgres_1c29ada2-8]: superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
[postgres_1c29ada2-8]:
[postgres_1c29ada2-8]: You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
[postgres_1c29ada2-8]: connections without a password. This is *not* recommended.
[postgres_1c29ada2-8]:
[postgres_1c29ada2-8]: See PostgreSQL documentation about "trust":
[postgres_1c29ada2-8]: https://www.postgresql.org/docs/current/auth-trust.html
.....

It should be a problem with tye when run the docker run -e <...>

When I copy the generated script by tye as following

podman run -d -e "PORT=5432" -e "PROXY_PORT=5432:5432" -e "POSTGRES_USER=myuser" -e "POSTGRES_PASSWORD=P@ssw0rd" -e "POSTGRES_DB=mydb" -e "CONNECTIONSTRINGS__POSTGRES=Server=10.0.2.2;Port=5432;User Id=myuser;Password=P@ssw0rd;" -e "APP_INSTANCE=postgres_1c29ada2-8" -e "CONTAINER_HOST=10.0.2.2" -p 5432:5432 --name postgres_1c29ada2-8 --restart=unless-stopped postgres:12-alpine

And run it right in the podman on wsl2 - Ubuntu host, then it can work correctly. I can remote login into Postgres db and manipulate schema and data in it

To Reproduce

Create tye.yaml

name: bff-auth
containerEngine: podman

services:

- name: postgres
  image: postgres:12-alpine
  env_file:
    - .env
  bindings:
    - port: 5432
      connectionString: Server=${host};Port=${port};User Id=${env:POSTGRES_USER};Password=${env:POSTGRES_PASSWORD};

And .env file

POSTGRES_USER=myuser
POSTGRES_PASSWORD=P@ssw0rd
POSTGRES_DB=mydb

Then run

tye run

Everything run well, but when we check logs of Postgres at http://localhost:8000, then we found the error logs as below

[postgres_1c29ada2-8]: docker run -d -e "PORT=5432" -e "PROXY_PORT=5432:5432" -e "POSTGRES_USER=myuser" -e "POSTGRES_PASSWORD=P@ssw0rd" -e "POSTGRES_DB=mydb" -e "CONNECTIONSTRINGS__POSTGRES=Server=10.0.2.2;Port=5432;User Id=myuser;Password=P@ssw0rd;" -e "APP_INSTANCE=postgres_1c29ada2-8" -e "CONTAINER_HOST=10.0.2.2" -p 5432:5432 --name postgres_1c29ada2-8 --restart=unless-stopped postgres:12-alpine
[postgres_1c29ada2-8]: 66a072b3f81ae09f20154ab572bfbf579937613f2f78827fa12da36f7bd6fc58
[postgres_1c29ada2-8]: Error: Database is uninitialized and superuser password is not specified.
[postgres_1c29ada2-8]: You must specify POSTGRES_PASSWORD to a non-empty value for the
[postgres_1c29ada2-8]: superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
[postgres_1c29ada2-8]:
[postgres_1c29ada2-8]: You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
[postgres_1c29ada2-8]: connections without a password. This is *not* recommended.
[postgres_1c29ada2-8]:
[postgres_1c29ada2-8]: See PostgreSQL documentation about "trust":
[postgres_1c29ada2-8]: https://www.postgresql.org/docs/current/auth-trust.html
.....

Further technical details

  • Include the output of tye --version: 0.11.0-alpha.21629.1+c55a663e44390be98935d11375d4248738a376fd, and it also got this issue when run with tye 0.10.xxx
  • If possible rerun the command with -v debug and include the output:
❯ tye run -v debug
Loading Application Details...
Restoring and evaluating projects
Restore and project evaluation took: 256.116ms
Launching Tye Host...

[14:59:22 INF] Executing application from D:\github\bff-auth\tye.yaml
[14:59:22 INF] Dashboard running on http://127.0.0.1:8000
[14:59:23 INF] Docker image postgres:12-alpine already installed
[14:59:23 INF] Running image postgres:12-alpine for postgres_1c29ada2-8
[14:59:23 INF] Application bff-auth started successfully with Pid: 31856
[14:59:24 INF] Running container postgres_1c29ada2-8 with ID 66a072b3f81a
[14:59:24 INF] Replica postgres_1c29ada2-8 is moving to a ready state
[14:59:24 INF] Collecting docker logs for postgres_1c29ada2-8.
  • The platform (Linux/macOS/Windows): Windows 11
@thangchung thangchung added the bug Something isn't working label Dec 30, 2021
@thangchung
Copy link
Contributor Author

When we tried with RabbitMQ, then we have got the same issue, we couldn't set username and password for RabbitMQ via variable environments. So I thought that this bug happen for all containers run on Podman with tye :|

@philliphoff
Copy link
Contributor

@thangchung Can you describe your setup a bit more? Are you testing in WSL2, or are you testing on Windows using a podman remote client that's connected to podman running in WSL2? I'm not seeing this issue when testing against podman running on my Mac, nor in WSL2 on my Windows machine. I've not tested the remote client configuration, however.

@philliphoff philliphoff added Needs more info and removed bug Something isn't working labels Jan 11, 2022
@tungphuong
Copy link

The same issue is with Podman and WSL2; tried with environment file or provide environment variables in Yaml file but cannot start the container with correct variables

@thangchung
Copy link
Contributor Author

@philliphoff Yes. I would like to confirm that this bug has happened on the remote client. I thought that was the bug in the Podman client and there is a PR to fix it, and hope after the release in a new version, I can re-visit to see whether it works with tye or not? See it containers/podman#12503

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

No branches or pull requests

3 participants