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

Redockerizing #2669

Open
jhsu802701 opened this issue Mar 17, 2021 · 7 comments
Open

Redockerizing #2669

jhsu802701 opened this issue Mar 17, 2021 · 7 comments

Comments

@jhsu802701
Copy link
Contributor

The current Docker setup does not include a container for Rails. We need a setup that includes a Rails container as well as containers for all other necessary services.

An example of what I plan to provide is at https://github.com/jhsu802701/rubymn2. Note that running the docker/build script takes care of everything needed in the setup PLUS testing, database seeding, and other features. Of course, the setup required here will be more complex and include more services.

@sonalkr132
Copy link
Member

Have you tried updating our docker-compose file and added the app folder as mount from the host? Please try this and let us know about issues.

he docker/build script takes care of everything needed in the setup PLUS testing, database seeding, and other features.

please elaborate on your proposal with regard to what specific changes would be needed. will it only involve build pipeline changes?

Note that we would not want to change our Dockerfile too drastically just to support development on docker.

@jhsu802701
Copy link
Contributor Author

In the RubyMN2 app (https://github.com/jhsu802701/rubymn2), running "docker/build" runs docker-compose build and executes the creation of the database, database migrations, running the test suite, seeding the database, creating block diagrams of the app (with railroady and rails-erd), and runs tests of the code quality (with tools like RuboCop, Rails Best Practices, Brakeman, Bundler-Audit, and Gemsurance). Note that there is a Docker container for Rails, which means that there is NO need to install Ruby or Rails in the host OS. All the host OS needs is Docker.

@jhsu802701
Copy link
Contributor Author

Note that we would not want to change our Dockerfile too drastically just to support development on docker.

OK, I see that the Dockerfile and docker-compose.yml file are used for building a Docker image in the GitHub CI environment to be pushed to quay.io (https://quay.io/repository/rubygems/rubygems.org). The Docker setup is NOT intended for use on my local machine.

I see that .github/workflows/docker.yml (part of the GitHub continuous integration) executes "docker-compose up -d" and then "./script/build_docker.sh". The CI environment starts up a Docker container based on the instructions in the Dockerfile and docker-compose.yml file. Then it runs the script/build_docker.sh script to turn this Docker container into a new Docker image and then uploads this new image to quay.io.

How accurate is this?

I'm trying to create a development environment that does NOT require me to install Ruby on Rails in my host OS. Given that the Dockerfile and docker-compose.yml file are dedicated to creating a Docker image for the production environment, I understand that changing them to create a local development environment (the conventional way of using Docker) is not a viable option.

So the possible paths forward are:

  1. Use the Docker image from quay.io to create a Docker container for my development environment. I could contribute scripts for this.
  2. Use Vagrant. I could contribute a Vagrantfile and other code for this. It's slower than a Docker development environment, but at least it would provide in the end a set-it-and-forget-it way to set things up in one fell swoop.

@sonalkr132
Copy link
Member

I understand that changing them to create a local development environment (the conventional way of using Docker) is not a viable option.

yeah, it is not possible to our existing Dockerfile for development. It should be okay to create a new Dockerfile.dev and use that in docker-compose.yaml to setup web.

The CI environment starts up a Docker container based on the instructions in the Dockerfile and docker-compose.yml file.

CI used docker-compose to only setup dependencies like postgres, es, and memcache, which are required to run tests. Dockerfile is only used for prod image build and does not depend on docker-compose (except for some smoke tests, where pg is required).

Use the Docker image from quay.io to create a Docker container for my development environment. I could contribute scripts for this.

I think a separate Dockerfile would probably be more straightforward.

@jhsu802701
Copy link
Contributor Author

OK, thanks for the idea of using an alternate Dockerfile. I've found details on how to implement this at https://docs.docker.com/compose/compose-file/compose-file-v3/ . So I'd be adding at least one additional service to the docker-compose.yml file.

@jhsu802701
Copy link
Contributor Author

I'll also add an alternate or overriding docker-compose.yml file. This is explained at https://docs.docker.com/compose/extends/ .

@simi
Copy link
Member

simi commented Oct 31, 2023

dev Dockerfile could be as simple as

# syntax=docker/dockerfile:1.4

# Use an official Ruby runtime as a parent image, with the Alpine variant for a smaller size
ARG RUBY_VERSION=3.2.2
ARG ALPINE_VERSION=3.18
FROM ruby:${RUBY_VERSION}-alpine${ALPINE_VERSION}

# Set the working directory in the container
WORKDIR /app

# Install system dependencies required by the project
# No need to optimize with cache mounts or other stages as in the production Dockerfile
RUN apk add --no-cache \
  bash \
  build-base \
  git \
  postgresql-dev \
  nodejs \
  tzdata \
  yarn

# Copy the Gemfile and Gemfile.lock into the container
COPY Gemfile* /app/

# Install the Ruby gems, including those needed in development and test groups
RUN bundle install

# Copy the main application.
COPY . /app/

# By default, execute the Rails server in development mode on port 3000
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

and docker-compose could be extend with similar service to use it

  web:
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - .:/app
    depends_on:
      - db
      - cache
      - search
    environment:
      - DATABASE_URL=postgres://postgres@localhost:5432
    profiles: ["dev"]
    network_mode: "host"

But that would not work on MacOs since there is no support for network_mode host. Any better solution? Anyone still interested in this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants