-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Changes from 2 commits
087468f
818e74b
71f9b1c
77d6bd1
92f37b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM ruby:2.7 | ||
|
||
WORKDIR /app | ||
ADD Gemfile* /app/ | ||
RUN bundle install | ||
|
||
ADD . /app/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
|
||
CMD ["bundle","exec","puma"] |
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' |
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 |
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 |
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 |
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" |
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tried?
It would be nice to demonstrate inferred sync There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
ADD Gemfile* ./