File tree Expand file tree Collapse file tree 7 files changed +142
-0
lines changed Expand file tree Collapse file tree 7 files changed +142
-0
lines changed Original file line number Diff line number Diff line change 1+ ## ruby-http
2+
3+ ### Usage:
4+
5+ ```
6+ faas template pull
7+ faas new --lang ruby-http homepage
8+ ```
9+
10+ #### Example:
11+
12+ Edit the ` homepage/handler.rb ` file to return some HTML:
13+
14+ ``` ruby
15+ class Handler
16+ def run (body , headers )
17+ response_headers = {" content-type" : " text/html" }
18+ body = " <html>Hello world from the Ruby template</html>"
19+
20+ return body, response_headers
21+ end
22+ end
23+ ```
24+
25+ Add a gem to the ` homepage/Gemfile ` if you need additional dependencies.
26+
27+ Deploy:
28+
29+ ``` sh
30+ faas-cli up -f homepage.yml
31+ ```
32+
Original file line number Diff line number Diff line change 1+ FROM ruby:2.4-alpine3.6
2+
3+ ARG ADDITIONAL_PACKAGE
4+
5+ # Alternatively use ADD https:// (which will not be cached by Docker builder)
6+ RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \
7+ && echo "Pulling watchdog binary from Github." \
8+ && curl -sSL https://github.com/openfaas-incubator/of-watchdog/releases/download/0.4.0/of-watchdog > /usr/bin/fwatchdog \
9+ && chmod +x /usr/bin/fwatchdog \
10+ && apk del curl
11+
12+ WORKDIR /home/app
13+
14+ COPY Gemfile .
15+ COPY index.rb .
16+ COPY function function
17+
18+ RUN bundle install \
19+ && mkdir -p /home/app/function
20+
21+ WORKDIR /home/app/function
22+
23+ RUN bundle install
24+
25+ RUN addgroup -S app \
26+ && adduser app -S -G app
27+
28+ RUN chown app:app -R /home/app
29+
30+ USER app
31+
32+ WORKDIR /home/app
33+
34+ ENV fprocess="ruby index.rb"
35+ EXPOSE 8080
36+
37+ HEALTHCHECK --interval=2s CMD [ -e /tmp/.lock ] || exit 1
38+
39+ ENV upstream_url="http://127.0.0.1:5000"
40+ ENV mode="http"
41+
42+ CMD ["fwatchdog" ]
Original file line number Diff line number Diff line change 1+ source 'https://rubygems.org'
2+
3+ gem "sinatra"
Original file line number Diff line number Diff line change 1+ source 'https://rubygems.org'
2+
Original file line number Diff line number Diff line change 1+ class Handler
2+ def run ( body , headers )
3+ response_headers = { "content-type" : "text/plain" }
4+ body = "Hello world from the Ruby template"
5+
6+ return body , response_headers
7+ end
8+ end
Original file line number Diff line number Diff line change 1+ # Copyright (c) Alex Ellis 2017. All rights reserved.
2+ # Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+ require_relative 'function/handler'
5+
6+ require 'sinatra'
7+
8+ set :port , 5000
9+ # set :bind, '0.0.0.0'
10+
11+ handler = Handler . new
12+
13+ get '/*' do
14+ res , res_headers = handler . run request . body , request . env
15+
16+ headers = res_headers
17+
18+ return res
19+ end
20+
21+ post '/*' do
22+ res , res_headers = handler . run request . body , request . env
23+ headers = res_headers
24+ return res
25+ end
26+
27+ put '/*' do
28+ res , res_headers = handler . run request . body , request . env
29+ headers = res_headers
30+
31+ return res
32+ end
33+
34+ delete '/*' do
35+ res , res_headers = handler . run request . body , request . env
36+ headers = res_headers
37+
38+ return res
39+ end
40+
Original file line number Diff line number Diff line change 1+ language : ruby
2+ fprocess : ruby index.rb
3+ build_options :
4+ - name : dev
5+ packages :
6+ - make
7+ - automake
8+ - gcc
9+ - g++
10+ - subversion
11+ - python3-dev
12+ - musl-dev
13+ - libffi-dev
14+ - libssh
15+ - libssh-dev
You can’t perform that action at this time.
0 commit comments