{"id":13513780,"url":"https://github.com/fly-apps/dockerfile-rails","last_synced_at":"2025-04-14T00:51:13.619Z","repository":{"id":65247326,"uuid":"588955450","full_name":"fly-apps/dockerfile-rails","owner":"fly-apps","description":"Provides a Rails generator to produce Dockerfiles and related files.","archived":false,"fork":false,"pushed_at":"2025-04-08T18:20:14.000Z","size":715,"stargazers_count":527,"open_issues_count":16,"forks_count":43,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-10T13:49:16.048Z","etag":null,"topics":["docker","dockerfile","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fly-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-14T15:45:47.000Z","updated_at":"2025-04-08T22:30:15.000Z","dependencies_parsed_at":"2024-05-12T00:31:56.858Z","dependency_job_id":null,"html_url":"https://github.com/fly-apps/dockerfile-rails","commit_stats":null,"previous_names":["fly-apps/dockerfile-rails","rubys/dockerfile-rails"],"tags_count":81,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fdockerfile-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fdockerfile-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fdockerfile-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fdockerfile-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fly-apps","download_url":"https://codeload.github.com/fly-apps/dockerfile-rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804773,"owners_count":21164131,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","dockerfile","rails","ruby"],"created_at":"2024-08-01T05:00:37.578Z","updated_at":"2025-04-14T00:51:13.590Z","avatar_url":"https://github.com/fly-apps.png","language":"Dockerfile","readme":"## Overview\n\nProvides a Rails generator to produce Dockerfiles and related files.  This is being proposed as the generator to be included in Rails 7.1, and a substantial number of pull requests along those lines have already been merged.  This repository contains fixes and features beyond those pull requests.  Highlights:\n\n  * Supports all [Rails supported releases](https://guides.rubyonrails.org/maintenance_policy.html), not just Rails 7.1, and likely works with a number of previous releases.\n  * Can be customized using flags on the `generate dockerfile` command, and rerun to produce a custom tailored dockerfile based on detecting the actual features used by your application.\n  * Will set `.node_version`, `packageManager` and install gems if needed to deploy your application.\n  * Can produce a `docker-compose.yml` file for locally testing your configuration before deploying.\n\nFor more background:\n\n* [Motivation](./MOTIVATION.md) - why this generator was created and what problems it is meant to solve\n* [Demos](./DEMO.md) - scripts to copy and paste into an empty directory to launch demo apps\n* [Test Results](./test/results) - expected outputs for each test\n\n## Usage\n\nInstall from the root of your Rails project by running the following.\n\n```\nbundle add dockerfile-rails --optimistic --group development\nbin/rails generate dockerfile\n```\n\nThe `--optimistic` flag will make sure you always get the latest `dockerfile-rails` gem when you run `bundle update \u0026\u0026 rails g dockerfile`.\n\n### General option:\n\n* `--force` - overwrite existing files\n* `--skip` - keep existing files\n\nIf neither are specified, you will be prompted if a file exists with\ndifferent contents.  If both are specified, `--force` takes precedence.\n\n### Runtime Optimizations:\n\n* `--alpine` - use [alpine](https://www.alpinelinux.org/) as base image (requires [Alpine \u003c= 3.18 OR Rails \u003e= 8.0](https://github.com/sparklemotion/sqlite3-ruby/issues/434))\n* `--fullstaq` - use [fullstaq](https://fullstaqruby.org/) [images](https://github.com/evilmartians/fullstaq-ruby-docker) on [quay.io](https://quay.io/repository/evl.ms/fullstaq-ruby?tab=tags\u0026tag=latest)\n* `--jemalloc` - use [jemalloc](https://jemalloc.net/) memory allocator\n* `--swap=n` - allocate swap space.  See [falloc options](https://man7.org/linux/man-pages/man1/fallocate.1.html#OPTIONS) for suffixes\n* `--yjit` - enable [YJIT](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md) optimizing compiler\n\n### Build optimizations:\n\n* `--cache` - use build caching to speed up builds\n* `--parallel` - use multi-stage builds to install gems and node modules in parallel\n\n### Add/remove a Feature:\n\n* `--ci` - include test gems in deployed image\n* `--compose` - generate a `docker-compose.yml` file\n* `--max-idle=n` - exit afer *n* seconds of inactivity.  Supports [iso 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) and [sleep](https://man7.org/linux/man-pages/man1/sleep.1.html#DESCRIPTION) syntaxes.  Uses passenger for now, awaiting [puma](https://github.com/puma/puma/issues/2580) support.\n* `--nginx` - serve static files via [nginx](https://www.nginx.com/).  May require `--root` on some targets to access `/dev/stdout`\n* `--thruster` - serve static files via [thruster](https://github.com/basecamp/thruster?tab=readme-ov-file#thruster).\n* `--link` - add [--link](https://docs.docker.com/engine/reference/builder/#copy---link) to COPY statements.  Some tools (like at the moment, [buildah](https://www.redhat.com/en/topics/containers/what-is-buildah)) don't yet support this feature.\n* `--no-lock` - don't add linux platforms, set `BUNDLE_DEPLOY`, or `--frozen-lockfile`.  May be needed at times to work around a [rubygems bug](https://github.com/rubygems/rubygems/issues/6082#issuecomment-1329756343).\n* `--sudo` - install and configure sudo to enable `sudo -iu rails` access to full environment\n\n#### Error Tracking \u0026 Alerting:\n* `--rollbar` - install gem and a default initializer for [Rollbar](https://rollbar.com/#)\n* `--sentry` - install gems and a default initializer for [Sentry](https://sentry.io/welcome/)\n\n### Add a Database:\n\nGenerally the dockerfile generator will be able to determine what dependencies you\nare actually using.  But should you be using DATABASE_URL, for example, at runtime\nadditional support may be needed:\n\n* `--litefs` - use [LiteFS](https://fly.io/docs/litefs/)\n* `--litestream` - use [Litestream](https://litestream.io/)\n* `--mysql` - add mysql libraries\n* `--postgresql` - add postgresql libraries\n* `--redis` - add redis libraries\n* `--sqlite3` - add sqlite3 libraries\n* `--sqlserver` - add SQL Server libraries\n\n### Add a package/environment variable/build argument:\n\nNot all of your needs can be determined by scanning your application.  For example, I like to add [vim](https://www.vim.org/) and [procps](https://packages.debian.org/bullseye/procps).\n\n * `--add package...` - add one or more debian packages\n * `--arg=name:value` - add a [build argument](https://docs.docker.com/engine/reference/builder/#arg)\n * `--env=name:value` - add an environment variable\n * `--remove package...` - remove package from \"to be added\" list\n\nArgs and environment variables can be tailored to a specific build phase by adding `-base`, `-build`, or `-deploy` after the flag name (e.g `--add-build freetds-dev --add-deploy freetds-bin`).  If no such suffix is found, the default for arg is `-base`, and the default for env is `-deploy`.  Removal of an arg or environment variable is done by leaving the value blank (e.g `--env-build=PORT:`).\n\n### Configuration:\n\n* `--bin-cd` - adjust binstubs to set current working directory\n[autocrlf](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf) enabled or may not be able to set bin stubs as executable.\n* `--label=name:value` - specify docker label.  Can be used multiple times.  See [LABEL](https://docs.docker.com/engine/reference/builder/#label) for detail\n* `--no-prepare` - omit `db:prepare`.  Useful for cloud platforms with [release](https://devcenter.heroku.com/articles/release-phase) phases\n* `--passenger` - use [Phusion Passenger](https://www.phusionpassenger.com/) under [nginx](https://www.nginx.com/)\n* `--platform=s` - specify target platform.  See [FROM](https://docs.docker.com/engine/reference/builder/#from) for details\n* `--variant=s` - dockerhub ruby variant, defaults to `slim`.  See [docker official images](https://hub.docker.com/_/ruby) for list.\n* `--precompile=defer` - may be needed when your configuration requires access to secrets that are not available at build time.  Results in larger images and slower deployments.\n* `--root` - run application as root\n* `--windows` - make Dockerfile work for Windows users that may have set `git config --global core.autocrlf true`\n* `--private-gemserver-domain=gems.example.com` - set the domain name of your private gemserver.  This is used to tell bundler for what domain to use the credentials of a private gemserver provided via a docker secret\n* `--no-precompiled-gems` - compile all gems instead of using precompiled versions\n\n### Advanced Customization:\n\nThere may be times where feature detection plus flags just aren't enough.  As an example, you may wish to configure and run multiple processes.\n\n* `--instructions=path` - a dockerfile fragment to be inserted into the final document.\n* `--migrate=cmd` - a replacement (generally a script) for `db:prepare`/`db:migrate`.\n* `--no-gemfile-updates` - do not modify my gemfile.\n* `--procfile=path` - a [Procfile](https://github.com/ddollar/foreman#foreman) to use in place of launching Rails directly.\n* `--registry=another.docker.registry.com` - use a different registry for sourcing Docker images (e.g. public.ecr.aws).\n\nLike with environment variables, packages, and build args, `--instructions` can be tailored to a specific build phase by adding `-base`, `-build`, or `-deploy` after the flag name, with the default being `-deploy`.\n\nAdditionally, if the instructions start with a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) instead the file being treated as a Dockerfile fragment, the file is treated as a script and a `RUN` statement is added to your Dockerfile instead.\n\n---\n\nOptions are saved between runs into `config/dockerfile.yml`.  To invert a boolean options, add or remove a `no-` prefix from the option name.\n\n## Testing\n\nRun:\n\nInstallation:\n\n```\nbrew install postgresql mysql zstd\nbundle config --local build.mysql2 \"--with-opt-dir=\"$(brew --prefix zstd)\"\"\nbundle install\n```\n\nA single invocation of `rake test:all` will run all of the tests defined.  dockerfile-rails has are three types of tests:\n\n  * `rake test:rubocop` runs [rubocop](https://github.com/rubocop/rubocop) using the same options as the Rails codebase.\n  * `rake test:system` creates a new esbuild application, generates a dockerfile, builds and runs it.  As this is time consuming, only one application is tested this way at this time, and a `--javascript` example was selected as it exercises a large portion of the features.\n  * `rake test` runs integration tests, as described below\n\nThe current integration testing strategy is to run `rails new` and `generate dockerfile` with various configurations and compare the generated artifacts with expected results.  `ARG` values in `Dockerfiles` are masked before comparison.\n\nRunning all integration tests, or even a single individual test can be done as follows:\n\n```\nrake test\n\nbundle exec rake test TEST=test/test_minimal.rb\nbundle exec ruby test/test_minimal.rb\n```\n\nTo assist with this process, outputs of tests can be captured automatically.  This is useful when adding new tests and when making a change that affects many tests.  Be sure to inspect the output (e.g., by using `git diff`) before committing.\n\n```\nrake test:capture\n```\n\nIf you are running a single test, the following environment variables settings may be helpful:\n\n * `RAILS_ENV=TEST` will match the environment used to produce the captured outputs.\n * `TEST_CAPTURE=1` will capture test results.\n * `TEST_KEEP=1` will leave the test app behind for inspection after the test completes.\n\n## Historical Links\n\nThe following links relate to the coordination between this package and Rails 7.1.\n\n* [Preparations for Rails 7.1](https://community.fly.io/t/preparations-for-rails-7-1/9512) - [Fly.io](https://fly.io/)'s plans and initial discussions with DHH\n* [Rails Dockerfile futures](https://discuss.rubyonrails.org/t/rails-dockerfile-futures/82091/1) - rationale for a generator\n* [Fly Cookbooks](https://fly.io/docs/rails/cookbooks/) - deeper dive into Dockerfile design choices\n* [app/templates/Dockerfile.tt](https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt) - current Rails 7.1 template\n* Fly.io [Cut over to Rails Dockerfile Generator on Sunday 29 Jan 2023](https://community.fly.io/t/cut-over-to-rails-dockerfile-generator-on-sunday-29-jan-2023/10350)\n* Fly.io [FAQ](https://fly.io/docs/rails/getting-started/dockerfiles/)\n* DDH's [target](https://github.com/rails/rails/pull/47372#issuecomment-1438971730)\n\nParallel efforts for Hanami:\n\n* [Proposal](https://discourse.hanamirb.org/t/dockerfile-hanami/816)\n","funding_links":[],"categories":["Dockerfile"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fdockerfile-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffly-apps%2Fdockerfile-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fdockerfile-rails/lists"}