Skip to content

Commit

Permalink
Add Ruby/Rack application example with hot reload (#3515)
Browse files Browse the repository at this point in the history
* Add Ruby/Rack application example with hot reload

* Optimize docker build with dependencies caching

* Change sync option to infer

* Comment typo

* Copy ruby example to examples/ruby folder
  • Loading branch information
dsalahutdinov authored and dgageot committed Jan 17, 2020
1 parent db72c1f commit 448b193
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 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 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* ./
RUN bundle install

ADD . ./

CMD ["bundle","exec","puma"]
5 changes: 5 additions & 0 deletions 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 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 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 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 './*.rb'
run Unreloader
33 changes: 33 additions & 0 deletions 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 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:
# Sync app.rb file, being watch with rack-unreloader
# or add any other rb file to your application
infer:
- '*.rb'
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* ./
RUN bundle install

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 './*.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:
# Sync app.rb file, being watch with rack-unreloader
# or add any other rb file to your application
infer:
- '*.rb'

0 comments on commit 448b193

Please sign in to comment.