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

[Discuss] How to let CIDER make use of Clojure docker image? #2552

Closed
stardiviner opened this issue Dec 25, 2018 · 8 comments
Closed

[Discuss] How to let CIDER make use of Clojure docker image? #2552

stardiviner opened this issue Dec 25, 2018 · 8 comments

Comments

@stardiviner
Copy link
Contributor

This is a discuss, but in order to keep records down, and might help other people. So I record it here. I know there is a channel #cider/#emacs on Slack. I will post this link over there.

I want to use different version and environment of Clojure. There is an official Clojure Docker image. https://hub.docker.com/_/clojure

I'm thinking how to use Clojure image's binary and REPL in Emacs, and CIDER.

There are some ways can access Docker image as I know:

  • running container which started Clojure REPL, user can attach it with Emacs package docker.el.
  • use Emacs package docker-tramp.el and docker.el to access clojure container binary commands like clojure, clj etc. So that Emacs use them as executable command path. Like CIDER has customize option cider-clojure-cli-command. I tried following, but failed.
(add-to-list 'exec-path "/docker:clojure:/usr/local/bin/")
(setq cider-clojure-cli-command "/docker:clojure:/usr/local/bin/clojure")
  • run the clojure image to expose the ip:port to host system. So that Emacs can access the Docker container just like host system local. I don't know how to do that yet.

Anyone have suggestion and solution? Welcome to add. (This might could add to Wiki, when the discussion is almost) Thanks for viewing.

@stardiviner
Copy link
Contributor Author

I found CIDER has an variable to keep connection records. Could be used in upper mentioned case.

Like this:

(setq cider-known-endpoints
  '(("host-a" "10.10.10.1" "7888")
    ("host-b" "7888")))

@stardiviner
Copy link
Contributor Author

  • use CIDER remote host SSH support to SSH into Docker container
  • Use CIDER transparent TRAMP support to use Emacs package docker-tramp.el to open files on container, then cider-jack-in-*, CIDER could transparently handling this.

@darkleaf
Copy link
Contributor

I use docker-compose and volumes:

# docker-compose.yml
version: '3'

volumes:
  m2:
  gitlibs:

services:
  app:
    image: clojure:tools-deps-alpine
    working_dir: "${PWD}"
    command: "true"
    ports:
      - "4444:4444" # nrepl
      - "4445:4445" # http
    environment:
      - "CLJ_CONFIG=${PWD}/.docker-clojure"
      - DATABASE_URL=postgres://postgres:password@db:5432/postgres
      - TEST_DATABASE_URL=postgres://postgres:password@test-db:5432/postgres
      - PORT=4446
    volumes:
      - ".:${PWD}:cached" # cached - MacOS option
      - m2:/root/.m2
      - gitlibs:/root/.gitlibs
    links:
      - db
      - test-db
  db: &db
    image: postgres:10.4-alpine
    environment:
      - POSTGRES_PASSWORD=password
  test-db:
    <<: *db
;; .docker-clojure/deps.edn
{:aliases {:cider {:extra-deps {darkleaf/cider-tools-desp
                                {:git/url "https://github.com/darkleaf/cider-tools-deps.git"
                                 :sha     "1025b510db24b36ab741bc5599e36806eec904ec"}}
                   :main-opts  ["-m" "darkleaf.cider-tools-deps"
                                "port" "4444" "host" "0.0.0.0"]}
           :repl  {:extra-deps {darkleaf/repl-tools-deps
                                {:git/url "https://github.com/darkleaf/repl-tools-deps.git"
                                 :sha     "04e128ca67785e4eb7ccaecfdaffa3054442358c"}}
                   :main-opts  ["-m" "darkleaf.repl-tools-deps"]}

           :run-tests {:extra-deps {com.cognitect/test-runner
                                    {:git/url "https://github.com/cognitect-labs/test-runner.git"
                                     :sha     "028a6d41ac9ac5d5c405dfc38e4da6b4cc1255d5"}}
                       :main-opts  ["-m" "cognitect.test-runner"]}

           :coverage {:extra-deps {cloverage {:mvn/version "1.0.13"}}
                      :main-opts  ["-m" "cloverage.coverage" "-p" "src"  "-s" "test"]}}}

I run docker-compose run --rm --service-port app bash and than clojure -Acider.
In emacs I press C-c M-c and connect to localhost:4444.

Dependencies are installed into volumes. So Emacs can't have access to them.

@stardiviner
Copy link
Contributor Author

Dependencies are installed into volumes. So Emacs can't have access to them.

I'm confused on this. Dependencies are installed into volumes, but Emacs CIDER connect to container started clojure -Acider alias. So if clojure -Acider should be able to access all dependencies in container. Add project dependencies into a container deps.edn file?

Can Docker access host system's .m2/ dependencies? So that Docker will be a bridge between Emacs CIDER and host system dependencies.

@zilti
Copy link

zilti commented Dec 27, 2018

We have Maven and tools like Boot and Leiningen, why on earth would Docker be even necessary here? Just because it's trendy?

@darkleaf
Copy link
Contributor

@stardiviner

I'm confused on this.

REPL is started inside a docker container. This process have access to container file system
with container related paths. Lock at volumes section:

    volumes:
      - ".:${PWD}:cached" # cached - MacOS option
      - m2:/root/.m2
      - gitlibs:/root/.gitlibs

$PWD is /User/darkleaf/projects/project for example. So the project sources are
available in the same path inside container .
It's make sense. REPL can send to Emacs some path and that path is container related.
Emacs can't get a file on host file system if paths are inconsistent.
So I use ${PWD}.

Later I used to mount .m2 and .gitlibs from host file system.
I use Docker for Mac and it's host volumes are slow. So I switched to container volumes.

@stardiviner
Copy link
Contributor Author

@darkleaf I see. Thanks.

@zilti switch Java version, Clojure version is simpler on Docker? and It's cleaner. Easy to package image then share, simpler to reproduce environment issue. I admit Leiningen and Boot (I have not use it myself) is great. Still thanks for your advice.

@bbatsov
Copy link
Member

bbatsov commented Mar 13, 2019

Seems you've sorted this out, so I'll close this ticket.

@bbatsov bbatsov closed this as completed Mar 13, 2019
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

No branches or pull requests

4 participants