misskey-dev / misskey

🌎 A completely free and open interplanetary microblogging platform πŸš€
https://misskey-hub.net/
GNU Affero General Public License v3.0
10.01k stars 1.37k forks source link

CannotExecuteNotConnectedError when running sudo docker-compose run --rm web yarn run init #8775

Open stampirl opened 2 years ago

stampirl commented 2 years ago

πŸ’‘ Summary

I'm trying to setup misskey on my server following docker-compose instructions in documentation. Process fails when running yarn run init

πŸ₯° Expected Behavior

Successful init of misskey.

🀬 Actual Behavior

I get "Error 1". Full output:

Creating misskey_web_run ... 
yarn run v1.22.17
$ npm run migrate

> misskey@12.110.1 migrate
> cd packages/backend && npx typeorm migration:run -d ormconfig.js

typeorm migration:run

Runs all pending migrations.

Options:
  -h, --help         Show help                                         [boolean]
  -d, --dataSource   Path to the file where your DataSource instance is defined.
                                                                      [required]
  -t, --transaction  Indicates if transaction should be used or not for
                     migration run. Enabled by default.     [default: "default"]
  -v, --version      Show version number                               [boolean]

CannotExecuteNotConnectedError: Cannot execute operation on "default" connection because connection is not yet established.
    at DataSource.destroy (/misskey/packages/backend/node_modules/typeorm/data-source/DataSource.js:169:19)
    at Object.handler (/misskey/packages/backend/node_modules/typeorm/commands/MigrationRunCommand.js:67:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm notice 
npm notice New minor version of npm available! 8.3.1 -> 8.11.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.11.0
npm notice Run npm install -g npm@8.11.0 to update!
npm notice 
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: 1

After running docker-compose up I can see in output:

db_1     | 2022-06-01 12:16:17.380 UTC [29] FATAL:  password authentication failed for user "misskey"
db_1     | 2022-06-01 12:16:17.380 UTC [29] DETAIL:  Role "misskey" does not exist.
db_1     |  Connection matched pg_hba.conf line 95: "host all all all md5"

I changed both .config/default.yml and .config/docker.env to use misskey as user and db name, but i looks like it's not used in actual db container.

Misskey version: git master Your OS: Debian 11

Johann150 commented 2 years ago

Role "misskey" does not exist.

This says the database user misskey does not exist, so I think your configuration is probably incorrect. From my understanding you need to configure an existing database user and the respective password.

But I am not too familiar with the Docker installation method so I might be wrong.

stampirl commented 2 years ago

That I do understand, but that should be done by docker bootstraping db with .config/docker.env. Bleow it's content:

# db settings
POSTGRES_PASSWORD=****************
POSTGRES_USER=misskey
POSTGRES_DB=misskey
yzhe819 commented 2 years ago

The same issue with dockerπŸ’¦

Here is a related issue for typeorm that might help # 8885

lacafjh commented 1 year ago

A similar issue occurred even with the default with modified DB username and password in default.yml and docker.env.

# log
$ sudo docker compose run --rm web yarn run init
[sudo] password for voyage: 
[+] Running 1/0
 β Ώ Container misskey_db  Running                                                                                                               0.0s
[+] Running 1/0
 β Ώ Container misskey_redis  Started                                                                                                            0.0s
yarn run v1.22.19
$ npm run migrate

> misskey@12.119.0 migrate
> cd packages/backend && npx typeorm migration:run -d ormconfig.js

[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
Error during migration run:
error: password authentication failed for user "example-misskey-user"
    at Parser.parseErrorMessage (/misskey/packages/backend/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/misskey/packages/backend/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/misskey/packages/backend/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/misskey/packages/backend/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 116,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '330',
  routine: 'auth_failed'
}
npm notice 
npm notice New major version of npm available! 8.11.0 -> 9.1.3
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.1.3
npm notice Run npm install -g npm@9.1.3 to update!
npm notice 
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The docker-compose.yml file:

version: "3"

services:
  web:
    xxxxxx
  redis:
    xxxxxx
  db:
    restart: always
    image: postgres:12.2-alpine
    networks:
      - internal_network
    env_file:
      - .config/docker.env
    volumes:
      - ./db:/var/lib/postgresql/data

networks:

The default.yml file:

#   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
#β”€β”€β”€β”˜ PostgreSQL configuration └────────────────────────────────

db:
  host: db
  port: 5432

  # Database name
  db: misskey

  # Auth
  user: example-misskey-user
  pass: password

The docker.env file:

# db settings
POSTGRES_PASSWORD=password
POSTGRES_USER=example-misskey-user
POSTGRES_DB=misskey

After further testing, I found the direct cause of the problem. It seems that all the changed items in docker.env were ignored. I restore the value of POSTGRES_PASSWORD in default.yml to example-misskey-pass and kept the value of pass in docker.env as password, then its deployment worked usually.

The default.yml file:

#   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
#β”€β”€β”€β”˜ PostgreSQL configuration └────────────────────────────────

db:
  host: db
  port: 5432

  # Database name
  db: misskey

  # Auth
  user: example-misskey-user
  pass: password

The docker.env file:

# db settings
POSTGRES_PASSWORD=example-misskey-pass
POSTGRES_USER=example-misskey-user
POSTGRES_DB=misskey

Deployment worked successfully:

# log
$ sudo docker compose run --rm web yarn run init
[+] Running 2/2
 β Ώ Container misskey_db     Recreated                                                                                                          0.5s
 β Ώ Container misskey_redis  Running                                                                                                            0.0s
[+] Running 1/1
 β Ώ Container misskey_db  Started                                                                                                               0.9s
yarn run v1.22.19
$ npm run migrate

> misskey@12.119.0 migrate
> cd packages/backend && npx typeorm migration:run -d ormconfig.js

query: SELECT * FROM current_schema()
query: SELECT version();
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = 'public' AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
No migrations are pending
npm notice 
npm notice New major version of npm available! 8.11.0 -> 9.1.3
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.1.3
npm notice Run npm install -g npm@9.1.3 to update!
npm notice 
Done in 6.91s.

Similarly, I also tried to modify only POSTGRES_USER or POSTGRES_DB to a custom value in docker.env, and keep values of user and db in default.yml as default, and the deployment was successful as well. And if I change the value in default.yml at the same time, an error text will be printed.

I have also considered that the path to the env file in the Compose file may be incorrectly filled. However, the issue still occurred after changing the path to the absolute path of docker.env.