Skip to content
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

Introducing Docker to Grape #2292

Merged
merged 14 commits into from
Apr 23, 2023
Merged

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Dec 20, 2022

Hi,

I've been using Docker for a while now and I thought it would be a great addition to include a Dockerfile to Grape. Also, docker-compose always been my go to for running containers even though its for multiple containers. It's just easier to configure than running docker commands with arguments.

Dockerfile

  • As an ARG called RUBY_VERSION for building an image on different ruby-version
  • Setting BUNDLE_PATH to /usr/local/bundle/gems
  • Setting LIB_PATH to /var/grape. Code from the host will be copied in that folder
  • Add basic packages for development
  • Install latest version of rubygems and bundle
  • Starts with an entrypoint

Entrypoint

  • echoes version of ruby, rubygems and bundle.
  • check gems sanity with bundle
  • update gems to latest version
  • execute bundle exec :your_command

Docker-compose

  • Default RUBY_VERSION to 3.
  • Add gems volume

Basic CLI

  • Basic command docker-compose run --rm --build grape <your_command>. You may replace <your_command> by anything that runs under bundle exec
  • --rm will remove automatically the container
  • --build will automatically build or rebuild the image (useful when changing RUBY_VERSION)

CLI

  • Running all specs docker-compose run --rm --build grape rspec
  • Running rspec on a specific file docker-compose run --rm --build grape rspec spec/:file_path
  • Running task docker-compose run --rm --build grape rake <task_name>
  • Running rubocop docker-compose run --rm --build grape rubocop
  • Running all specs on a specific ruby version (e.g 2.7.7) RUBY_VERSION=2.7.7 docker-compose run --rm --build grape rspec
  • Running specs on a specific gemfile (e.g rails_7.gemfile) docker-compose run -e GEMFILE=rails_7 --rm --build grape rspec

Running the container will automatically install the missings gems and run your command.

Add entrypoint.sh
Add docker-compose.yml
@dblock
Copy link
Member

dblock commented Dec 20, 2022

Let's add something to the README about using this and a CHANGELOG entry?

Should there be a workflow that brings up the container in CI?

@duffn
Copy link
Member

duffn commented Mar 16, 2023

This is nice to show people how to use Docker with grape but if it goes in the repo, feels like it belongs in something like an “examples” directory.

@ericproulx
Copy link
Contributor Author

This is nice to show people how to use Docker with grape but if it goes in the repo, feels like it belongs in something like an “examples” directory.

@duffn I've added examples in the CONTRIBUTING.md

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit below.

CONTRIBUTING.md Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
@dblock
Copy link
Member

dblock commented Apr 16, 2023

Can I have other maintainers say whether they would like this merged or not?

Should we require/add a CI to ensure the Dockerfile works?

CONTRIBUTING.md Outdated Show resolved Hide resolved
Copy link
Member

@dm1try dm1try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked locally, looks good to me)

@ericproulx
Copy link
Contributor Author

rubocop offenses fixed in #2319

@dblock
Copy link
Member

dblock commented Apr 23, 2023

Thanks. Rebase?

I just merged it. We can fix any failures on main.

@dblock dblock merged commit 4efe0d6 into ruby-grape:master Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants