溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在docker上裝elmlang可視調(diào)試編碼器ellie

發(fā)布時間:2021-12-13 13:49:55 來源:億速云 閱讀:152 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要講解了“怎么在docker上裝elmlang可視調(diào)試編碼器ellie”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么在docker上裝elmlang可視調(diào)試編碼器ellie”吧!

好了,在針對prod的dockerfile和docker-compose.yml作修改之前,先改幾個源碼中的文件:

配置文件config/prod.exs中的config :ellie, Ellie.Repo段

在adpter條目下增加:

  username: "postgres",
  password: "postgres",
  database: "ellie",
  hostname: "database",
  port: 5432,
  ssl: false,

以上是ellie container實例啟動時連接postgresql實例的配置。

database是數(shù)據(jù)庫所在主機的主機名,docker-compose.yml中數(shù)據(jù)庫 postgresql9.5對應(yīng)container的ID,一般是database,對于那個ssl,如果不加ssl,會在運行時出現(xiàn)ssl not avaliable

config :logger段也換成這個:config :logger, :console, format: "[$level] $message\n",否則接下來被一個run.sh包含的phx.server控制臺不出任何信息。

assets/package-lock.json中,找到natives,升級一下其版本

"natives": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/natives/-/natives-1.1.6.tgz" },

以上是為了在防止nodejs在編譯deps時出現(xiàn)natives有關(guān)的錯誤。

dockerfile中:

DEPS下加一段安裝postgresql-client:

# Install postgres-client
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" >> /etc/apt/sources.list.d/pgdg.list \
    && wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - \
    && apt-get update \
    && apt-get -yq --no-install-recommends install inotify-tools postgresql-client-9.5

然后就是dockerfile主體部分了:

# Download Elm platform binaries
RUN mkdir -p /tmp/elm_bin/0.18.0 && mkdir -p /tmp/elm_bin/0.19.0 \
    # goon executable for Procelain Elixir library, to run executables in Elixir processes
    && wget -q https://github.com/alco/goon/releases/download/v1.1.1/goon_linux_386.tar.gz -O /tmp/goon.tar.gz \
    && tar -xvC /tmp/elm_bin -f /tmp/goon.tar.gz \
    && chmod +x /tmp/elm_bin/goon \
    && rm /tmp/goon.tar.gz \
    # Elm Platform 0.18
    && wget -q https://github.com/elm-lang/elm-platform/releases/download/0.18.0-exp/elm-platform-linux-64bit.tar.gz -O /tmp/platform-0.18.0.tar.gz \
    && tar -xvC /tmp/elm_bin/0.18.0 -f /tmp/platform-0.18.0.tar.gz \
    && rm /tmp/platform-0.18.0.tar.gz \
    # Elm Format 0.18
    && wget -q https://github.com/avh5/elm-format/releases/download/0.7.0-exp/elm-format-0.18-0.7.0-exp-linux-x64.tgz -O /tmp/format-0.18.0.tar.gz \
    && tar -xvC /tmp/elm_bin/0.18.0 -f /tmp/format-0.18.0.tar.gz \
    && rm /tmp/format-0.18.0.tar.gz \
    && chmod +x /tmp/elm_bin/0.18.0/* \
    # Elm Platform 0.19
    && wget -q https://github.com/elm/compiler/releases/download/0.19.0/binaries-for-linux.tar.gz -O /tmp/platform-0.19.0.tar.gz \
    && tar -xvC /tmp/elm_bin/0.19.0 -f /tmp/platform-0.19.0.tar.gz \
    && rm /tmp/platform-0.19.0.tar.gz \
    && chmod +x /tmp/elm_bin/0.19.0/* \
    # Elm Format 0.19
    && wget -q https://github.com/avh5/elm-format/releases/download/0.8.0-rc3/elm-format-0.19-0.8.0-rc3-linux-x64.tgz -O /tmp/format-0.19.0.tar.gz \
    && tar -xvC /tmp/elm_bin/0.19.0 -f /tmp/format-0.19.0.tar.gz \
    && rm /tmp/format-0.19.0.tar.gz \
    && chmod +x /tmp/elm_bin/0.19.0/* \
    # 以上都是準(zhǔn)備elmlang的binaries到tmp下的原邏輯,,以下準(zhǔn)備整個app執(zhí)行環(huán)境,命名為tmp2是為了將這二步驟以對應(yīng)的方式列出。
    # 這里的tmp2,其實對應(yīng)原版的dockerfile中是 add . /app,只是原版的構(gòu)建出來在單機跑起來沒事,在遷移安裝到別的docker主機上跑起來,會提示找不到文件(定位不到正確的app頂層。所以deps.get時會找不到package.json等,entrypoint也找不到run.sh)。你多構(gòu)建幾次原版dockerfile與這里對比就知道了。
    # 你可能已經(jīng)注意到這條很長的RUN,它將所有關(guān)于生成app的邏輯都維持在一個RUN中,否則就超了docker構(gòu)建時的分層文件系統(tǒng)了,會導(dǎo)致不意料的事情發(fā)生。猜測原版 add . /app 就是沒有維持在同一個文件系統(tǒng)中。docker-compose.yml中的volume也會不能生效。
    && git clone https://github.com/minlearn/ellie-corrected /tmp2 \
    && mkdir -p /tmp2/priv/bin \
    && cp -r /tmp/elm_bin/* /tmp2/priv/bin \
    && mkdir -p /tmp2/priv/elm_home \
    # 安裝elixir相關(guān)的所有擴展并生成項目的數(shù)據(jù)庫文件
    && cd /tmp2 \
    && mix deps.get \
    && mix compile \
    && mix do loadpaths, absinthe.schema.json /tmp2/priv/graphql/schema.json \
    ## 安裝nodejs相關(guān)的所有擴展,并生成項目的webpack靜態(tài)文件
    && cd /tmp2/assets \
    && npm install \
    && npm run graphql \
    && npm run build

至此,生成構(gòu)建了所有項目運行時的資源。

已經(jīng)差不多可以運行了。準(zhǔn)備ENV預(yù)定義的參數(shù),docker run時會欠入到實例:

ENV MIX_ENV=prod \
    NODE_ENV=production \
    PORT=4000 \
    ELM_HOME=/tmp2/priv/elm_home \
  SECRET_KEY_BASE="+ODF8PyQMpBDb5mxA117MqkLne/bGi0PZoTl5uIHAzck2hDAJ8uGJPzark0Aolyi"

定義運行

# WORKDIR的主要作用就是定義接下來所有指令,尤其是entrypoint等的路徑
WORKDIR /tmp2
EXPOSE 4000
RUN chmod +x /tmp2/run.sh
ENTRYPOINT ["/tmp2/run.sh"]

這個run.sh是分離postgresql所在容器和ellie所在容器的entrypoint,所有連接數(shù)據(jù)庫初始化的工作都要在這里完成,因為它繼承了ENV關(guān)于prod的預(yù)埋參數(shù)所以運行時不會出錯,否則比如在非docker構(gòu)建的情況下,你把mix phx.server單獨在命令行中執(zhí)行,會出現(xiàn)如下錯誤:(EXIT) no process: the process is not alive or there's no process currently associated with the given name。你就需要在run.sh中export所有這些參數(shù),這也是docker的聯(lián)合文件系統(tǒng)在編譯(dockerfile)/運行(run.sh)不同階段需要做到邏輯同步的要求。

run.sh的內(nèi)容(它是git repos中要新增的一個文件,需提交到新git repos中):

#! /usr/bin/env bash
set -e
cd /tmp2
until PGPASSWORD=postgres psql -h "database" -U "postgres" -c '\q'; do
  >&2 echo "Postgres is unavailable - sleeping"
  sleep 5
done
mix ecto.create
mix ecto.migrate
mix phx.server

最后,docker-compose.yml也一目了然了。

ellie:
  image: minlearn/ellie-corrected
  links:
  - database:database
  ports:
  - 4000:4000
  restart: always
  environment:
  - SERVER_HOST=52.81.25.39
database:
  image: postgres:9.5
  environment:
  - POSTGRES_PASSWORD=postgres
  restart: always

minlearn/ellie-corrected是我在dockerhub上編譯正確的ellie,實際上,上面的ellie的volumes同樣是沒有起作用的。留給其它人解決吧(這就是分層文件系統(tǒng)給人理解上帶來的極大不便)。反正項目部署到任何支持docker的機器都可以啟動并進(jìn)入ellie所在IP:4000的界面了。

假設(shè)上面的沒加SERVER_HOST,進(jìn)去你會發(fā)現(xiàn)ip:4000/new顯示ellie的動畫,但一直hangout,控制臺顯示,[error] Could not check origin for Phoenix.Socket transport.

這就需要設(shè)置SERVER_HOST=ip變量了(這個ip是你部署ellie所在機器的外網(wǎng)IP或被訪問IP:4000所在的IP),這個變量不能放在dockerfile中,也不能放在run.sh中(因為這二個文件要做進(jìn)docker image中的,而你無法預(yù)知要將這個docker image放哪個IP的主機上),故要放在docker-compose.yml中ellie段下在實際開啟ellie container時指定,比如我部署運行時的IP是52.81.25.39。

感謝各位的閱讀,以上就是“怎么在docker上裝elmlang可視調(diào)試編碼器ellie”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么在docker上裝elmlang可視調(diào)試編碼器ellie這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI