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

docs(phoenix): connect to unix socket instead of tcp #1146

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

sevillaarvin
Copy link
Contributor

issue: #1088
reference: https://github.com/cachix/devenv/pull/803/files

tested on nixos@23.11
$ ./result/bin/devenv-run-tests --only phoenix examples
Running in directory examples
  Running phoenix
• Overriding .devenv to .devenv.BjsnRDLkJDdy
• Building tests ...
• Using Cachix: devenv
✔ Building tests in 2.0s.
• Building processes ...
✔ Building processes in 18.7s.
• Starting processes ...
• Building shell ...
✔ Building shell in 18.5s.
• PID is 471594
• Stop:      $ devenv processes stop
✔ Starting processes in 18.5s.
• Running tests ...
• Building shell ...
* creating /home/user/.mix/archives/hex-2.0.6
✔ Building shell in 1.7s.
* creating /home/user/.mix/elixir/1-15/rebar3

15:29:53.674 [notice] Application hex exited: Hex.Application.start(:normal, []) returned an error: shutdown: failed to start child: Hex.State
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Hex.Repo.default_hexpm_repo/0 is undefined (module Hex.Repo is not available)
            (hex 2.0.6) Hex.Repo.default_hexpm_repo()
            (hex 2.0.6) lib/hex/config.ex:108: Hex.Config.read_repos/1
            (hex 2.0.6) lib/hex/state.ex:157: Hex.State.init/1
            (elixir 1.15.7) lib/agent/server.ex:8: Agent.Server.init/1
            (stdlib 4.3.1.3) gen_server.erl:851: :gen_server.init_it/2
            (stdlib 4.3.1.3) gen_server.erl:814: :gen_server.init_it/6
            (stdlib 4.3.1.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

15:29:53.681 [notice] Application inets exited: :stopped

15:29:53.682 [notice] Application ssl exited: :stopped

15:29:53.682 [notice] Application public_key exited: :stopped

15:29:53.682 [notice] Application asn1 exited: :stopped

15:29:53.682 [notice] Application crypto exited: :stopped
Could not start Hex. Try fetching a new version with "mix local.hex" or uninstalling it with "mix archive.uninstall hex.ez"
* creating /home/user/.mix/archives/hex-2.0.6
** (MatchError) no match of right hand side value: {:error, {:hex, {{:shutdown, {:failed_to_start_child, Hex.State, {:undef, [{Hex.Repo, :default_hexpm_repo, [], []}, {Hex.Config, :read_repos, 1, [file: ~c"lib/hex/config.ex", line: 108]}, {Hex.State, :init, 1, [file: ~c"lib/hex/state.ex", line: 157]}, {Agent.Server, :init, 1, [file: ~c"lib/agent/server.ex", line: 8]}, {:gen_server, :init_it, 2, [file: ~c"gen_server.erl", line: 851]}, {:gen_server, :init_it, 6, [file: ~c"gen_server.erl", line: 814]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 240]}]}}}, {Hex.Application, :start, [:normal, []]}}}}
    (hex 2.0.6) lib/hex.ex:5: Hex.start/0
    (mix 1.15.7) lib/mix/hex.ex:60: Mix.Hex.start/0
    (mix 1.15.7) lib/mix/dep/loader.ex:189: Mix.Dep.Loader.with_scm_and_app/5
    (mix 1.15.7) lib/mix/dep/loader.ex:141: Mix.Dep.Loader.to_dep/4
    (elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (mix 1.15.7) lib/mix/dep/loader.ex:364: Mix.Dep.Loader.mix_children/3
    (mix 1.15.7) lib/mix/dep/loader.ex:18: Mix.Dep.Loader.children/1
    (mix 1.15.7) lib/mix/dep/converger.ex:97: Mix.Dep.Converger.all/4
The directory /home/user/projects/devenv/examples/phoenix/hello already exists. Are you sure you want to continue? [Yn] * creating hello/lib/hello/application.ex
* creating hello/lib/hello.ex
* creating hello/lib/hello_web/controllers/error_json.ex
* creating hello/lib/hello_web/endpoint.ex
* creating hello/lib/hello_web/router.ex
* creating hello/lib/hello_web/telemetry.ex
* creating hello/lib/hello_web.ex
* creating hello/mix.exs
* creating hello/README.md
* creating hello/.formatter.exs
* creating hello/.gitignore
* creating hello/test/support/conn_case.ex
* creating hello/test/test_helper.exs
* creating hello/test/hello_web/controllers/error_json_test.exs
* creating hello/lib/hello/repo.ex
* creating hello/priv/repo/migrations/.formatter.exs
* creating hello/priv/repo/seeds.exs
* creating hello/test/support/data_case.ex
* creating hello/lib/hello_web/controllers/error_html.ex
* creating hello/test/hello_web/controllers/error_html_test.exs
* creating hello/lib/hello_web/components/core_components.ex
* creating hello/lib/hello_web/controllers/page_controller.ex
* creating hello/lib/hello_web/controllers/page_html.ex
* creating hello/lib/hello_web/controllers/page_html/home.html.heex
* creating hello/test/hello_web/controllers/page_controller_test.exs
* creating hello/lib/hello_web/components/layouts/root.html.heex
* creating hello/lib/hello_web/components/layouts/app.html.heex
* creating hello/lib/hello_web/components/layouts.ex
* creating hello/priv/static/images/logo.svg
* creating hello/lib/hello/mailer.ex
* creating hello/lib/hello_web/gettext.ex
* creating hello/priv/gettext/en/LC_MESSAGES/errors.po
* creating hello/priv/gettext/errors.pot
* creating hello/priv/static/robots.txt
* creating hello/priv/static/favicon.ico
* creating hello/assets/js/app.js
* creating hello/assets/vendor/topbar.js
* creating hello/assets/css/app.css
* creating hello/assets/tailwind.config.js
* running mix deps.get
* creating /home/user/.mix/elixir/1-15/rebar3
Resolving Hex dependencies...
Resolution completed in 0.013s
New:
  phx_new 1.7.12
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 11 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.7.12.ez" with MIX_ENV=prod
* creating /home/user/.mix/archives/phx_new-1.7.12
• Setting up shell environment ...
* creating /home/user/.mix/archives/hex-2.0.6
* running mix assets.setup
* creating /home/user/.mix/elixir/1-15/rebar3
Resolving Hex dependencies...
Resolution completed in 0.016s
New:
  phx_new 1.7.12
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 11 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.7.12.ez" with MIX_ENV=prod
* creating /home/user/.mix/archives/phx_new-1.7.12
• Testing ...
• Running .test.sh...
+ pushd hello
~/projects/devenv/examples/phoenix/hello ~/projects/devenv/examples/phoenix
+ wait_for_port 4000 60
+ local port=4000
+ local timeout=60
+ timeout 60 bash -c 'until echo > /dev/tcp/localhost/4000; do sleep 0.5; done'
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
* running mix deps.compile
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused

We are almost there! The following steps are missing:

    $ cd hello

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

Start your Phoenix app with:

    $ mix phx.server

You can also run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix phx.server

[postgres       ] The files belonging to this database system will be owned by user "user".
[postgres       ] This user must also own the server process.
[postgres       ]
[postgres       ] The database cluster will be initialized with locale "C".
[postgres       ] The default text search configuration will be set to "english".
[postgres       ]
[postgres       ] Data page checksums are disabled.
[postgres       ]
[postgres       ] creating directory /home/user/projects/devenv/examples/phoenix/.devenv.BjsnRDLkJDdy/state/postgres ... ok
[postgres       ] creating subdirectories ... ok
[postgres       ] selecting dynamic shared memory implementation ... posix
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
[postgres       ] selecting default max_connections ... 100
[postgres       ] selecting default shared_buffers ... 128MB
[postgres       ] selecting default time zone ... Asia/Manila
[postgres       ] creating configuration files ... ok
[postgres       ] running bootstrap script ... ok
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
[postgres       ] performing post-bootstrap initialization ... ok
[phoenix        ] Compiling 15 files (.ex)
[postgres       ] syncing data to disk ... ok
[postgres       ]
[postgres       ] initdb: warning: enabling "trust" authentication for local connections
[postgres       ] initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
[postgres       ]
[postgres       ] Success. You can now start the database server using:
[postgres       ]
[postgres       ]     /nix/store/ph0bg8kq0g47h6rczgifrrbnag1isb56-postgresql-15.6/bin/pg_ctl -D /home/user/projects/devenv/examples/phoenix/.devenv.BjsnRDLkJDdy/state/postgres -l logfile start
[postgres       ]
[postgres       ]
[postgres       ] PostgreSQL initdb process complete.
[postgres       ]
[postgres       ]
[postgres       ] PostgreSQL is setting up the initial database.
[postgres       ]
[postgres       ] waiting for server to start....2024-04-18 07:30:22.226 GMT [477697] LOG:  starting PostgreSQL 15.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 13.2.0, 64-bit
[postgres       ] 2024-04-18 07:30:22.226 GMT [477697] LOG:  listening on Unix socket "/run/user/1000/devenv-2920468/postgres/.s.PGSQL.5432"
[postgres       ] 2024-04-18 07:30:22.237 GMT [477700] LOG:  database system was shut down at 2024-04-18 07:30:22 GMT
[postgres       ] 2024-04-18 07:30:22.243 GMT [477697] LOG:  database system is ready to accept connections
[postgres       ]  done
[postgres       ] server started
[postgres       ] Checking presence of database: hello_dev
[postgres       ] 0
[postgres       ] Creating database: hello_dev
[postgres       ] CREATE DATABASE
[postgres       ] CREATE ROLE
[postgres       ] waiting for server to shut down...2024-04-18 07:30:22.383 GMT [477697] LOG:  received fast shutdown request
[postgres       ] .2024-04-18 07:30:22.386 GMT [477697] LOG:  aborting any active transactions
[postgres       ] 2024-04-18 07:30:22.387 GMT [477697] LOG:  background worker "logical replication launcher" (PID 477703) exited with exit code 1
[postgres       ] 2024-04-18 07:30:22.387 GMT [477698] LOG:  shutting down
[postgres       ] 2024-04-18 07:30:22.390 GMT [477698] LOG:  checkpoint starting: shutdown immediate
[postgres       ] 2024-04-18 07:30:22.449 GMT [477698] LOG:  checkpoint complete: wrote 923 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.022 s, sync=0.029 s, total=0.063 s; sync files=305, longest=0.007 s, average=0.001 s; distance=4226 kB, estimate=4226 kB
[postgres       ] 2024-04-18 07:30:22.457 GMT [477697] LOG:  database system is shut down
[postgres       ]  done
[postgres       ] server stopped
[postgres       ] 2024-04-18 07:30:22.504 GMT [477581] LOG:  starting PostgreSQL 15.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 13.2.0, 64-bit
[postgres       ] 2024-04-18 07:30:22.504 GMT [477581] LOG:  listening on Unix socket "/run/user/1000/devenv-2920468/postgres/.s.PGSQL.5432"
[postgres       ] 2024-04-18 07:30:22.514 GMT [477718] LOG:  database system was shut down at 2024-04-18 07:30:22 GMT
[postgres       ] 2024-04-18 07:30:22.521 GMT [477581] LOG:  database system is ready to accept connections
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
[phoenix        ] Generated hello app
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
bash: connect: Connection refused
bash: line 1: /dev/tcp/localhost/4000: Connection refused
[phoenix        ] [info] Running HelloWeb.Endpoint with Bandit 1.4.2 at 127.0.0.1:4000 (http)
[phoenix        ] [info] Access HelloWeb.Endpoint at http://localhost:4000
[phoenix        ] [watch] build finished, watching for changes...
+ mix ecto.create
[phoenix        ]
[phoenix        ] Rebuilding...
The database for Hello.Repo has already been created
+ curl -s http://localhost:4000/
+ grep 'Phoenix Framework'
[phoenix        ] [info] GET /
[phoenix        ] [debug] Processing with HelloWeb.PageController.home/2
[phoenix        ]   Parameters: %{}
[phoenix        ]   Pipelines: [:browser]
[phoenix        ] [info] Sent 200 in 26ms
    <!-- @caller lib/hello_web/components/layouts/root.html.heex:7 (hello) --><!-- <Phoenix.Component.live_title> lib/phoenix_component.ex:2002 (phoenix_live_view) --><title data-suffix=" · Phoenix Framework">
     · Phoenix Framework</title><!-- </Phoenix.Component.live_title> -->
      Phoenix Framework
+ popd
~/projects/devenv/examples/phoenix
✔ Running tests in 34.6s.
• Stopping process with PID 471594
Stopping processes...
• Tests passed :)
[postgres       ] 2024-04-18 07:30:24.931 GMT [477581] LOG:  received fast shutdown request
[postgres       ] 2024-04-18 07:30:24.934 GMT [477581] LOG:  aborting any active transactions
[postgres       ] 2024-04-18 07:30:24.934 GMT [477746] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477747] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477750] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477748] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477745] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477749] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477743] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477744] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.934 GMT [477742] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.935 GMT [477741] FATAL:  terminating connection due to administrator command
[postgres       ] 2024-04-18 07:30:24.937 GMT [477581] LOG:  background worker "logical replication launcher" (PID 477721) exited with exit code 1
[postgres       ] 2024-04-18 07:30:24.938 GMT [477716] LOG:  shutting down
[postgres       ] 2024-04-18 07:30:24.941 GMT [477716] LOG:  checkpoint starting: shutdown immediate
[postgres       ] 2024-04-18 07:30:24.945 GMT [477880] LOG:  PID 477750 in cancel request did not match any process
[postgres       ] 2024-04-18 07:30:24.947 GMT [477881] LOG:  PID 477749 in cancel request did not match any process
[postgres       ] 2024-04-18 07:30:24.949 GMT [477882] LOG:  PID 477748 in cancel request did not match any process
[postgres       ] 2024-04-18 07:30:24.954 GMT [477883] LOG:  PID 477747 in cancel request did not match any process
[postgres       ] 2024-04-18 07:30:24.954 GMT [477716] FATAL:  could not access status of transaction 0
[postgres       ] 2024-04-18 07:30:24.954 GMT [477716] DETAIL:  Could not open file "pg_xact/0000": No such file or directory.
[postgres       ] 2024-04-18 07:30:24.955 GMT [477581] LOG:  checkpointer process (PID 477716) exited with exit code 1
[postgres       ] 2024-04-18 07:30:24.955 GMT [477581] LOG:  terminating any other active server processes
[postgres       ] 2024-04-18 07:30:24.956 GMT [477581] LOG:  abnormal database system shutdown
[postgres       ] 2024-04-18 07:30:24.960 GMT [477581] LOG:  database system is shut down
Processes stopped.


Ran 1 tests, 0 failed.

@domenkozar domenkozar merged commit d775275 into cachix:main Apr 18, 2024
139 of 255 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants