Skip to content

Instantly share code, notes, and snippets.

@hungle00
Last active April 14, 2023 08:38
Show Gist options
  • Select an option

  • Save hungle00/9208dc7a0197a43346496d2aa5df3bc0 to your computer and use it in GitHub Desktop.

Select an option

Save hungle00/9208dc7a0197a43346496d2aa5df3bc0 to your computer and use it in GitHub Desktop.
Use docker-compose to dockerize rails app
version: "3"
services:
db:
image: postgres:12.6-alpine
environment:
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
web:
build: .
command: bin/rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/usr/src/app
ports:
- "3000:3000"
depends_on:
- db
FROM ruby:2.6.6-alpine3.12
LABEL maintainer="hungle"
# Minimal requirements to run a Rails app
RUN apk add --no-cache --update build-base \
linux-headers \
git \
postgresql-dev \
nodejs \
yarn \
tzdata
ENV APP_PATH /usr/src/app
# Different layer for gems installation
WORKDIR $APP_PATH
ADD Gemfile $APP_PATH
ADD Gemfile.lock $APP_PATH
RUN gem list bundler
RUN gem install bundler -v 2.2.4
RUN bundle install
# Copy the application into the container
COPY . $APP_PATH
EXPOSE 3000
name: Auction Api
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports: ['5432:5432']
env:
POSTGRES_USER: auction_api
POSTGRES_PASSWORD: rails_dev
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.6
bundler-cache: true
- name: Install dependencies
run: |
bundle install --jobs 4 --retry 3
yarn
- name: Setup db and test
env:
RAILS_ENV: test
POSTGRES_PASSWORD: rails_dev
run: |
bundle exec rails db:setup
bundle exec rspec
docker-compose build
docker-compose run --rm web bin/rails db:create
docker-compose run --rm web bin/rails db:migrate
docker-compose run --rm web bin/rails db:seed
docker-compose up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment