Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ruby/Rack application example with hot reload #3515

Merged
merged 5 commits into from
Jan 17, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions integration/examples/ruby/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Example: Ruby/Rack with hot-reload

Simple example based on Ruby/Rack application demonstrating the file synchronization mode.

#### Init

```bash
skaffold dev
```

#### Workflow

* Make some changes to `app.rb`:
* The file will be synchronized to the cluster
* Make some changes to `Gemfile`:
* The full build/push/deploy process will be triggered, fetching dependencies from `rubygems`


9 changes: 9 additions & 0 deletions integration/examples/ruby/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ruby:2.7

WORKDIR /app
ADD Gemfile* /app/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ADD Gemfile* ./

RUN bundle install

ADD . /app/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ADD . ./


CMD ["bundle","exec","puma"]
5 changes: 5 additions & 0 deletions integration/examples/ruby/backend/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'rack'
gem 'rack-unreloader' # for dynamic reloading
gem 'puma'
16 changes: 16 additions & 0 deletions integration/examples/ruby/backend/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GEM
remote: https://rubygems.org/
specs:
nio4r (2.5.2)
puma (4.3.1)
nio4r (~> 2.0)
rack (2.1.1)
rack-unreloader (1.7.0)

PLATFORMS
ruby

DEPENDENCIES
puma
rack
rack-unreloader
5 changes: 5 additions & 0 deletions integration/examples/ruby/backend/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class App
def self.call(env)
[ 200, {"Content-Type" => "text/html"}, ["Hello Skaffold!"]]
end
end
7 changes: 7 additions & 0 deletions integration/examples/ruby/backend/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require './app.rb'

require 'rack/unreloader'
Unreloader = Rack::Unreloader.new{App}

Unreloader.require './app.rb'
run Unreloader
33 changes: 33 additions & 0 deletions integration/examples/ruby/k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Service
metadata:
name: ruby
spec:
ports:
- port: 9292
targetPort: 9292
type: LoadBalancer
selector:
app: ruby
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ruby
spec:
selector:
matchLabels:
app: ruby
template:
metadata:
labels:
app: ruby
spec:
containers:
- name: ruby
image: ruby-example
ports:
- containerPort: 9292
env:
- name: RACK_ENV
value: "development"
11 changes: 11 additions & 0 deletions integration/examples/ruby/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: skaffold/v2alpha1
kind: Config
build:
artifacts:
- image: ruby-example
context: backend
sync:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried?

sync:
  infer:
  - *.rb

It would be nice to demonstrate inferred sync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I've changed to rack unreloader config and skaffold's option to infer. Works well

manual:
# Sync only app.rb file, being watch with rack-unreloader
- src: 'app.rb'
dest: .