Coder Social home page Coder Social logo

rackup's Introduction

Paketo Buildpack for Rackup

gcr.io/paketo-buildpacks/rackup

The Rackup CNB sets the start command for a given rack-compliant ruby application.

Integration

This CNB writes a start command, so there's currently no scenario we can imagine that you would need to require it as dependency. If a user likes to include some other functionality, it can be done independent of the Rackup CNB without requiring a dependency of it.

To package this buildpack for consumption:

$ ./scripts/package.sh

This builds the buildpack's source using GOOS=linux by default. You can supply another value as the first argument to package.sh.

buildpack.yml Configurations

There are no extra configurations for this buildpack based on buildpack.yml.

Logging Configurations

To configure the level of log output from the buildpack itself, set the $BP_LOG_LEVEL environment variable at build time either directly (ex. pack build my-app --env BP_LOG_LEVEL=DEBUG) or through a project.toml file If no value is set, the default value of INFO will be used.

The options for this setting are:

  • INFO: (Default) log information about the progress of the build process
  • DEBUG: log debugging information about the progress of the build process
$BP_LOG_LEVEL="DEBUG"

rackup's People

Contributors

aramprice avatar arjun024 avatar dependabot[bot] avatar foresteckhardt avatar joshzarrabi avatar kvedurmu avatar paketo-bot avatar robdimsdale avatar ryanmoran avatar sophiewigmore avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rackup's Issues

Empty response from Sinatra app run with rackup when Gemfile.lock is not present

Using this example app, if the Gemfile.lock is removed and no specific version of the rack gem is added to the Gemfile, the following response is returned from the running application:

$ curl http://localhost:8080
curl: (52) Empty reply from server

We expect that either a Gemfile.lock or a simple gem 'rack' directive in the Gemfile would result in a working application. Instead, users would have to specify the rack gem with a specific version, as below, to obtain a working application image:

 source 'https://rubygems.org' 
                                                                                                                                              
 gem 'sinatra'
 gem 'rack', '~>1.5.1' 

RFC 0019: Allow RACK_ENV to be overridden at build time

Paketo RFC 0019 states that users should be able to override environment variables that the buildpacks set, if they're environment variables commonly used in the language ecosystem.

In this buildpack, the build process sets RACK_ENV in a way that ignores any user-provided value for the environment variable. This locks users into configuration that may not work for their app. For instance, to build https://github.com/pglombardo/PasswordPusher without an external DB, RACK_ENV must be set to private.

If it's possible for the buildpack to function while respecting that environment variable, it should do so.

Upgrade to buildpack API v0.5

The buildpack currently uses CNB Buildpacks API v0.2, while other buildpacks in the Ruby language family, such as the Bundle Install buildpack use v0.5. The CNB spec has evolved since then, and it would be nice to have all of the language family buildpacks up to date. To take advantage of more upstream features, the buildpack should be upgraded to API v0.5.

Check out the Buildpack API release notes for each version, and also the buildpacks.io API Migration guides for information on what has changed in each API version.

RACK_ENV is not properly passed in start command

When trying to push a Sinatra app that includes specific configurations associated with the Rack environment, we noticed that the Sinatra configuration was being ignored. We believe we've tracked it down to this line in the buildpack:

bundle exec rackup --env RACK_ENV=production -p ...

When we removed RACK_ENV= from the start command, the app was configured correctly with the production config:

bundle exec rackup --env production -p ...

We also got the app to configure correctly by changing the start command to use the RACK_ENV environment variable instead of the --env flag:

RACK_ENV=production bundle exec rackup -p ...

We also verified that, without any of the above changes, the RACK_ENV environment variable has the literal string value "RACK_ENV=production", with the RACK_ENV= prefix embedded in the value:

$ puts ENV['RACK_ENV']
RACK_ENV=production

Expected Behavior

RACK_ENV should be set to a valid value such as production

Current Behavior

RACK_ENV is currently being set incorrectly with a prefix of RACK_ENV=.

Possible Solution

The buildpack can be updated to use either the flag or the environment variable as described above.

Steps to Reproduce

  1. Build this app with the full Ruby CNB
  2. Run the app
  3. Curl <app-address>:<app-port>/v2/catalog
  4. Observe the app returning a 500 Internal Server Error

Upgrade to packit v2

Please upgrade to the latest packit v2 release to enable new features and extended support.

Start command port default overrides rackup config

I'm using a Rails app that uses rack with a Rack config file that sets the port to 3000.

Rackup file:

# This file is used by Rack-based servers to start the application.
#\ -o 0.0.0.0 -p 3000

require_relative 'config/environment'

run Rails.application

Example app - https://github.com/kvedurmu/paketo-samples/tree/master/ruby/rack/hello_rails

When I pack build my app and docker run it without passing in PORT as an environment variable, it looks like the start command that was defined in the build process overrides the port specified in my rackup config and still defaults to 9292.

Docker run output based off an app built using config above:

docker run -p 3000:3000 -it my-rack-app3
Parsing options from the first comment line is deprecated!
[2020-06-10 22:38:06] INFO  WEBrick 1.4.2
[2020-06-10 22:38:06] INFO  ruby 2.6.5 (2019-10-01) [x86_64-linux]
[2020-06-10 22:38:06] INFO  WEBrick::HTTPServer#start: pid=1 port=9292
^C[2020-06-10 22:38:55] INFO  going to shutdown ...
[2020-06-10 22:38:55] INFO  WEBrick::HTTPServer#start done.

Expected Behavior
The app should run on the port specified in my rackup config by default. The ordering that I'd expect here is:

  1. When the PORT environment variable is specified, run on that.
  2. When the rackup config sets a default port, run on that default when a PORT is not specified.
  3. (none of the above conditions met) - default to 9292

Unable to run Rails app using Rack without setting host config

I have a rails app that uses rack that I'm attempting to build using the rackup buildpack. I'm able to run it locally by running bundle exec rackup, but when I attempt to pack build and docker run it, I'm not able to access my app on localhost.

However, when I update my rackup config and add in #\ -o 0.0.0.0 at the top (deprecated) and then build my app, I'm able to run it.

Rails app I'm using - https://github.com/kvedurmu/paketo-samples/tree/master/ruby/rack/hello_rails

Successful build/run:

pack build my-rack-app --buildpack gcr.io/paketo-buildpacks/nodejs --buildpack gcr.io/paketo-community/ruby --builder gcr.io/paketo-buildpacks/builder:full-cf
........................................................
===> DETECTING
paketo-buildpacks/node-engine   0.0.210
paketo-buildpacks/yarn-install  0.1.49
paketo-community/mri            0.0.122
paketo-community/bundler        0.0.108
paketo-community/bundle-install 0.0.12
paketo-community/rackup         0.0.4
===> ANALYZING
Previous image with name "index.docker.io/library/my-rack-app:latest" not found
===> RESTORING
===> BUILDING
Node Engine Buildpack 0.0.210
  Resolving Node Engine version
    Candidate version sources (in priority order):
       -> "*"

    Selected Node Engine version (using ): 10.20.1

  Executing build process
    Installing Node Engine 10.20.1
      Completed in 2.766s

  Configuring environment
    NODE_ENV     -> "production"
    NODE_HOME    -> "/layers/paketo-buildpacks_node-engine/node"
    NODE_VERBOSE -> "false"

    Writing profile.d/0_memory_available.sh
      Calculates available memory based on container limits at launch time.
      Made available in the MEMORY_AVAILABLE environment variable.

Yarn Install Buildpack 0.1.49
  Executing build process
    Installing Yarn 1.22.4
      Completed in 398ms

  Resolving installation process
    Process inputs:
      yarn.lock -> Found

    Selected default build process: 'yarn install'

  Executing build process
    Running yarn install --ignore-engines --frozen-lockfile --modules-folder /layers/paketo-buildpacks_yarn-install/modules/node_modules
      Completed in 28.729s

  Configuring environment
PATH -> "$PATH:/layers/paketo-buildpacks_yarn-install/modules/node_modules/.bin"
MRI Buildpack 0.0.122
  Resolving MRI version
    Candidate version sources (in priority order):
      <unknown> -> "2.6.5"
      <unknown> -> "*"

    Selected MRI version (using <unknown>): 2.6.5

  Executing build process
    Installing MRI 2.6.5
      Completed in 2.641s

  Configuring environment
    GEM_PATH -> "/home/vcap/.gem/ruby/2.6.0:/layers/paketo-community_mri/mri/lib/ruby/gems/2.6.0"

Bundler Buildpack 0.0.108
  Resolving Bundler version
    Candidate version sources (in priority order):
      Gemfile.lock -> "2.1.4"
      <unknown>    -> "*"
      <unknown>    -> "*"

    Selected Bundler version (using Gemfile.lock): 2.1.4

  Executing build process
    Installing Bundler 2.1.4
      Completed in 1.891s

  Configuring environment
    GEM_PATH -> "$GEM_PATH:/layers/paketo-community_bundler/bundler"

Bundle Install Buildpack 0.0.12
  Executing build process
    Running 'bundle install'
      Completed in 3m20.684s

  Configuring environment
    BUNDLE_PATH -> "/layers/paketo-community_bundle-install/gems"

Rackup Buildpack 0.0.4
  Writing start command
    bundle exec rackup -p "${PORT:-9292}"
===> EXPORTING
Adding layer 'launcher'
Adding layer 'paketo-buildpacks/node-engine:node'
Adding layer 'paketo-buildpacks/yarn-install:modules'
Adding layer 'paketo-buildpacks/yarn-install:yarn'
Adding layer 'paketo-community/mri:mri'
Adding layer 'paketo-community/bundler:bundler'
Adding layer 'paketo-community/bundle-install:gems'
Adding 1/1 app layer(s)
Adding layer 'config'
*** Images (75360150e801):
      index.docker.io/library/my-rack-app:latest
Adding cache layer 'paketo-buildpacks/node-engine:node'
Adding cache layer 'paketo-buildpacks/yarn-install:modules'
Adding cache layer 'paketo-buildpacks/yarn-install:yarn'
Adding cache layer 'paketo-community/mri:mri'
Adding cache layer 'paketo-community/bundler:bundler'
Successfully built image my-rack-app

docker run -p 9292:9292 -it my-rack-app
Parsing options from the first comment line is deprecated!
[2020-06-10 21:56:03] INFO  WEBrick 1.4.2
[2020-06-10 21:56:03] INFO  ruby 2.6.5 (2019-10-01) [x86_64-linux]
[2020-06-10 21:56:03] INFO  WEBrick::HTTPServer#start: pid=1 port=9292
172.17.0.1 - - [10/Jun/2020:21:56:14 +0000] "GET / HTTP/1.1" 200 399722 0.3192
^C[2020-06-10 21:56:40] INFO  going to shutdown ...
[2020-06-10 21:56:41] INFO  WEBrick::HTTPServer#start done.

To reproduce the error:

  1. Remove the rackup host option here - https://github.com/kvedurmu/paketo-samples/blob/master/ruby/rack/hello_rails/config.ru#L2
  2. Pack build
  3. Docker run it. The app isn't accessible on localhost.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.