docker
crystal
crenv

crenvでcrystalをインストール

公式
crenv

rubyのスクリプトで処理が遅いと思うところでcrystalを取り入れてみようかな、程度のモチベーションで使ってみる。

crystalのDockerfileを示す。

yumで必須はgcc,git

Dockerfile
FROM             centos:centos7.4.1708
MAINTAINER       TestUser
ENV              container docker

##### crystal environment var
ENV              crystal_ver=0.20.0 #最新は投稿時点で0.24.1
ENV              CRENV_ROOT=/usr/local/crenv

##### yum setting & install
RUN              yum update -y && yum clean all
RUN              yum swap -y fakesystemd systemd && yum clean all
#RUN              yum install -y httpd && yum clean all
#RUN              systemctl enable httpd
RUN              yum -y install git gcc-c++\
                     make tar wget openssl openssl-devel \
                     readline readline-devel gdbm-devel libffi-devel zlib-devel \
                     curl-devel procps autoconf sudo bzip2 bzip2-devel gcc postgresql-devel \
                     sqlite sqlite-devel

##### mkdir
# for data persistence on docker.
RUN              mkdir /root/work

##### crystal install
RUN              curl -L https://raw.github.com/pine/crenv/master/install.sh |bash
RUN              echo 'export PATH="${CRENV_ROOT}/bin:$PATH"' >> /etc/profile.d/crenv.sh
RUN              echo 'eval "$(crenv init -)"' >> /etc/profile.d/crenv.sh
RUN              source /etc/profile.d/crenv.sh
RUN              ${CRENV_ROOT}/bin/crenv install "${crystal_ver}"
RUN              ${CRENV_ROOT}/bin/crenv global "${crystal_ver}"

##### expose
EXPOSE           22
EXPOSE           80
EXPOSE           443
EXPOSE           5432
EXPOSE           8000
EXPOSE           8001

追加

docker-composeでcrystal playを立ち上げるようにしておく。
ちな、0.24.1ではバグでplayが上記のインストール手順ではうまく動かない。

/usr/local/crenv/shims/crystal play
can't find file 'compiler/crystal/tools/playground/server.cr'
???
???
???
???
???

Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
version: '3'

services:
  crystal:
    build:
      context: .
    user: root
    volumes:
       - "./work:/root/work"
    privileged: true
    ports:
      #- "4444:4444"
      #- "18080:18080"
      - "8001:8001"
    restart: unless-stopped
    command: /usr/local/crenv/shims/crystal play -b 0.0.0.0 -p 8001

docker-compose up -dで立ち上げるとlocalhost:8001でplaygroundが使える。