devenv icon indicating copy to clipboard operation
devenv copied to clipboard

Allow services to be docker containers to ease migrating to devenv

Open ParetoOptimalDev opened this issue 1 year ago • 5 comments

Context: A codebase I'm working on had mongo, postgresql, and localstack. Mongo and postgres already existed as services.

I was about to add localstack, but realized that we use an older version that nixpkgs currently has. It's probably still worth adding, but it made me realize how quickly I could have a proof of concept for devenv if it gave an easy way for running docker containers as services.

workaround: docker run ... in enterShell is what I'll probably do for now.

ParetoOptimalDev avatar Jul 26 '23 19:07 ParetoOptimalDev

You can use 'docker run' and 'docker rm -f', if you use process-compose as the implementation for the services. Check the process-compose readme for examples. I use this extensively already for hard to package things.

thenonameguy avatar Jul 26 '23 19:07 thenonameguy

Relevant to #2

domenkozar avatar Jul 27 '23 10:07 domenkozar

We could have something like

{ 
  services.container.foobar.image = "postgres:14";
}

That would run the docker or some other container tech to run the container.

domenkozar avatar Jul 27 '23 10:07 domenkozar

We could have something like

{ 
  services.container.foobar.image = "postgres:14";
}

That would run the docker or some other container tech to run the container.

That sounds good and is what I envisioned, but I haven't yet checked out the process-compose example the other user mentioned so I'm not sure how it compares.

ParetoOptimalDev avatar Jul 27 '23 14:07 ParetoOptimalDev

Just an example for any future people who wander upon this,

processes.postgres = {
    exec = ( lib.concatStringsSep " " [
        "${pkgs.docker}/bin/docker"
        "--name postgres"
        "run"
        "-p 5432:5432"
        "postgres"
      ]
    );

    process-compose = {
      description = "docker container of postgres";
      shutdown = {
        command = "${cfg.package}/bin/docker rm -f postgres";
      };
    };
  };

NikolaiSch avatar Mar 26 '24 14:03 NikolaiSch