LoginSignup
9
1

More than 3 years have passed since last update.

Azure Container InstancesでNervesアプリを開発する

Last updated at Posted at 2020-12-15

この記事は、「Docker Advent Calendar 2020」 7日目です。
あいていたので埋めました。
前日は、@c3driveさんのAWSにコンテナ環境を構築する

はじめに

Dockerfile

# docker-elixir 1.11.2
# https://hub.docker.com/_/elixir
FROM elixir:1.11.2

ENV DEBCONF_NOWARNINGS yes

# Install libraries for Nerves development
RUN apt-get update && \
    apt-get install -y build-essential automake autoconf git squashfs-tools ssh-askpass pkg-config curl openssh-server && \
    rm -rf /var/lib/apt/lists/*

RUN mkdir /var/run/sshd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
COPY ./config_files/id_rsa.pub /root/.ssh/authorized_keys
EXPOSE 22

# [Optional] Uncomment this section to install libraries for customizing Nerves System
#RUN apt-get update && \
#    apt-get install -y libssl-dev libncurses5-dev bc m4 unzip cmake python && \
#    rm -rf /var/lib/apt/lists/*

# Install fwup (https://github.com/fhunleth/fwup)
ENV FWUP_VERSION="1.8.2"
RUN wget https://github.com/fhunleth/fwup/releases/download/v${FWUP_VERSION}/fwup_${FWUP_VERSION}_amd64.deb && \
    apt-get install -y ./fwup_${FWUP_VERSION}_amd64.deb && \
    rm ./fwup_${FWUP_VERSION}_amd64.deb && \
    rm -rf /var/lib/apt/lists/*

# Install hex and rebar
RUN mix local.hex --force
RUN mix local.rebar --force
# Install Mix environment for Nerves
RUN mix archive.install hex nerves_bootstrap 1.10.0 --force

CMD ["/usr/sbin/sshd", "-D"]
$ mkdir config_files
$ cp ~/.ssh/id_rsa.pub config_files/
$ docker build -t docker-nerves .
  • イメージを作ったら、あとの手順は以下のような感じです
  • 以下、もう少し詳しくみていきます

1. Azure Container Registryにイメージを登録

$ docker login xxx.azurecr.io
$ docker tag docker-nerves xxx.azurecr.io/docker-nerves
$ docker push xxx.azurecr.io/docker-nerves

2. Azure Container Instancesでそのカスタムイメージを使うように設定する

スクリーンショット 2020-12-16 0.02.11.png

3. sshで接続してNervesアプリの開発をする

$ ssh root@20.43.93.225

:point_up::point_up_tone1::point_up_tone2::point_up_tone3::point_up_tone4::point_up_tone5:で、コンテナの中に入ります

コンテナの中での操作

$ cd ~/.ssh
$ ssh-keygen -t rsa -b 4096
$ cd
$ mix nerves.new hello_nerves
$ cd hello_nerves
$ export MIX_TARGET=rpi4
$ mix deps.get
$ mix firmware

で、無事にコンテナの中にファームウェア
/root/hello_nerves/_build/rpi4_dev/nerves/images/hello_nerves.fwができます :fire::fire::fire:

Raspberry Pi 4以外の場合は、Targetsから値を選んでください。

開発マシンにもどって

$ scp root@20.43.93.225:/root/hello_nerves/_build/rpi4_dev/nerves/images/hello_nerves.fw .
  • クラウドにあるコンテナからファームウェアをもってきて
  • microSDカードを開発マシンに挿して
$ fwup hello_nerves.fw
  • あっ、fwupのインストール方法を説明していない。。。
  • クラウドのコンテナからRaspberry Piにmix upload(つまりssh)したいという話がでていた部分はこの記事ではなにもできていません

メモ

  • mixコマンドを実行したときに、
warning: the VM is running with native name encoding of latin1 which may cause Elixir to malfunction as it expects utf8. Please ensure your locale is set to UTF-8 (which can be verified by running "locale" in your shell)

という警告がちょいちょいでていました。

Nervesで一体何がつくれるの?

https___qiita-image-store.s3.ap-northeast-1.amazonaws.com_0_131808_decc299d-a6e7-1e9d-2d0e-6bb58c57b476.jpeg

おまけ2 どうやってコンテナの中の.exを編集するの?

スクリーンショット 2020-12-16 8.42.39.png

Wrapping Up :christmas_tree::santa::santa_tone1::santa_tone2::santa_tone3::santa_tone4::santa_tone5::christmas_tree:

  • @takasehideki 先生のDockerfileは書き換えずにそのままで対応できるもっとスマートな方法があるかもしれません
  • クラウドのコンテナからRaspberry Piにmix upload(つまりssh)したい!? というような話には踏み込めていません
  • Enjoy Elixir !!! :rocket::rocket::rocket:
  • この記事をきっかけにNervesに興味をもっていただけましたら、ぜひNervesJPのSlackでお待ちしています!
    • 愉快なfolksたちが歓迎します!!!

https___qiita-user-contents.imgix.net_https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F240349%2F5ef22bb9-f357-778c-1bff-b018cce54948.png_ixlib=rb-1.2.png

明日は、@kosuketakeiさんの文系出身業務経験なしのプログラマーがDocker使ってみた です。引き続きお楽しみください。

9
1
1

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
9
1