LoginSignup
3
3

More than 5 years have passed since last update.

rustとscalaとkotilnの勉強 環境構築

Last updated at Posted at 2018-05-14

rustとscalaとkotkinを勉強しようと思う。
以前、common lispとrubyとpythonを同時に勉強したんだけど今回はこの3つ。
他にも候補はあった。
Elixir:静的型の方がどうしてもスキだから落選。でもその内やってみたい。
swift:iOS以外で使われる未来が見えない+後述の理由でlinuxで動かす必要があり落選。
haskell:頭いい人向けすぎだから僕には無理。

結局、rust、scala、kotlinになった。

で勉強にむけて環境の構築から。
まず大きな縛りとして、

iPhoneで勉強できること

がある。
理由は「通勤中くらいしか勉強できない」から。
子供がまだ1歳ってこともあり帰宅後、休日は子供と遊びたい。娘可愛い。

というわけでiPhoneで勉強できる状況をつくるべく頑張った。

まだhello worldくらいしかやってないので変わるかもしれないけど今は以下の構成。

さくらvpsにcentos7+docker
でその上に各言語のコンテナ動かす

iPhoneからはpromptでssh接続
sshでつないでコンテナ起動してソースはvimで書く感じ。
sftpでssh越しのファイルをいじれるエディタも試したが、コンパイルしたり実行したりするときに別のアプリに切り替えるのが面倒でvimで落ち着いている。
たいしたソースの量じゃないから耐えられてるのかもしれない。

sbtやらgradleやらのキャッシュと書いたソースはホストのディレクトリをコンテナでマウントしてそこに置く。

ホストのディレクトリはこんな感じ
~/study/rust
~/study/kotlin
~/study/scala
~/dockers/rust/.zshrc
~/dockers/rust/.vimrc
~/dockers/rust/.emacs
~/dockers/rust/Dockerfile
~/dockers/scala/.zshrc
~/dockers/scala/.vimrc
~/dockers/scala/.emacs
~/dockers/scala/Docketfile
~/dockers/kotlin/.zshrc
~/dockers/kotlin/.vimrc
~/dockers/kotlin/.emacs
~/dockers/kotlin/Dockerfile

各言語のDockerfileは以下
rust

FROM    rust:1.25.0
MAINTAINER xxx <xxx@xxx>

RUN apt-get update
RUN apt-get install -y sudo
RUN apt-get install -y vim-nox
RUN apt-get install -y zsh
RUN apt-get install -y emacs-nox

RUN apt-get install -y locales
RUN localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja

RUN echo "xxx ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/xxx

RUN groupadd -g 1000 wheel \
    && useradd  -g wheel -G sudo -m -s /bin/bash xxx \
    && echo 'xxx:pass' | chpasswd \
    && echo 'root:pass' | chpasswd

ENV USER xxx
USER xxx

COPY .emacs /home/xxx/
COPY .vimrc /home/xxx/
COPY .zshrc /home/xxx/

RUN mkdir -p /home/xxx/study/rust

Build

docker build --force-rm=true -t rust.v04.1.25.0 .

実行

docker run -it -v /home/xxx/study/rust:/home/xxx/study/rust -w /home/xxx/study/rust -u xxx rust.v04.1.25.0 /bin/zsh

scalaはこれ

FROM openjdk:8u151-jdk
MAINTAINER xxx <xxx@xxx>

RUN apt-get update
RUN apt-get install -y sudo
RUN apt-get install -y vim-nox
RUN apt-get install -y zsh
RUN apt-get install -y emacs-nox

RUN apt-get install -y locales
RUN localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV SCALA_VERSION=2.12.5
ENV SBT_VERSION=1.1.4

RUN echo "xxx ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/xxx

RUN groupadd -g 1000 wheel \
    && useradd  -g wheel -G sudo -m -s /bin/bash xxx  \
    && echo 'xxx:pass' | chpasswd \
    && echo 'root:pass' | chpasswd

ENV SCALA_VERSION=2.12.5
ENV SBT_VERSION=1.1.4

RUN apt-get update \
    && wget https://downloads.lightbend.com/scala/${SCALA_VERSION}/scala-${SCALA_VERSION}.deb \
    && dpkg -i scala-${SCALA_VERSION}.deb \
    && rm -f scala-${SCALA_VERSION}.deb

RUN curl -sL https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.tgz | tar xzf - -C /usr/local \
    && ln -s /usr/local/sbt/bin/sbt /usr/local/bin/sbt

RUN apt-get autoremove
RUN apt-get autoclean

USER xxx

RUN mkdir -p /home/xxx/study/scala

RUN pwd \
    && cd /home/xxx \
    && sbt about

COPY .emacs /home/xxx/
COPY .vimrc /home/xxx/
COPY .zshrc /home/xxx/

Build

docker build --force-rm=true -t  scala.v01.2.12.5 .

実行

docker run -it -v /home/xxx/study/scala:/home/xxx/study/scala -w /home/xxx/study/scala -u xxx scala.v01.2.12.5 /bin/zsh 

kotlinがこれ

FROM openjdk:8u151-jdk
MAINTAINER xxx   <xxx@xxx>

RUN apt-get update
RUN apt-get install -y sudo
RUN apt-get install -y vim-nox
RUN apt-get install -y zsh
RUN apt-get install -y emacs-nox

RUN apt-get install -y locales
RUN localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja

RUN echo "xxx ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/xxx

RUN groupadd -g 1000 wheel \
    && useradd  -g wheel -G sudo -m -s /bin/bash xxx  \
    && echo 'xxx:pass' | chpasswd \
    && echo 'root:pass' | chpasswd

ENV KOTLIN_VERSION=1.2.40

RUN apt-get install -y gradle

RUN cd /tmp && curl -sL https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip -O
RUN cd /tmp && unzip kotlin-compiler-${KOTLIN_VERSION}.zip -d /opt

RUN apt-get autoremove
RUN apt-get autoclean

USER xxx

RUN mkdir -p /home/xxx/study/kotlin
ENV PATH $PATH:/opt/kotlinc/bin
ENV GRADLE_USER_HOME /home/xxx/study/kotlin/.gradle
COPY .emacs /home/xxx/
COPY .vimrc /home/xxx/
COPY .zshrc /home/xxx/

Build

docker build --force-rm=true -t  kotlin.v01.1.2.40 .

実行

docker run -it -v /home/xxx/study/kotlin:/home/xxx/study/kotlin -w /home/xxx/study/kotlin -u xxx kotlin.v01.1.2.40 /bin/zsh
3
3
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
3
3