# Dockerfile-hanami?

**URL:** <https://discourse.hanakai.org/t/dockerfile-hanami/816>\
**Category:** proposals\
**Created:** [March 29, 2023, 10:46pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816 "2023-03-29T22:46:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubys](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/rubys/32/630_2.png) [@rubys](https://discourse.hanakai.org/u/rubys)\
**Post date:** [March 29, 2023, 10:46pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/1 "2023-03-29T22:46:03Z")

</div>

My name is Sam Ruby. I work for [fly.io](https://fly.io/) and maintain a gem named [dockerfile-rails](https://github.com/rubys/dockerfile-rails).

I’d like to explore if there would be any interest in a dockerfile-hanami gem built on the same codebase. The basic idea would be to have a single command that can be run to build a Dockerfile and optionally a docker-compose.yml file. This gem would have no dependencies on Rails, but likely on things like Thor to parse command line arguments and to process templates. My current codebase may have incidental dependencies on active\_support, and when we get there we can jointly decide if that’s OK or if that should be worked around.

The Dockerfiles produced would enable the application to be deployed pretty much anywhere, or even run on your own machine.

From a purely packaging point of view, all Rack/Postgres/Redis applications are essentially the same, the key difference being in the spelling of the command to launch the server, and how things like migrations are handled.

What I’m looking for is people with experience in the Hanami ecosystem to know what gems are common and what special configurations are worth looking for.

I’m open to whatever mode of cooperation works best - gathering requirements here, merging in pull requests, or even adding collaborators who are interested in helping maintaining this.

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/solnic/32/757_2.png) [@solnic](https://discourse.hanakai.org/u/solnic)\
**Post date:** [March 30, 2023, 5:55am UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/2 "2023-03-30T05:55:35Z")

</div>

Hey Sam, this sounds great! I’m happy to help you with this 🙂

---

<div class="post-metadata">

**Author:** ![rubys](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/rubys/32/630_2.png) [@rubys](https://discourse.hanakai.org/u/rubys)\
**Post date:** [March 30, 2023, 7:02am UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/3 "2023-03-30T07:02:27Z")

</div>

Sweet!

The thing that I would find most helpful is if somebody familiar with the hanami ecosystem could define a few concrete scenarios. If you look at [dockerfile-rails/DEMO.md at main · rubys/dockerfile-rails · GitHub](https://github.com/rubys/dockerfile-rails/blob/main/DEMO.md) you will find a number of scripts that you can copy/paste to your OSX/Linux/WSL2 terminal to launch a demo. The equivalent to the first demo is fairly obvious. Perhaps the next one to focus on would be the third. Feel free to replace ActionCable with AnyCable. ActiveRecord with rom-rb. It looks like a SVG can be found here: [Hanami Vector SVG Icon - SVG Repo](https://www.svgrepo.com/svg/353858/hanami). Writing down an equivalent scenario that I can run on my machine (ignoring the last few lines that set up and run the Dockerfile) would give me something to go on.

Then go from there to define other scenarios that are representative of hanami usage. Don’t worry about matching other scenarios on that page unless there is some significant difference as you will get the remaining scenarios for free (and conversely, Rails will get AnyCable and rom-rb for free - isn’t synergy wonderful?)

Once such scenario(s) is/are ready, the rest should fall in place quickly.

---

<div class="post-metadata">

**Author:** ![jodosha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/jodosha/32/710_2.png) [@jodosha](https://discourse.hanakai.org/u/jodosha)\
**Post date:** [March 30, 2023, 11:55am UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/4 "2023-03-30T11:55:54Z")

</div>

@rubys Thanks for getting in touch. We want this to happen!

@solnic Here are some inputs for you:

- A minimal Hanami app: [web-frameworks/ruby/hanami at master · the-benchmarker/web-frameworks · GitHub](https://github.com/the-benchmarker/web-frameworks/tree/master/ruby/hanami)
- [Getting Started with Hanami and Docker Compose · Luca Guidi](https://lucaguidi.com/2023/02/13/getting-started-with-hanami-and-docker-compose/)
- [Setup Hanami with Sidekiq · Luca Guidi](https://lucaguidi.com/2023/02/20/setup-hanami-with-sidekiq/)

* * *

Folks, please let me know if you’ll need my input. Cheers!

---

<div class="post-metadata">

**Author:** ![rubys](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/rubys/32/630_2.png) [@rubys](https://discourse.hanakai.org/u/rubys)\
**Post date:** [March 30, 2023, 2:12pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/5 "2023-03-30T14:12:34Z")

</div>

I’m going to start in parallel on a minimal hanami application. My first question: with Rails it is possible to add a generator simply by subclassing:

```auto
class DockerfileGenerator < Rails::Generators::Base

```

Is something like this possible with Hanami?

Edit: unless I hear otherwise, I’m going to see if I can use this as an example: [GitHub - davydovanton/hanami-operation-generator: Simple library for generating operations for hanami-dry-system project](https://github.com/davydovanton/hanami-operation-generator)

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/bkuhlmann/32/475_2.png) [@bkuhlmann](https://discourse.hanakai.org/u/bkuhlmann)\
**Post date:** [March 30, 2023, 7:01pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/6 "2023-03-30T19:01:33Z")

</div>

Yeah, the equivalent in Hanami is to subclass `App::Command`. Example:

```ruby
module Docker
  class Demo < App::Command
    desc "A demonstration command"

    def call(**)
      # Implementation details go here.
    end
  end
end

```

Here are a few additional references to get you bootstrapped:

- [Dry CLI](https://dry-rb.org/gems/dry-cli): This is where you can read up on how all of this works.
- [Hanami CLI](https://github.com/hanami/cli): Sits atop Dry CLI. Within this repository, you might want to check out the [commands](https://github.com/hanami/cli/tree/main/lib/hanami/cli/commands) and [generators](https://github.com/hanami/cli/tree/main/lib/hanami/cli/generators) for further examples.
- [Hemo](https://github.com/bkuhlmann/hemo): This is my Hanami demonstration project built with HTMX so you can use this as a source as well. This [extension](https://github.com/bkuhlmann/hemo/blob/main/bin/hanami#L8-L17) of the Hanami CLI might be of interest as well.

---

<div class="post-metadata">

**Author:** ![rubys](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/rubys/32/630_2.png) [@rubys](https://discourse.hanakai.org/u/rubys)\
**Post date:** [March 31, 2023, 5:12pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/7 "2023-03-31T17:12:01Z")

</div>

Possibly dumb question, does hanami load plugins anymore?

I found this code commit 625a709746122b5549255abd2cd3aef14133608d but that executable has moved to cli and no longer appears to load plugins.

In any case, I have the following in my Gemfile and my plugin is not being loaded when I run 'bundle exec hanami generate`:

```auto
group :plugins do
  gem 'dockerfile-hanami', path: '/Users/rubys/git/dockerfile-hanami'
end

```

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/bkuhlmann/32/475_2.png) [@bkuhlmann](https://discourse.hanakai.org/u/bkuhlmann)\
**Post date:** [March 31, 2023, 6:46pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/8 "2023-03-31T18:46:47Z")

</div>

No question is ever a dumb question. 😉

I don’t know the direct answer to this but, in searching through both the CLI and Hanami core projects, I couldn’t find any reference to `bundler_groups` which is the method that defines `[:plugins]`. Someone in the community with more knowledge might need to chime in.

This may or may not help, but here’s how I use a special `tools` group through my [Hemo](https://github.com/bkuhlmann/hemo) application:

- [Spec Helper](https://github.com/bkuhlmann/hemo/blob/main/spec/spec_helper.rb#L4)
- [Puma](https://github.com/bkuhlmann/hemo/blob/main/config/puma.rb#L7)
- [Console](https://github.com/bkuhlmann/hemo/blob/main/bin/console#L5)
- [Rack Config](https://github.com/bkuhlmann/hemo/blob/main/config.ru#L4)

Anyway, may or may not help you until someone else can chime in.

---

<div class="post-metadata">

**Author:** ![rubys](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/rubys/32/630_2.png) [@rubys](https://discourse.hanakai.org/u/rubys)\
**Post date:** [March 31, 2023, 8:17pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/9 "2023-03-31T20:17:39Z")

</div>

Things noticed along the way: Avoiding links as they seem to trigger spam filters.

- If you go to github hanami/hanami and click on the API docs, you get “The page isn’t redirecting properly”
- If you go to [hanamirb.org](http://hanamirb.org) and click on docs, you get 1.3.3
- If you search for “register” in the 1.3.3 docs, you find an example that does not work:
  - you need to require “hanami/cli/command” (no trailing s)
  - you need to also require “hanami/cli”

I still haven’t tested the final line in that example as I have yet to get plugins to work.

---

<div class="post-metadata">

**Author:** ![matthewford](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/matthewford/32/633_2.png) [@matthewford](https://discourse.hanakai.org/u/matthewford)\
**Post date:** [May 25, 2023, 4:49pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/10 "2023-05-25T16:49:08Z")

</div>

Is there an example docker file? We’re thinking of deploying our app to fly.

---

<div class="post-metadata">

**Author:** ![sebastjan\_hribar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/sebastjan_hribar/32/323_2.png) [@sebastjan\_hribar](https://discourse.hanakai.org/u/sebastjan_hribar)\
**Post date:** [May 25, 2023, 6:23pm UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/11 "2023-05-25T18:23:56Z")

</div>

Hi,

I hope it’s fine to reply here and it’s not too off the main topic.

FWIW here is the link to my unrelated SO question, but you’ll see how I’ve setup two compose files for production and staging: [How to run two or more Docker environments with nginx and ssl enabled - Stack Overflow](https://stackoverflow.com/questions/76326666/how-to-run-two-or-more-docker-environments-with-nginx-and-ssl-enabled?noredirect=1#comment134595164_76326666). Variables come from different .env files.

Every environment (production, staging and so on) boots 3 containers: DB, nginx and web app.

I have most of the stuff in compose files, so the Docker file is short:

```auto
    FROM ruby:2.7.5-bullseye
    RUN apt-get update && apt-get install vim -y
    RUN bundle config --global frozen 1
    RUN adduser --disabled-login app_owner
    USER app_user
    WORKDIR /usr/src/app
    COPY --chown=app_user Gemfile Gemfile.lock ./
    COPY --chown=app_user . ./
    RUN gem install bundler:1.17.3
    RUN bundle install
    ENV HANAMI_HOST=0.0.0.0
    ENV HANAMI_ENV=production
    EXPOSE 2300

```

I also have a Makefile to streamline deployment for all environments and clients. Here is a sample of the Makefile for the staging:

```auto
# Staging for deploy environment
stage-f:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging up
stage:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging up -d
stage-b:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging up --build -d
stage-bf:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging up --build
stage-down:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging down
stage-down-v:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging down --volumes
stage-stop:
	docker-compose -f docker-compose-staging.yml --env-file .env.staging stop

```

See also here: [https://codereviewvideos.com/course/docker-tutorial-for-beginners/video/docker-compose-multiple-environments](https://codereviewvideos.com/course/docker-tutorial-for-beginners/video/docker-compose-multiple-environments)

I control now everything with a Makefile and it really pays off. The problem in the question above is most likely linked to my poor knowledge of port mapping. Hopefully, I’ll resolve it soon.

I hope this helps.

Best, Seba

---

<div class="post-metadata">

**Author:** ![aotoki](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/aotoki/32/665_2.png) [@aotoki](https://discourse.hanakai.org/u/aotoki)\
**Post date:** [December 18, 2023, 4:17am UTC](https://discourse.hanakai.org/t/dockerfile-hanami/816/12 "2023-12-18T04:17:36Z")

</div>

Hi, @rubys

I have a similar gem [GitHub - elct9620/boxing: The zero-configuration Dockerfile generator for Ruby.](https://github.com/elct9620/boxing) that can generate Dockerfile, too.

According to the discussion, I think we both depend on Thor’s template feature to generate it.

I have an idea is use Rake to replace Thor and use `ERB` directly to generate the Dockerfile. The Rails and Hanami both support the rake and we can easily extend them to have the same command.
