-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of Ruby template ported to of-watchdog
Signed-off-by: Alex Ellis (VMware) <[email protected]>
- Loading branch information
0 parents
commit 4b2cf0e
Showing
7 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## ruby-http | ||
|
||
### Usage: | ||
|
||
``` | ||
faas template pull | ||
faas new --lang ruby-http homepage | ||
``` | ||
|
||
#### Example: | ||
|
||
Edit the `homepage/handler.rb` file to return some HTML: | ||
|
||
```ruby | ||
class Handler | ||
def run(body, headers) | ||
response_headers = {"content-type": "text/html"} | ||
body = "<html>Hello world from the Ruby template</html>" | ||
|
||
return body, response_headers | ||
end | ||
end | ||
``` | ||
|
||
Add a gem to the `homepage/Gemfile` if you need additional dependencies. | ||
|
||
Deploy: | ||
|
||
```sh | ||
faas-cli up -f homepage.yml | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM ruby:2.4-alpine3.6 | ||
|
||
ARG ADDITIONAL_PACKAGE | ||
|
||
# Alternatively use ADD https:// (which will not be cached by Docker builder) | ||
RUN apk --no-cache add curl ${ADDITIONAL_PACKAGE} \ | ||
&& echo "Pulling watchdog binary from Github." \ | ||
&& curl -sSL https://github.com/openfaas-incubator/of-watchdog/releases/download/0.4.0/of-watchdog > /usr/bin/fwatchdog \ | ||
&& chmod +x /usr/bin/fwatchdog \ | ||
&& apk del curl | ||
|
||
WORKDIR /home/app | ||
|
||
COPY Gemfile . | ||
COPY index.rb . | ||
COPY function function | ||
|
||
RUN bundle install \ | ||
&& mkdir -p /home/app/function | ||
|
||
WORKDIR /home/app/function | ||
|
||
RUN bundle install | ||
|
||
RUN addgroup -S app \ | ||
&& adduser app -S -G app | ||
|
||
RUN chown app:app -R /home/app | ||
|
||
USER app | ||
|
||
WORKDIR /home/app | ||
|
||
ENV fprocess="ruby index.rb" | ||
EXPOSE 8080 | ||
|
||
HEALTHCHECK --interval=2s CMD [ -e /tmp/.lock ] || exit 1 | ||
|
||
ENV upstream_url="http://127.0.0.1:5000" | ||
ENV mode="http" | ||
|
||
CMD ["fwatchdog"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem "sinatra" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source 'https://rubygems.org' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Handler | ||
def run(body, headers) | ||
response_headers = {"content-type": "text/plain"} | ||
body = "Hello world from the Ruby template" | ||
|
||
return body, response_headers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) Alex Ellis 2017. All rights reserved. | ||
# Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
require_relative 'function/handler' | ||
|
||
require 'sinatra' | ||
|
||
set :port, 5000 | ||
# set :bind, '0.0.0.0' | ||
|
||
handler = Handler.new | ||
|
||
get '/*' do | ||
res, res_headers = handler.run request.body, request.env | ||
|
||
headers = res_headers | ||
|
||
return res | ||
end | ||
|
||
post '/*' do | ||
res, res_headers = handler.run request.body, request.env | ||
headers = res_headers | ||
return res | ||
end | ||
|
||
put '/*' do | ||
res, res_headers = handler.run request.body, request.env | ||
headers = res_headers | ||
|
||
return res | ||
end | ||
|
||
delete '/*' do | ||
res, res_headers = handler.run request.body, request.env | ||
headers = res_headers | ||
|
||
return res | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: ruby | ||
fprocess: ruby index.rb | ||
build_options: | ||
- name: dev | ||
packages: | ||
- make | ||
- automake | ||
- gcc | ||
- g++ | ||
- subversion | ||
- python3-dev | ||
- musl-dev | ||
- libffi-dev | ||
- libssh | ||
- libssh-dev |