LoginSignup
3
0

More than 1 year has passed since last update.

Elixirで作ったSlackアプリをHacobuneでイゴかす (2021/12/14)

Last updated at Posted at 2021-12-13

2021/12/14(火)の回です。

はじめに

What is Hacobune ?

Hacobuneは、当社が「インフラを意識しない世界を実現する」をビジョンに開発したPaaS型クラウドサービスです。スタートアップ企業や少人数でのサービスの開発を行うお客さまなど、スモールスタートでの開発に適しています。Hacobuneを利用することで、インフラの構築が不要となり、お客さまはアプリケーションの開発およびアップデートのみに専念することができ、サービスリリースのサイクルを加速させることが可能となります。

(https://www.sakura.ad.jp/information/announcements/2021/08/12/1968207782/)

ハイライト

Dockerfileをつくればでデプロイできちゃいます :rocket::rocket::rocket:

ソースコード

Dockerfile

:point_up::point_up_tone1::point_up_tone2::point_up_tone3::point_up_tone4::point_up_tone5: のガイドを参考にしています。

Dockerfile
ARG MIX_ENV="prod"

FROM hexpm/elixir:1.12.3-erlang-24.1.4-alpine-3.13.6 as build

# install build dependencies
RUN apk add --no-cache build-base git python3 curl

# prepare build dir
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ARG MIX_ENV
ENV MIX_ENV="${MIX_ENV}"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/$MIX_ENV.exs config/
RUN mix deps.compile

COPY priv priv

# note: if your project uses a tool like https://purgecss.com/,
# which customizes asset compilation based on what it finds in
# your Elixir templates, you will need to move the asset compilation
# step down so that `lib` is available.
COPY assets assets
RUN mix assets.deploy

# compile and build the release
COPY lib lib
RUN mix compile
# changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM alpine:3.13.6 AS app
RUN apk add --no-cache libstdc++ openssl ncurses-libs

ARG MIX_ENV
ENV USER="elixir"

WORKDIR "/home/${USER}/app"
# Creates an unprivileged user to be used exclusively to run the Phoenix app
RUN \
  addgroup \
   -g 1000 \
   -S "${USER}" \
  && adduser \
   -s /bin/sh \
   -u 1000 \
   -G "${USER}" \
   -h "/home/${USER}" \
   -D "${USER}" \
  && su "${USER}"

# Everything from this line onwards will run in the context of the unprivileged user.
USER "${USER}"

COPY --from=build --chown="${USER}":"${USER}" /app/_build/"${MIX_ENV}"/rel/slack_doorman ./

ENTRYPOINT ["bin/slack_doorman"]

# Usage:
#  * build: sudo docker image build -t elixir/slack_doorman .
#  * shell: sudo docker container run --rm -it --entrypoint "" -p 127.0.0.1:4000:4000 elixir/slack_doorman sh
#  * run:   sudo docker container run --rm -it -p 127.0.0.1:4000:4000 --name my_app elixir/slack_doorman
#  * exec:  sudo docker container exec -it slack_doorman sh
#  * logs:  sudo docker container logs --follow --tail 100 slack_doorman
CMD ["start"]

たぶん

に該当することをしているのだとおもいます。

Hacobuneへのデプロイ

:point_up::point_up_tone1::point_up_tone2::point_up_tone3::point_up_tone4::point_up_tone5:公式ドキュメントです。

事前準備

デプロイ方法は次の3種類とのことです。

①パブリックのDockerイメージを使用
②プライベートのDockerイメージを使用
③GitHubレポジトリをHacobuneに接続して使用(Dockerfileが必須)

①パブリックのDockerイメージを使用を説明します。
dockerhubを使う例で書きます。

$ docker build -t slack_doorman .
$ docker tag slack_doorman <your_username>/slack_doorman
$ docker login
$ docker push torifukukaiou/slack_doorman

Hacobune

に従ってすすめるとよいです。
こんな感じです。

スクリーンショット 2021-11-24 20.42.14.png

  • ポートは4000です。
  • 外部公開は有効にします(SlackからHTTP Postしてもらうため)

あとは環境変数の設定を行ってください。
先述のslack_doormanでは次の3つの環境変数を設定する必要があります。

  • SLACK_SIGNING_SECRET
  • SLACK_BOT_TOKEN
  • SECRET_KEY_BASE
    • mix phx.gen.secret で作成

たったこれだけで、しかもいまなら無料!!! で、Slackアプリをイゴかすことができます:tada::tada::tada:

$\huge{Thank\ you\ very\ much!!!}$

Wrapping up :lgtm::lgtm::lgtm::lgtm::lgtm::lgtm::lgtm::lgtm:

Enjoy docker!!!
Enjoy Slack!!!
Enjoy Hacobune!!!

人間五十年 下天の内をくらぶれば、夢幻のごとくなり。一度生を得て滅せぬ者のあるべきか

時は今あめが下知る五月かな

露と落ち露と消えにしわが身かななにはのことも夢のまた夢

親思ふ心にまさる親心 今日のおとづれ何と聞くらん


おまけ

Elixirを始めてみよう! とおもった、あなたに参考情報(クリスマス🎄プレゼント)を贈ります。:gift::gift::gift:
思い立ったが吉日です!!!

オススメの書籍 :books:

Webアプリケーションを楽しむなら

IoTを楽しむなら

AIを楽しむなら

コミュニティ

FCOvBkAUYAE6mL8.jpeg
@piacerex さん作 :pray::pray_tone1::pray_tone2::pray_tone3::pray_tone4::pray_tone5:


  1. 「動かしてみます」の意。おそらく西日本の方言、たぶん。NervesJPではおなじみ。少し古いオートレースの映像ですが、実況アナウンサーが「針2イゴきます」とはっきり言っています。https://autorace.jp/netstadium/SearchMovie/Movie/iizuka?date=2017-01-04&p=5&race_number=11&pg=  

  2. 大時計の針のこと。針がイゴいてある地点まで到達すると選手はスタートを切って良い発走の合図。針がイゴきはじめると(おそらく)選手は緊張するし、スタートはその後のレース展開に大きく影響するので、車券を握りしめている観客たちがもっとも緊張する瞬間であるため、先の尖った鋭いものを連想させる針は緊張の暗喩としても言い得て妙。 

3
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
3
0