This repository was archived by the owner on Jul 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Add Docker Support for Local Development and CI Pipeline #40
Copy link
Copy link
Open
Labels
Description
Description
Add Docker support to the project to ensure consistency between local development and the CI pipeline. This will help mimic the CI environment locally, allowing for early detection of issues before code is pushed to GitHub.
Steps to Implement
- Create Dockerfile:
- Add a Dockerfile to the project root with the necessary configuration to set up the development environment.
- Ensure the Dockerfile includes:
- Installation of Ruby 3.2.2
- Installation of Node.js
- Installation of Postgres client
- Installation of necessary gems and npm packages
- Precompilation of assets
- Update Database Configuration:
- Update config/database.yml to use environment variables for database configuration, allowing for easy configuration in Docker.
- Create Docker Compose File (Optional):
- Add a docker-compose.yml file to define and run multi-container Docker applications.
- Include services for the app and Postgres database.
4.Update Documentation:
- Update README.md with instructions on how to build and run the Docker container locally.
- Include steps for running tests within the Docker container.
Example Dockerfile:
# Use the official Ruby image as a base
FROM ruby:3.2.2
# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
# Install Postgres client
RUN apt-get update -qq && apt-get install -y postgresql-client
# Set up working directory
WORKDIR /app
# Copy the Gemfile and Gemfile.lock
COPY Gemfile* ./
# Install bundler and gems
RUN gem install bundler:2.5.5
RUN bundle install
# Copy the rest of the application code
COPY . .
# Install npm dependencies
RUN npm install --legacy-peer-deps
# Precompile assets
RUN node build.ci.js
# Expose the port your app runs on
EXPOSE 3000
# Start the main process
CMD ["rails", "server", "-b", "0.0.0.0"]
Example docker-compose.yml (Optional):
version: '3.8'
services:
db:
image: postgres:latest
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: line_development
ports:
- "5432:5432"
web:
build: .
command: bundle exec rails server -b 0.0.0.0
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/line_development
Example Database Configuration:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: <%= ENV['POSTGRES_USER'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>
host: <%= ENV['POSTGRES_HOST'] || 'localhost' %>
development:
<<: *default
database: line_development
test:
<<: *default
database: line_test
Run Tests in the Docker Container
docker-compose run web bundle exec rspec