adalessa / laravel.nvim

Plugin for Nvim to work with laravel projects.
MIT License
280 stars 15 forks source link

Docker compose not working anymore #58

Closed dorkster100 closed 9 months ago

dorkster100 commented 9 months ago

The problem is that compose executable does not exist for me, is there a reason it is not docker-compose? Replacing compose with docker-compose in this file fixes this issue for me.

  create_user_command("DockerCompose", "compose", {
    up = function()
      api.async(
        "compose",
        { "up", "-d" },
        ---@param response ApiResponse
        function(response)
          if response:failed() then
            vim.notify(response:prettyErrors(), vim.log.levels.ERROR)
          else
            vim.notify("Compose Up Completed", vim.log.levels.INFO)
            status.refresh()
          end
        end
      )
    end,

On another note, create_user_command for some reason does register DockerCompose every other time even with non existing executable compose, so there is also some issue with that.

adalessa commented 9 months ago

Hi @dorkster100 I think I know the problem. The usage of compose is intentional. is defined to be mapped in the configuration. I don't use docker-compose because it was deprecated and from the docs is expected to use docker compose. What I think it happen is that the wrong environment was being loaded. Could you check the :checkhealth laravel that should show which environment was being use ? I notice that lua does not respect the index for alphanumeric keys so I have to do a little refactor so the order in the config is respected. the fix is live

dorkster100 commented 9 months ago
laravel: require("laravel.health").check()

Laravel ~
- OK fd installed
- OK rg installed

Environment ~
- OK Environment setup successful
- Name: local
- Condition: 
- {
  executable = { "php" }
  }
- Commands: 
- {}

Composer Dependencies ~
- OK Composer dependency `doctrine/dbal` is installed
- OK Composer dependency `laravel/tinker` is installed
dorkster100 commented 9 months ago

@adalessa after update it got better, it recognized the DockerCompose env, but now the commands dont work Error executing lua callback [NULL], and again it fixed setting docker-compose for me, i think he does not recognize it as executible otherwise.

adalessa commented 9 months ago

does your version of docker have the sub command compose docker compose?

adalessa commented 9 months ago

From the documentation the way to run docker compose is like that https://docs.docker.com/compose/gettingstarted/#step-4-build-and-run-your-app-with-compose. The settings yes it's for case like that change the compose command as you may need and the container exec.

dorkster100 commented 9 months ago

yes my version works with docker compose and all docker environvent commands work like DockerCompose ps

here is health now:

laravel: require("laravel.health").check()

Laravel ~
- OK fd installed
- OK rg installed

Environment ~
- OK Environment setup successful
- Name: docker-compose
- Condition: 
- {
  executable = { "docker" },
  file_exists = { "docker-compose.yml" }
  }
- Commands: 
- { {
  commands = { "php", "composer", "npm" },
  docker = {
  container = {
  default = "app",
  env = "APP_SERVICE"
  },
  exec = { "docker", "compose", "exec", "-it" }
  }
  },
  compose = { "docker", "compose" }
  }
adalessa commented 9 months ago

what command gives you the error ?

dorkster100 commented 9 months ago

Laravel routes and Laravel artisan, just to be clear first health that i posted was with previous commit, sorry to confuse.

adalessa commented 9 months ago

Yes I realize that. To confirm the problem if in the config you change to

{
      name = "docker-compose",
      condition = {
        file_exists = { "docker-compose.yml" },
        executable = { "docker" },
      },
      commands = {
        compose = { "docker-compose" },
        {
          commands = { "php", "composer", "npm" },
          docker = {
            container = {
              env = "APP_SERVICE",
              default = "app",
            },
            exec = { "docker-compose", "exec", "-it" },
          },
        },
      },
    }

With this should be using only docker-compose

dorkster100 commented 9 months ago

Laravel artisan now works, Laravel routes still fail with same error

adalessa commented 9 months ago

I will have to create an environment to test, I tested with sail and local with no issue. I will appreciate if you have some examples of your docker configuration that you could share.

dorkster100 commented 9 months ago

Is there some sort of cache? Because now artisan works with no changes, but routes does not

adalessa commented 9 months ago

The caches are clean on setup, you can run :Larave cache:clean to trigger it. Routes could be if the state of the aplication could not retrieve the routes. Something wrong on the web.php for example.

dorkster100 commented 9 months ago

Yes, you were right I actually had some errors with composer. Would be nice to have some error output. okay, now it seems to work.

adalessa commented 9 months ago

Agree, I will check on that.

adalessa commented 9 months ago

I have pushed a version that should report the error from the artisan commands. I think with that we can close the ticket for now.