9
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Julia] web アプリをJuliaで作る

Posted at

何のメモ?

JuliaでGenieを使ってWebアプリを作ろうと思った際の覚書。
Dockerで実装するとちょっとハマるのでそのことを書ておく。

どんなときに役立つの?

Dockerで web application for Julia な環境を作る。

Juliaとは

以前の記事参照:https://qiita.com/risa0320/items/b10e1457b58de64687ce

Genieとは

Julia の web Framework。
https://genieframework.com/
https://genieframework.github.io/Genie.jl/dev/index.html

使った環境

  • Docker version 19.03.12
  • docker-compose version 1.26.2

Genie の使い方

install


julia> ] 
pkg> add Genie
julia> using Genie

Genie アプリ作成

プロジェクトをこれで作成するとTemplate一式が作成され、るので便利。

julia> using Genie
julia> Genie.newapp("app_name")

ルーティング登録

routing.jl
using Genie
import Genie.Router: route

route("/") do
  "Hellow - Welcome to Genie!"
end

サーバとして起動

ここがDockerでの注意ポイント。
次の項目で説明する。

start_app.jl
using Genie

Genie.config.run_as_server = true
Genie.AppServer.startup(8000)

これで、 http://localhost:8000 もしくは http://127.0.0.1:8000 でブラウザから確認できる。

Dockerで web app for julia コンテナで実現する

Dockerfile
FROM julia:1.5

RUN julia -e 'using Pkg; Pkg.add("Genie");' && ¥
  julia -e 'using Genie; Genie.newapp("app_name");'
docker-compose.yaml
version: '3'
services:
  web_app:
    container_name: web_app
    build: ./
    environment:
      TZ: 'Asia/Tokyo'
    ports:
     - 8000:8000
    volumes:
     - ./:/julia_app
    working_dir: /julia_app
    command: julia start_app.jl
start_app.jl
using Genie
import Genie.Router: route

Genie.config.run_as_server = true

route("/") do
  "Hello - Welcome to Genie!"
end
# docker を使う場合は "0.0.0.0"を指定しないと動作しない!
Genie.AppServer.startup(8000, "0.0.0.0") 

参考記事

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?