Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Swift で開発した Web アプリケーションを Amazon EC2 Containe...
Search
ngs
March 07, 2016
Technology
4.5k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swift で開発した Web アプリケーションを Amazon EC2 Container Services で運用する
http://ja.ngs.io/2016/03/04/swift-webapp-on-ecs/
http://connpass.com/event/27667/
ngs
March 07, 2016
More Decks by ngs
See All by ngs
Mindstorms NXT Playground Book for iPad
ngs
0
1.9k
Hubot を使って日々のルーチンワークをゼロにする
ngs
3
1.6k
IBM Cloud Tools for Swift
ngs
0
540
WWDC 2016
ngs
2
1.5k
CI2Go
ngs
0
970
Oneteam の開発チームが行っている協同のための工夫 v2016-04-13
ngs
0
3k
Oneteam の 少人数で複数プロダクトを 開発する技術的な試行錯誤 #eventdots
ngs
2
3.4k
Electron アプリのビルド + 配信自動化
ngs
0
3.1k
Kaizen Platform での Hubot 活用事例
ngs
7
5.5k
Other Decks in Technology
See All in Technology
負債のメタファと2026年 / Debt Metaphor in Agentic Engineering Age 202609 Edition
twada
PRO
8
3.4k
アプリログインとWeb認証基盤をつなぐ ASWebAuthenticationSession 作法
shimastripe
1
330
ADKで始める業務改善 - AIエージェント開発時の考えと設計
harappa80
2
150
「守り」で活用するオンデバイスLLM 〜写ってはいけないを総力戦で防ぐ〜 / iOSDC Japan 2026
nakamuuu
0
160
AIを活用するために決めた "やらないこと" - 価値に注目する / Not betting on AI
soudai
PRO
2
540
品質と信頼性を地続きにする
grimoh
0
460
俺の仕事は AIに奪われないし、たぶんその BIも要らない
hikaruri
0
490
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
9
960
Claude Codeを「使うほど育つ」AI秘書にするノウハウ
minorun365
PRO
30
26k
LLMに渡さなかった仕事
nanaism
0
270
Spring BootからQuarkusへの移行
tatsuya1bm
2
120
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
1.6k
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Marketing to machines
jonoalderson
1
5.8k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
300
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
Claude Code のすすめ
schroneko
67
230k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
280
Transcript
Swift Ͱ։ൃͨ͠ Web ΞϓϦέʔγϣϯΛ Amazon EC2 Container Services Ͱӡ༻͢Δ Atsushi
Nagase @ngs / http://ja.ngs.io/ https://one-team.com/products/
None
None
@ngs
None
None
BUILD • sbt assembly • docker build TEST • sbt
test:test • cd serverspec && rspec DEPLOY • docker push • aws ecs register-task-definition • aws ecs update-service
None
Kitsura https://developer.ibm.com/swift/products/kitura/ Nest https://github.com/nestproject/Nest Perfect http://perfect.org/ Slimane https://github.com/noppoMan/Slimane Swifton https://github.com/necolt/Swifton
$ sbt assembly $ java -jar myapp.jar $ curl http://0.0.0.0:8080
HTTP/1.1 200 OK
$ swift build $ .build/release/MyApp $ curl http://0.0.0.0:8000 HTTP/1.1 200
OK
None
None
swift build .build/debug/Swifton-TodoApp open http://0.0.0.0:8000/todos
$ cat Procfile web: Swifton-TodoApp --workers 3 --bind 0.0.0.0:$PORT $
cat app.json { "name": "Swifton TodoApp Example", "description": "An example TodoApp using Swifton web framework on Heroku.", "repository": "https://github.com/necolt/Swifton-TodoApp", "website": "https://github.com/necolt/Swifton-TodoApp", "keywords": [“swifton", "curassow"], "buildpacks": [{ "url": “https://github.com/kylef/heroku-buildpack-swift" }] }
FROM ubuntu:14.04 MAINTAINER
[email protected]
ENV SWIFT_BRANCH development ENV SWIFT_VERSION DEVELOPMENT-SNAPSHOT-2016-02-08-a
ENV SWIFT_PLATFORM ubuntu14.04 RUN apt-get update && \ apt-get install -y build-essential wget clang libedit-dev python2.7 python2.7-dev libicu52 rsync libxml2 git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - && \ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift RUN SWIFT_ARCHIVE_NAME=swift-$SWIFT_VERSION-$SWIFT_PLATFORM && \ SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/swift-$SWIFT_VERSION/ $SWIFT_ARCHIVE_NAME.tar.gz && \ wget $SWIFT_URL && \ wget $SWIFT_URL.sig && \ gpg --verify $SWIFT_ARCHIVE_NAME.tar.gz.sig && \ tar -xvzf $SWIFT_ARCHIVE_NAME.tar.gz --directory / --strip-components=1 && \ rm -rf $SWIFT_ARCHIVE_NAME* /tmp/* /var/tmp/* ENV PATH /usr/bin:$PATH RUN mkdir -p /swifton WORKDIR /swifton ADD . /swifton RUN swift build --configuration release EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
ENV SWIFT_BRANCH development ENV SWIFT_VERSION DEVELOPMENT-SNAPSHOT-2016-02-08-a
ENV SWIFT_PLATFORM ubuntu14.04 RUN apt-get update && \ apt-get install -y build-essential wget clang libedit-dev python2.7 python2.7-dev libicu52 rsync libxml2 git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - && \ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift RUN SWIFT_ARCHIVE_NAME=swift-$SWIFT_VERSION-$SWIFT_PLATFORM && \ SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/swift-$SWIFT_VERSION/ $SWIFT_ARCHIVE_NAME.tar.gz && \ wget $SWIFT_URL && \ wget $SWIFT_URL.sig && \ gpg --verify $SWIFT_ARCHIVE_NAME.tar.gz.sig && \ tar -xvzf $SWIFT_ARCHIVE_NAME.tar.gz --directory / --strip-components=1 && \ rm -rf $SWIFT_ARCHIVE_NAME* /tmp/* /var/tmp/* ENV PATH /usr/bin:$PATH RUN mkdir -p /swifton WORKDIR /swifton ADD . /swifton RUN swift build --configuration release EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
ENV SWIFT_BRANCH development ENV SWIFT_VERSION DEVELOPMENT-SNAPSHOT-2016-02-08-a
ENV SWIFT_PLATFORM ubuntu14.04 RUN apt-get update && \ apt-get install -y build-essential wget clang libedit-dev python2.7 python2.7-dev libicu52 rsync libxml2 git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - && \ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift RUN SWIFT_ARCHIVE_NAME=swift-$SWIFT_VERSION-$SWIFT_PLATFORM && \ SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/swift-$SWIFT_VERSION/ $SWIFT_ARCHIVE_NAME.tar.gz && \ wget $SWIFT_URL && \ wget $SWIFT_URL.sig && \ gpg --verify $SWIFT_ARCHIVE_NAME.tar.gz.sig && \ tar -xvzf $SWIFT_ARCHIVE_NAME.tar.gz --directory / --strip-components=1 && \ rm -rf $SWIFT_ARCHIVE_NAME* /tmp/* /var/tmp/* ENV PATH /usr/bin:$PATH RUN mkdir -p /swifton WORKDIR /swifton ADD . /swifton RUN swift build --configuration release EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
ENV SWIFT_BRANCH development ENV SWIFT_VERSION DEVELOPMENT-SNAPSHOT-2016-02-08-a
ENV SWIFT_PLATFORM ubuntu14.04 RUN apt-get update && \ apt-get install -y build-essential wget clang libedit-dev python2.7 python2.7-dev libicu52 rsync libxml2 git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - && \ gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift RUN SWIFT_ARCHIVE_NAME=swift-$SWIFT_VERSION-$SWIFT_PLATFORM && \ SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/swift-$SWIFT_VERSION/ $SWIFT_ARCHIVE_NAME.tar.gz && \ wget $SWIFT_URL && \ wget $SWIFT_URL.sig && \ gpg --verify $SWIFT_ARCHIVE_NAME.tar.gz.sig && \ tar -xvzf $SWIFT_ARCHIVE_NAME.tar.gz --directory / --strip-components=1 && \ rm -rf $SWIFT_ARCHIVE_NAME* /tmp/* /var/tmp/* ENV PATH /usr/bin:$PATH RUN mkdir -p /swifton WORKDIR /swifton ADD . /swifton RUN swift build --configuration release EXPOSE 8000 CMD .build/release/Swifton-TodoApp
None
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> sha256:c35f9 30 seconds ago 893.2 MB
$ swift build --configuration release $ docker build -t $DOCKER_REPO
.
https://swift.org/download/#latest-development-snapshots
http://blog.circleci.com/trusty-image-public-beta/
$ sudo apt-get install libicu-dev clang-3.6 jq $ sudo update-alternatives
--install \ /usr/bin/clang clang /usr/bin/clang-3.6 100 $ sudo update-alternatives --install \ /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
$ swift build --configuration release
. |-- .build | `-- release | `-- Swifton-TodoApp |--
Views | `-- Todos | |-- Edit.html.stencil | |-- Index.html.stencil | |-- New.html.stencil | `-- Show.html.stencil `-- swift `-- usr `-- lib `-- swift `-- linux |-- libFoundation.so |-- libXCTest.so |-- libswiftCore.so |-- libswiftGlibc.so `-- libswiftSwiftOnoneSupport.so
. |-- .build | `-- release | `-- Swifton-TodoApp |--
Views | `-- Todos | |-- Edit.html.stencil | |-- Index.html.stencil | |-- New.html.stencil | `-- Show.html.stencil `-- swift `-- usr `-- lib `-- swift `-- linux |-- libFoundation.so |-- libXCTest.so |-- libswiftCore.so |-- libswiftGlibc.so `-- libswiftSwiftOnoneSupport.so
. |-- .build | `-- release | `-- Swifton-TodoApp |--
Views | `-- Todos | |-- Edit.html.stencil | |-- Index.html.stencil | |-- New.html.stencil | `-- Show.html.stencil `-- swift `-- usr `-- lib `-- swift `-- linux |-- libFoundation.so |-- libXCTest.so |-- libswiftCore.so |-- libswiftGlibc.so `-- libswiftSwiftOnoneSupport.so
. |-- .build | `-- release | `-- Swifton-TodoApp |--
Views | `-- Todos | |-- Edit.html.stencil | |-- Index.html.stencil | |-- New.html.stencil | `-- Show.html.stencil `-- swift `-- usr `-- lib `-- swift `-- linux |-- libFoundation.so |-- libXCTest.so |-- libswiftCore.so |-- libswiftGlibc.so `-- libswiftSwiftOnoneSupport.so
$ cat .dockerignore * !Views !swift/usr/lib/swift/linux/*.so !.build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
RUN apt-get update && apt-get install
-y libicu52 libxml2 curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ENV APP_DIR /var/www/app RUN mkdir -p ${APP_DIR} WORKDIR ${APP_DIR} ADD . ${APP_DIR} RUN ln -s ${APP_DIR}/swift/usr/lib/swift/linux/*.so /usr/lib EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
RUN apt-get update && apt-get install
-y libicu52 libxml2 curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ENV APP_DIR /var/www/app RUN mkdir -p ${APP_DIR} WORKDIR ${APP_DIR} ADD . ${APP_DIR} RUN ln -s ${APP_DIR}/swift/usr/lib/swift/linux/*.so /usr/lib EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
RUN apt-get update && apt-get install
-y libicu52 libxml2 curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ENV APP_DIR /var/www/app RUN mkdir -p ${APP_DIR} WORKDIR ${APP_DIR} ADD . ${APP_DIR} RUN ln -s ${APP_DIR}/swift/usr/lib/swift/linux/*.so /usr/lib EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
RUN apt-get update && apt-get install
-y libicu52 libxml2 curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ENV APP_DIR /var/www/app RUN mkdir -p ${APP_DIR} WORKDIR ${APP_DIR} ADD . ${APP_DIR} RUN ln -s ${APP_DIR}/swift/usr/lib/swift/linux/*.so /usr/lib EXPOSE 8000 CMD .build/release/Swifton-TodoApp
FROM ubuntu:14.04 MAINTAINER
[email protected]
RUN apt-get update && apt-get install
-y libicu52 libxml2 curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ENV APP_DIR /var/www/app RUN mkdir -p ${APP_DIR} WORKDIR ${APP_DIR} ADD . ${APP_DIR} RUN ln -s ${APP_DIR}/swift/usr/lib/swift/linux/*.so /usr/lib EXPOSE 8000 CMD .build/release/Swifton-TodoApp
None
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> sha256:c35f9 2 minutes ago 893.2 MB <none> <none> sha256:0d31d 30 seconds ago 245.8 MB
None
require 'spec_helper' describe port(8000) do it { should be_listening }
end describe command('curl -i -s -H \'Accept: text/html\' http://0.0.0.0:8000/') do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to contain 'HTTP/1.1 200 OK' } its(:stdout) { is_expected.to contain '<h1>Listing Todos</h1>' } end 1.upto(2) do|n| describe command("curl -i -s -H \'Accept: text/html\' http://0.0.0.0:8000/todos -d \'title=Test#{n}\'") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to contain 'HTTP/1.1 302 FOUND' } its(:stdout) { is_expected.to contain 'Location: /todos' } end end describe command('curl -i -s -H \'Accept: text/html\' http://0.0.0.0:8000/todos') do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to contain 'HTTP/1.1 200 OK' } its(:stdout) { is_expected.to contain '<h1>Listing Todos</h1>' } its(:stdout) { is_expected.to contain '<td>Test1</td>' } its(:stdout) { is_expected.to contain '<td>Test2</td>' } its(:stdout) { is_expected.to contain '<td><a href="/todos/0">Show</a></td>' } its(:stdout) { is_expected.to contain '<td><a href="/todos/1">Show</a></td>' } end
$ cd serverspec && export DOCKER_CONTAINER=serverspec && bundle exec rspec
Port "8000" should be listening Command "curl -i -s -H 'Accept: text/html' http://0.0.0.0:8000/" exit_status should eq 0 stdout should contain "HTTP/1.1 200 OK" stdout should contain "<h1>Listing Todos</h1>" Command "curl -i -s -H 'Accept: text/html' http://0.0.0.0:8000/todos -d 'title=Test1'" exit_status should eq 0 stdout should contain "HTTP/1.1 302 FOUND" stdout should contain "Location: /todos" Command "curl -i -s -H 'Accept: text/html' http://0.0.0.0:8000/todos -d 'title=Test2'" exit_status should eq 0 stdout should contain "HTTP/1.1 302 FOUND" stdout should contain "Location: /todos" Command "curl -i -s -H 'Accept: text/html' http://0.0.0.0:8000/todos" exit_status should eq 0 stdout should contain "HTTP/1.1 200 OK" stdout should contain "<h1>Listing Todos</h1>" stdout should contain "<td>Test1</td>" stdout should contain "<td>Test2</td>"
$ docker tag $DOCKER_REPO "${DOCKER_REPO}:b${CIRCLE_BUILD_NUM}" $ docker push "${DOCKER_REPO}:b${CIRCLE_BUILD_NUM}"
#!/bin/sh set -eu APP_NAME=swifton-example- UPPER_ENV_NAME=$(echo $ENV_NAME | awk '{print toupper($0)}')
CLUSTER="${APP_NAME}${ENV_NAME}" TASK_FAMILY="${APP_NAME}${ENV_NAME}" SERVICE_NAME="${APP_NAME}service-${ENV_NAME}" LOADBALANCER_NAME="${APP_NAME}${ENV_NAME}" CONTAINER_PORT=8000 CONTAINER_NAME=$CONTAINER_NAME CONTAINER_PORT=$CONTAINER_PORT APP_NAME=$APP_NAME \ erb ecs-task-definitions/service.json.erb > .ecs-task-definition.json TASK_DEFINITION_JSON=$(aws ecs register-task-definition --family $TASK_FAMILY \ --cli-input-json "file://$(pwd)/.ecs-task-definition.json") TASK_REVISION=$(echo $TASK_DEFINITION_JSON | jq .taskDefinition.revision) SERVICE_JSON=$(aws ecs describe-services --services $SERVICE_NAME --cluster $CLUSTER) if [ $(echo $SERVICE_JSON | jq '.services | length') = "0" ]; then SERVICE_JSON=$(aws ecs create-service --cluster ${CLUSTER} --service ${SERVICE_NAME} \ --task-definition ${TASK_FAMILY}:${TASK_REVISION} --desired-count 1 \ --load-balancers loadBalancerName=${LOADBALANCER_NAME},containerName=${CONTAINER_NAME},containerPort=$ {CONTAINER_PORT} --role ecs-operation) else DESIRED_COUNT=$(echo $SERVICE_JSON | jq '.services[0].desiredCount') if [ ${DESIRED_COUNT} = "0" ]; then DESIRED_COUNT="1" fi SERVICE_JSON=$(aws ecs update-service --cluster ${CLUSTER} --service ${SERVICE_NAME} --task-definition $ {TASK_FAMILY}:${TASK_REVISION} --desired-count ${DESIRED_COUNT}) fi echo $SERVICE_JSON | jq .
ଟँ