4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

clojureの環境構築

Last updated at Posted at 2021-09-01

はじめに

最近、clojureと言う言語を聞いたので、その環境構築を行いました。
clojureはLISPをJVM仮装マシン上で動けるようにしたものです。

レポジトリはこちら

dockerのビルド

ディレクトリ構成

初回インストールを行うために以下の構成にしてあります。
後で、変更します。

├── Dockerfile
├── docker-compose.yaml
Dockerfile
FROM clojure:openjdk-8
WORKDIR /usr/src/app

# bashは入れても入れなくてもどっちでもいいです。
RUN apt-get update && apt-get install --no-install-recommends -y bash=5.0-4 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
docker-compose.yaml
version: '3'
services:
  clojure:
    build: .
    tty: true # 後で、コンテナ内に入るため。終わったら消す。

インストールと永続化

docker-compose exec clojure bash -c "lein new app workspace"
docker cp `docker-compose ps -q clojure`:/usr/src/app/workspace/ ./

docker-compose.yamlを書き換える。

docker-compose.yaml
version: '3'
services:
  clojure:
    build: .
    command: 'lein run'
    working_dir: /usr/src/app/workspace
    volumes:
      - ./workspace:/usr/src/app/workspace

最終的なディレクトリ構成

作られたディレクトリの中身は完全にjavaですね。

├── Dockerfile
├── docker-compose.yaml
└── workspace
    ├── CHANGELOG.md
    ├── LICENSE
    ├── README.md
    ├── doc
    │   └── intro.md
    ├── project.clj
    ├── resources
    ├── src
    │   └── workspace
    │       └── core.clj
    ├── target
    │   └── default
    │       ├── classes
    │       │   └── META-INF
    │       │       └── maven
    │       │           └── workspace
    │       │               └── workspace
    │       │                   └── pom.properties
    │       └── stale
    │           └── leiningen.core.classpath.extract-native-dependencies
    └── test
        └── workspace
            └── core_test.clj

Hello, World!

最後に、docker compose up!!!

> docker compose up
Attaching to clojure_1
clojure_1  | Retrieving org/clojure/clojure/1.10.1/clojure-1.10.1.pom from central
clojure_1  | Retrieving org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.pom from central
clojure_1  | Retrieving org/clojure/pom.contrib/0.2.2/pom.contrib-0.2.2.pom from central
clojure_1  | Retrieving org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.pom from central
clojure_1  | Retrieving org/clojure/clojure/1.10.1/clojure-1.10.1.jar from central
clojure_1  | Retrieving org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar from central
clojure_1  | Retrieving org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar from central
clojure_1  | Hello, World!
clojure_1 exited with code 0

ビルドしていなければ、勝手にビルドしてくれるみたいですね。
ここは、go,javaよりも便利ですね。

workspace/src/workspace/core.clj
(ns workspace.core
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

このファイルを書くかえれば、コーディングが行えます。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?