Swift WebフレームワークKituraをDocker on Amazon EC2で動かしてみた
2016/02/24 10:30追記 : IBM Container for Bluemixの情報を追記しました
ども、大瀧です。 本日公開されたIBM製Swift WebフレームワークKituraを、AWSでしかもDockerで動作させてみたのでご紹介します。
KituraはLinuxで動く
Bluemixのページでは当然KituraをIBM Bluemixで動作させる様子が全面に紹介されていますが、Swift自体はLinuxで動作することが知られているのでAmazon EC2やDockerで動作させることも出来るのでは?と思い立った次第です。
GitHubの手順に従うよう、Dockerfile
を作成しました。
FROM ubuntu:wily RUN apt-get update && apt-get install -y \ git \ libhttp-parser-dev libcurl4-openssl-dev libhiredis-dev \ clang libicu-dev \ dh-autoreconf pkg-config libkqueue0 libkqueue-dev libbsd-dev libblocksruntime-dev \ wget \ && rm -rf /var/lib/apt/lists/* RUN wget https://swift.org/builds/development/ubuntu1510/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10.tar.gz && \ tar zxf swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10.tar.gz && \ mkdir -p /opt/swift && \ mv swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10/usr/ /opt/swift/ ENV PATH /opt/swift/usr/bin:$PATH RUN git clone -b opaque-pointer git://github.com/seabaylea/swift-corelibs-libdispatch && \ cd swift-corelibs-libdispatch && sh ./autogen.sh && ./configure && make && make install ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH RUN wget https://github.com/IBM-Swift/Kitura/raw/master/Sources/Modulemaps/module.modulemap -O /usr/local/include/dispatch/module.modulemap RUN wget http://ftp.exim.org/pub/pcre/pcre2-10.20.tar.gz && \ tar zxf pcre2-10.20.tar.gz && \ cd pcre2-10.20/ && \ ./configure && make && make install RUN git clone https://github.com/IBM-Swift/Kitura.git && \ cd Kitura/ && \ swift build ; \ make CMD ./Kitura/.build/debug/KituraSample
動作確認
- AMI : ubuntu-wily-15.10-amd64-server-20160217.1 (ami-552a2b3b) (東京リージョン)
- Docker : バージョン 1.10.2, build c3959b1
上記Dockerfile
を保存し、Dockerイメージの作成、実行するだけです。サンプルアプリケーションKituraSample
は8090ポートをListenするのでポートをアサインし、curl
でアクセスしています。
$ sudo docker build -t takipone/kitura . : (略) $ sudo docker run -d -p 8090:8090 takipone/kitura $ curl localhost:8090 You're running Kitura $
動きました!
IBM公式Dockerイメージもあるよ(でも動かない)
BluemixにはIBM Container for BluemixというDocker対応サービスがあるので、Docker Hubにそれらしいイメージを見つけることができました。
- Docker Hub (ibmcom/kitura-ubuntuイメージ)
- IBM-Swift/kitura-ubuntu-docker (Dockerfileのソース)
ただ、手元でpull
して試してみた限りではエラーで動きませんでした。Bluemix専用の構成があるのかもしれません。
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 50c224b55be8 ibmcom/kitura-ubuntu:latest "/bin/sh -c /root/ci." 12 minutes ago Exited (2) 11 minutes ago admiring_meitner $ docker logs 50c224b55be8 >> About to clone branch 'master' for Kitura Cloning into 'Kitura'... >> About to build Kitura... Cloning https://github.com/IBM-Swift/Kitura-router.git Using version 0.2.0 of package Kitura-router Cloning https://github.com/IBM-Swift/Kitura-net.git Using version 0.2.0 of package Kitura-net Cloning https://github.com/IBM-Swift/Kitura-sys.git Using version 0.2.0 of package Kitura-sys Cloning https://github.com/IBM-Swift/LoggerAPI.git Using version 0.2.0 of package LoggerAPI Cloning https://github.com/IBM-Swift/BlueSocket.git Using version 0.0.4 of package BlueSocket Cloning https://github.com/IBM-Swift/Kitura-CurlHelpers.git Using version 0.2.0 of package Kitura-CurlHelpers Cloning https://github.com/IBM-Swift/Kitura-HttpParserHelper.git Using version 0.2.0 of package Kitura-HttpParserHelper Cloning https://github.com/IBM-Swift/Kitura-Pcre2.git Using version 0.2.0 of package Kitura-Pcre2 Cloning https://github.com/IBM-Swift/SwiftyJSON.git Using version 3.1.0 of package SwiftyJSON Cloning https://github.com/IBM-Swift/HeliumLogger.git Using version 0.2.0 of package HeliumLogger Cloning https://github.com/IBM-Swift/Kitura-TestFramework.git Using version 0.2.0 of package Kitura-TestFramework Compiling Swift Module 'LoggerAPI' (1 sources) /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:37:68: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public static func verbose(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:38:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__ ) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:38:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__ ) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:43:64: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func info(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:44:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:44:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:49:67: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func warning(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:50:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:50:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:55:65: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func error(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:56:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:56:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:61:65: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func debug(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:62:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:62:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file Linking Library: .build/debug/LoggerAPI.a Compiling Swift Module 'KituraSys' (4 sources) <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: build had 1 command failures swift-build: error: exit(1): ["/root/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/root/Kitura/.build/debug/Kitura-Sys.o/llbuild.yaml"] swift build Compiling Swift Module 'KituraSys' (4 sources) <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: module 'Dispatch' requires feature 'blocks' <unknown>:0: error: could not build Objective-C module 'Dispatch' <unknown>:0: error: build had 1 command failures swift-build: error: exit(1): ["/root/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/root/Kitura/.build/debug/Kitura-Sys.o/llbuild.yaml"] make: [make] Error 1 (ignored) Makefile:21: recipe for target 'make' failed make -f Packages/Kitura-net*/Makefile make[1]: Entering directory '/root/Kitura' mkdir -p ./.build/debug clang -c -fPIC ./Packages/Kitura-CurlHelpers-0.2.0/CurlHelpers.c -o ./.build/debug/CurlHelpers.o ar rcs ./.build/debug/libcurlHelpers.a ./.build/debug/CurlHelpers.o clang -c -fPIC -I/usr/local/include ./Packages/Kitura-HttpParserHelper-0.2.0/utils.c -o ./.build/debug/httpParserHelper.o ar rcs ./.build/debug/libhttpParserHelper.a ./.build/debug/httpParserHelper.o swift build -Xcc -fblocks -Xlinker -L./.build/debug -Xlinker -ldispatch Compiling Swift Module 'LoggerAPI' (1 sources) /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:37:68: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public static func verbose(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:38:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__ ) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:38:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__ ) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:43:64: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func info(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:44:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:44:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:49:67: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func warning(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:50:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:50:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:55:65: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func error(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:56:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:56:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:61:65: warning: __FUNCTION__ is deprecated and will be removed in Swift 3, please use #function public class func debug(msg: String, functionName: String = __FUNCTION__, ^~~~~~~~~~~~ #function /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:62:24: warning: __LINE__ is deprecated and will be removed in Swift 3, please use #line lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #line /root/Kitura/Packages/LoggerAPI-0.2.0/Sources/LoggerAPI/Logger.swift:62:53: warning: __FILE__ is deprecated and will be removed in Swift 3, please use #file lineNum: Int = __LINE__, fileName: String = __FILE__) { ^~~~~~~~ #file Linking Library: .build/debug/LoggerAPI.a Compiling Swift Module 'KituraSys' (4 sources) /root/Kitura/Packages/Kitura-sys-0.2.0/Sources/KituraSys/Queue.swift:48:42: error: use of unresolved identifier 'get_dispatch_queue_concurrent' let concurrent: COpaquePointer = get_dispatch_queue_concurrent() ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <unknown>:0: error: build had 1 command failures swift-build: error: exit(1): ["/root/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/root/Kitura/.build/debug/Kitura-Sys.o/llbuild.yaml"] make[1]: *** [kitura] Error 1 Packages/Kitura-net-0.2.0/Makefile:44: recipe for target 'kitura' failed make[1]: Leaving directory '/root/Kitura' Makefile:21: recipe for target 'make' failed make: *** [make] Error 2 $
まとめ
IBMが作った!Bluemixで動く!というので話題になっていますが、シンプルなSwiftのAPサーバーと捉えると、Dockerとの相性は実はとてもいいんじゃないか?と思った次第です。
これから育っていくフレームワークだと思いますが、Swiftの先進的な言語設計が様々な環境で活用できるのであれば、広く受け入れられる仕組みになるかもしれないですね!