|
| 1 | +VERSION 0.7 |
| 2 | + |
| 3 | +# This allows one to change the running Ruby version with: |
| 4 | +# |
| 5 | +# `earthly --allow-privileged +test --EARTHLY_RUBY_VERSION=2.7` |
| 6 | +ARG --global EARTHLY_RUBY_VERSION=3.3 |
| 7 | +ARG --global BUNDLER_VERSION=2.4.5 |
| 8 | + |
| 9 | +FROM ruby:$EARTHLY_RUBY_VERSION |
| 10 | +WORKDIR /gem |
| 11 | + |
| 12 | +deps: |
| 13 | + # No need to keep a single `RUN` here since this target uses `SAVE ARTIFACT` |
| 14 | + # which means there's no Docker image created here. |
| 15 | + RUN apt update \ |
| 16 | + && apt install --yes \ |
| 17 | + --no-install-recommends \ |
| 18 | + build-essential \ |
| 19 | + git \ |
| 20 | + && mkdir /gems \ |
| 21 | + && git clone https://github.com/Pharmony/warden.git /gems/warden \ |
| 22 | + && cd /gems/warden \ |
| 23 | + && git checkout features/support-multiple-messages \ |
| 24 | + && gem install bundler:${BUNDLER_VERSION} |
| 25 | + |
| 26 | + COPY Gemfile /gem/Gemfile |
| 27 | + COPY Gemfile.lock /gem/Gemfile.lock |
| 28 | + COPY *.gemspec /gem |
| 29 | + COPY lib/devise/version.rb /gem/lib/devise/version.rb |
| 30 | + |
| 31 | + RUN bundle install --jobs $(nproc) |
| 32 | + |
| 33 | + SAVE ARTIFACT /gems git-gems |
| 34 | + SAVE ARTIFACT /usr/local/bundle bundler |
| 35 | + SAVE ARTIFACT /gem/Gemfile Gemfile |
| 36 | + SAVE ARTIFACT /gem/Gemfile.lock Gemfile.lock |
| 37 | + |
| 38 | +dev: |
| 39 | + RUN apt update \ |
| 40 | + && apt install --yes \ |
| 41 | + --no-install-recommends \ |
| 42 | + git \ |
| 43 | + && gem install bundler:${BUNDLER_VERSION} |
| 44 | + |
| 45 | + # Import cached gems |
| 46 | + COPY +deps/git-gems /gems |
| 47 | + COPY +deps/bundler /usr/local/bundle |
| 48 | + COPY +deps/Gemfile /gem/Gemfile |
| 49 | + COPY +deps/Gemfile.lock /gem/Gemfile.lock |
| 50 | + |
| 51 | + # Import gem files |
| 52 | + FOR gem_folder IN app config lib test *.gemspec Rakefile |
| 53 | + COPY $gem_folder /gem/$gem_folder |
| 54 | + END |
| 55 | + |
| 56 | + ENTRYPOINT ["bundle", "exec"] |
| 57 | + CMD ["rake"] |
| 58 | + |
| 59 | + # Run `earthly +dev` in order to get the Docker image exported to your |
| 60 | + # Docker images. |
| 61 | + SAVE IMAGE heartcombo/devise:latest |
| 62 | + |
| 63 | +# |
| 64 | +# This target runs the test suite. |
| 65 | +# |
| 66 | +# On you local machine you would likely use `docker compose run --rm gem` |
| 67 | +# instead, avoiding to refresh the Docker image which takes some seconds. |
| 68 | +# |
| 69 | +# Use the following command in order to run the tests suite: |
| 70 | +# earthly --allow-privileged +test [--TEST_COMMAND="rake test TEST=test/test_foobar.rb"] |
| 71 | +# |
| 72 | +# See the above `EARTHLY_RUBY_VERSION` variable. |
| 73 | +test: |
| 74 | + FROM earthly/dind:alpine |
| 75 | + |
| 76 | + COPY docker-compose-earthly.yml ./docker-compose.yml |
| 77 | + |
| 78 | + # Optionnal argument in the case you'd like to run something else than |
| 79 | + # `rake test` |
| 80 | + ARG TEST_COMMAND |
| 81 | + |
| 82 | + # Creates a temporary Docker image using the output from the +dev target, |
| 83 | + # that will be used within the `WITH DOCKER ... END` block only. |
| 84 | + WITH DOCKER --load heartcombo/devise:latest=+dev |
| 85 | + RUN docker-compose run --rm gem $TEST_COMMAND |
| 86 | + END |
0 commit comments