Giter Club home page Giter Club logo

ruby-on-whales's Introduction

Ruby on Whales

This repository contains an example dockerized Ruby on Rails development configuration based on the Ruby on Whales blog post.

Example configuration

See the example folder.

Interactive generator

We also provide an interactive generator for Rails apps to quickly setup a dockerized environment for your app. Just run the following command and follow the instructions:

bundle exec rails app:template LOCATION='https://railsbytes.com/script/z5OsoB'

You can also run it via Ruby Bytes (so you can dockerize a Rails app without installing it on your host machine):

rbytes install https://railsbytes.com/script/z5OsoB

See also

License

The code is available as open source under the terms of the MIT License.

ruby-on-whales's People

Contributors

envek avatar fargelus avatar kalashnikovisme avatar manuelvanrijn avatar oliverklee avatar palkan avatar rinasergeeva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-on-whales's Issues

Dockerfile tests fail

https://github.com/evilmartians/ruby-on-whales/runs/5643222494?check_suite_focus=true

 DockerfileTest
  test_default_dockerfile                                         FAIL (6.57s)
        Expected "ARG RUBY_VERSION\nARG DISTRO_NAME=bullseye\n\nFROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME\n\nARG DISTRO_NAME\n\n# Common dependencies\nRUN apt-get update -qq \\\n  && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \\\n    build-essential \\\n    gnupg2 \\\n    curl \\\n    less \\\n    git \\\n  && apt-get clean \\\n  && rm -rf /var/cache/apt/archives/* \\\n  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \\\n  && truncate -s 0 /var/log/*log\n\n# Application dependencies\n# We use an external Aptfile for this, stay tuned\nCOPY Aptfile /tmp/Aptfile\nRUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \\\n  DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \\\n    $(grep -Ev '^\\s*#' /tmp/Aptfile | xargs) \\\n    && apt-get clean \\\n    && rm -rf /var/cache/apt/archives/* \\\n    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \\\n    && truncate -s 0 /var/log/*log\n\n# Configure bundler\nENV LANG=C.UTF-8 \\\n  BUNDLE_JOBS=4 \\\n  BUNDLE_RETRY=3\n\n# Store Bundler settings in the project's root\nENV BUNDLE_APP_CONFIG=.bundle\n\n# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec`\n# ENV PATH /app/bin:$PATH\n\n# Upgrade RubyGems and install the latest Bundler version\nRUN gem update --system && \\\n    gem install bundler\n\n# Create a directory for the app code\nRUN mkdir -p /app\nWORKDIR /app\n\n# Document that we're going to expose port 3000\nEXPOSE 3000\n# Use Bash as the default command\nCMD [\"/usr/bin/bash\"]\n" to include "RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add".
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:79:in `assert_file_contains'
        test/generator/dockerfile_test.rb:17:in `test_default_dockerfile'

Typo inside compose.yml

Hello.

I found type inside of compose.yml template that cause error after exit from dip rails c command.

Probably fix:
IRB_HISTFILE: /usr/local/hst/.irb_history => IRB_HISTFILE: /usr/local/hist/.irb_history

XDG_DATA_HOME compose env variable location?

We're implementing a version of the docker setup outlined here for our own development, and was curious if the following was intentional:

The rails_cache volume is set to /app/tmp/cache:

- rails_cache:/app/tmp/cache

The XDG_DATA_HOME environment variable is set to /app/tmp/caches (plural):

XDG_DATA_HOME: /app/tmp/caches

Is XDG_DATA_HOME meant to be on the rails_cache volume? or a different directory with a too-close name?

Test failures on CI in NodeTest

https://github.com/evilmartians/ruby-on-whales/pull/11/checks

NodeTest
  test_default_node_versions                                      FAIL (1.26s)
        Expected to print line: Which Node version do you want to install? (Press ENTER to use 16, type 'n/no' to skip installing Node). Got: <ER to use 16, type 'n/no' to skip installing Node) 
        <o install? (Press ENTER to install the latest one) 
        NODE_VERSION=16
        YARN_VERSION=latest
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:71:in `assert_line_printed'
        test/generator/node_test.rb:16:in `block in test_default_node_versions'
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:61:in `block (2 levels) in run_generator'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/open3.rb:227:in `popen_run'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/open3.rb:209:in `popen2e'
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:54:in `block in run_generator'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.9/lib/bundler.rb:399:in `block in with_unbundled_env'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.9/lib/bundler.rb:698:in `with_env'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.9/lib/bundler.rb:399:in `with_unbundled_env'
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:51:in `run_generator'
        test/generator/node_test.rb:14:in `test_default_node_versions'

  test_custom_node_versions                                       FAIL (1.24s)
        Expected to print line: Which Node version do you want to install? (Press ENTER to use 16, type 'n/no' to skip installing Node). Got: <ER to use 16, type 'n/no' to skip installing Node) 14
        <o install? (Press ENTER to install the latest one) 1.13.0
        NODE_VERSION=14
        YARN_VERSION=1.13.0
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:71:in `assert_line_printed'
        test/generator/node_test.rb:41:in `block in test_custom_node_versions'
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:61:in `block (2 levels) in run_generator'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/open3.rb:227:in `popen_run'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/open3.rb:209:in `popen2e'
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:54:in `block in run_generator'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.9/lib/bundler.rb:399:in `block in with_unbundled_env'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.9/lib/bundler.rb:698:in `with_env'
        /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.9/lib/bundler.rb:399:in `with_unbundled_env'
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:51:in `run_generator'
        test/generator/node_test.rb:39:in `test_custom_node_versions'

  test_skip_node                                                  FAIL (1.25s)
        Expected to print line: Which Node version do you want to install? (Press ENTER to use 16, type 'n/no' to skip installing Node). Got: <ER to use 16, type 'n/no' to skip installing Node) n
        NODE_VERSION=nope
        YARN_VERSION=
        /home/runner/work/ruby-on-whales/ruby-on-whales/test/test_helper.rb:71:in `assert_line_printed'

DockerfileTest fails: No PostgreSQL, Node and Yarn sections generated

https://github.com/evilmartians/ruby-on-whales/runs/5660599326?check_suite_focus=true

According to the test run in https://github.com/evilmartians/ruby-on-whales/runs/5660599326?check_suite_focus=true, the Dockerfile generated in the tests does not have the sections that are within conditions that depend on the variables postgres_version, node_version and yarn_version, causing the test to fail.

I don't know whether the generator is broken or whether the it is the test.

How to use cache in github action when using dip

Reference

When using dip.yml it is convenient to use it in github actions as well. Example from a repo of mine

    - name: Build Images
        run: dip build
        shell: bash

      - name: Pull Images
        run: dip compose pull redis minio caddy  
        shell: bash
      
      - name: Provision
        run: touch .dockerdev/.bashrc && dip provision
        shell: bash

      - name: Integration Tests
        run: dip test system
        shell: bash

By default this doesn't cache the images created in dip build step. How can we do that?

Failed to fetch http://deb.debian.org/debian/dists/bullseye-updates/InRelease Unable to connect to deb.debian.org:80

I'm updating one of our apps to 2.0, but I'm having trouble getting it to build. It's bombing out with the following

Step 5/20 : RUN apt-get update -qq   && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends     build-essential     gnupg2     curl     less     git   && apt-get clean   && rm -rf /var/cache/apt/archives/*   && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*   && truncate -s 0 /var/log/*log
 ---> Running in cdf872855db3
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye/InRelease  Could not connect to deb.debian.org:80 (151.101.18.132), connection timed out
W: Failed to fetch http://security.debian.org/debian-security/dists/bullseye-security/InRelease  Could not connect to security.debian.org:80 (151.101.2.132), connection timed out Could not connect to security.debian.org:80 (151.101.66.132), connection timed out Could not connect to security.debian.org:80 (151.101.130.132), connection timed out Could not connect to security.debian.org:80 (151.101.194.132), connection timed out
W: Failed to fetch http://deb.debian.org/debian/dists/bullseye-updates/InRelease  Unable to connect to deb.debian.org:80:
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
Package gnupg2 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  gpgv

Package less is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Unable to locate package build-essential
E: Package 'gnupg2' has no installation candidate
E: Unable to locate package curl
E: Package 'less' has no installation candidate
E: Unable to locate package git
ERROR: Service 'rails' failed to build : The command '/bin/sh -c apt-get update -qq   && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends     build-essential     gnupg2     curl     less     git   && apt-get clean   && rm -rf /var/cache/apt/archives/*   && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*   && truncate -s 0 /var/log/*log' returned a non-zero code: 100
ERROR: Command 'dip bash -c bin/setup' executed with error

I have made some minor changes to the Dockerfile and compose.yml files, but nothing which I think would be causing this problem - I've shared them below anyway.

x-app: &app
  build:
    context: .
    args:
      RUBY_VERSION: '3.0.3'
      PG_MAJOR: '14'
      NODE_MAJOR: '16'
  image: amigo:2.0.1
  environment: &env
    NODE_ENV: ${NODE_ENV:-development}
    RAILS_ENV: ${RAILS_ENV:-development}
  tmpfs:
    - /tmp
    - /app/tmp/pids

x-backend: &backend
  <<: *app
  stdin_open: true
  tty: true
  volumes:
    - ..:/app:cached
    - bundle:/usr/local/bundle
    - rails_cache:/app/tmp/cache
    - node_modules:/app/node_modules
    - history:/usr/local/hist
    - ./.psqlrc:/root/.psqlrc:ro
    - ./.bashrc:/root/.bashrc:ro
  environment: &backend_environment
    <<: *env
    DATABASE_URL: postgres://postgres:postgres@postgres:5432
    MALLOC_ARENA_MAX: 2
    WEB_CONCURRENCY: ${WEB_CONCURRENCY:-1}
    BOOTSNAP_CACHE_DIR: /usr/local/bundle/_bootsnap
    XDG_DATA_HOME: /app/tmp/caches
    HISTFILE: /usr/local/hist/.bash_history
    PSQL_HISTFILE: /usr/local/hist/.psql_history
    IRB_HISTFILE: /usr/local/hst/.irb_history
    EDITOR: vi
  depends_on: &backend_depends_on
    postgres:
      condition: service_healthy

services:
  rails:
    <<: *backend
    command: bundle exec rails

  web:
    <<: *backend
    command: bundle exec rails server -b 0.0.0.0
    ports:
      - '3000:3000'

  postgres:
    image: postgres:14
    volumes:
      - .psqlrc:/root/.psqlrc:ro
      - postgres:/var/lib/postgresql/data
      - history:/user/local/hist
    environment:
      PSQL_HISTFILE: /user/local/hist/.psql_history
      POSTGRES_PASSWORD: postgres
    ports:
      - 5432
    healthcheck:
      test: pg_isready -U postgres -h 127.0.0.1
      interval: 5s

volumes:
  bundle:
  node_modules:
  history:
  rails_cache:
  postgres:
ARG RUBY_VERSION
ARG DISTRO_NAME=bullseye

FROM ruby:$RUBY_VERSION-slim-$DISTRO_NAME

ARG DISTRO_NAME

# Common dependencies
RUN apt-get update -qq \
  && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    build-essential \
    gnupg2 \
    curl \
    less \
    git \
  && apt-get clean \
  && rm -rf /var/cache/apt/archives/* \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
  && truncate -s 0 /var/log/*log

ARG PG_MAJOR
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
  && echo deb http://apt.postgresql.org/pub/repos/apt/ $DISTRO_NAME-pgdg main $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
  DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    libpq-dev \
    postgresql-client-$PG_MAJOR \
    && apt-get clean \
    && rm -rf /var/cache/apt/archives/* \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && truncate -s 0 /var/log/*log

ARG NODE_MAJOR
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
  DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    nodejs \
    && apt-get clean \
    && rm -rf /var/cache/apt/archives/* \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && truncate -s 0 /var/log/*log

# Application dependencies
# We use an external Aptfile for this, stay tuned
COPY Aptfile /tmp/Aptfile
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
  DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
    $(grep -Ev '^\s*#' /tmp/Aptfile | xargs) \
    && apt-get clean \
    && rm -rf /var/cache/apt/archives/* \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && truncate -s 0 /var/log/*log

# Configure bundler
ENV LANG=C.UTF-8 \
  BUNDLE_JOBS=4 \
  BUNDLE_RETRY=3

# Store Bundler settings in the project's root
ENV BUNDLE_APP_CONFIG=.bundle

# Uncomment this line if you want to run binstubs without prefixing with `bin/` or `bundle exec`
# ENV PATH /app/bin:$PATH

# Upgrade RubyGems and install the latest Bundler version
RUN gem update --system && \
    gem install bundler

# Create a directory for the app code
RUN mkdir -p /app
WORKDIR /app

# Document that we're going to expose port 3000
EXPOSE 3000
# Use Bash as the default command
CMD ["/usr/bin/bash"]

How to fix "It seems your ruby installation is missing psych (for YAML output)."?

Hey,
thank you for this repo. I learned a lot from it. I updated the ruby version of one of my projects from 2.7.x to 3.0.0, but now I'm struggling with the following bundle install-error:

/usr/local/lib/ruby/3.0.0/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
LoadError: libruby.so.3.1: cannot open shared object file: No such file or directory - /usr/local/bundle/gems/psych-3.3.2/lib/psych.so

I'm using ruby:3.0.3-slim-buster. Installing libyaml-dev does not solve the issue.

Do you know the reason for this?

Thanks and best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.