-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ruby/Rack application example with hot reload (#3515)
* 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
1 parent
db72c1f
commit 448b193
Showing
16 changed files
with
208 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,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` | ||
|
||
|
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,9 @@ | ||
FROM ruby:2.7 | ||
|
||
WORKDIR /app | ||
ADD Gemfile* ./ | ||
RUN bundle install | ||
|
||
ADD . ./ | ||
|
||
CMD ["bundle","exec","puma"] |
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,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rack' | ||
gem 'rack-unreloader' # for dynamic reloading | ||
gem 'puma' |
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,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 |
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,5 @@ | ||
class App | ||
def self.call(env) | ||
[ 200, {"Content-Type" => "text/html"}, ["Hello Skaffold!"]] | ||
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,7 @@ | ||
require './app.rb' | ||
|
||
require 'rack/unreloader' | ||
Unreloader = Rack::Unreloader.new{App} | ||
|
||
Unreloader.require './*.rb' | ||
run Unreloader |
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,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" |
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,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' |
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,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` | ||
|
||
|
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,9 @@ | ||
FROM ruby:2.7 | ||
|
||
WORKDIR /app | ||
ADD Gemfile* ./ | ||
RUN bundle install | ||
|
||
ADD . ./ | ||
|
||
CMD ["bundle","exec","puma"] |
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,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rack' | ||
gem 'rack-unreloader' # for dynamic reloading | ||
gem 'puma' |
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,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 |
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,5 @@ | ||
class App | ||
def self.call(env) | ||
[ 200, {"Content-Type" => "text/html"}, ["Hello Skaffold!"]] | ||
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,7 @@ | ||
require './app.rb' | ||
|
||
require 'rack/unreloader' | ||
Unreloader = Rack::Unreloader.new{App} | ||
|
||
Unreloader.require './*.rb' | ||
run Unreloader |
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,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" |
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,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' |