Skip to content

Commit

Permalink
Introducing Docker to Grape (#2292)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Apr 23, 2023
1 parent 3b6f3db commit 4efe0d6
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## MAC OS
.DS_Store
.com.apple.timemachine.supported

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## REDCAR
.redcar

## VIM
*.swp
*.swo

## RUBYMINE
.idea

## PROJECT::GENERAL
coverage
doc
pkg
.rvmrc
.ruby-version
.ruby-gemset
.rspec_status
.bundle
.byebug_history
dist
Gemfile.lock
gemfiles/*.lock
tmp
.yardoc

## Rubinius
.rbx

## Bundler binstubs
bin

## ripper-tags and gem-ctags
tags

## PROJECT::SPECIFIC
.project
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [#2311](https://github.com/ruby-grape/grape/pull/2311): Fix tests by pinning rack-test to < 2.1 - [@duffn](https://github.com/duffn).
* [#2310](https://github.com/ruby-grape/grape/pull/2310): Fix YARD docs markdown rendering - [@duffn](https://github.com/duffn).
* [#2317](https://github.com/ruby-grape/grape/pull/2317): Remove maruku and rubocop-ast as direct development/testing dependencies - [@ericproulx](https://github.com/ericproulx).
* [#2292](https://github.com/ruby-grape/grape/pull/2292): Introduce Docker to local development - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@ git pull upstream master
git checkout -b my-feature-branch
```

### Docker

If you're familiar with [Docker](https://www.docker.com/), you can run everything through the following command:

```
docker-compose run --rm --build grape <command_and_parameters>
```

About the execution process:
- displays Ruby, Rubygems, Bundle and Gemfile version when starting:
```
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux-musl]
rubygems 3.4.12
Bundler version 2.4.1 (2022-12-24 commit f3175f033c)
Running default Gemfile
```
- keeps the gems to the latest possible version
- executes under `bundle exec`

Here are some examples:

- 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_0.gemfile) `docker-compose run -e GEMFILE=rails_7_0 --rm --build grape rspec`

#### Bundle Install and Test

Ensure that you can build the project and run tests.
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'

volumes:
gems:

services:
grape:
build:
context: .
dockerfile: docker/Dockerfile
args:
- RUBY_VERSION=${RUBY_VERSION:-3}
stdin_open: true
tty: true
volumes:
- .:/var/grape
- gems:/usr/local/bundle
15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION-alpine

ENV BUNDLE_PATH /usr/local/bundle/gems
ENV LIB_PATH /var/grape

RUN apk add --update --no-cache make gcc git libc-dev && \
gem update --system && gem install bundler

WORKDIR $LIB_PATH

COPY /docker/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]
16 changes: 16 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -e

# Useful information
echo -e "$(ruby --version)\nrubygems $(gem --version)\n$(bundle version)"
if [ -z "${GEMFILE}" ]
then
echo "Running default Gemfile"
else
export BUNDLE_GEMFILE="./gemfiles/${GEMFILE}.gemfile"
echo "Running gemfile: ${GEMFILE}"
fi

# Keep gems in the latest possible state
(bundle check || bundle install) && bundle update && bundle exec ${@}

0 comments on commit 4efe0d6

Please sign in to comment.