Created
April 7, 2021 18:20
-
-
Save fdietz/1242349e6f6afff554d8a6fe66f80726 to your computer and use it in GitHub Desktop.
Rails Docker Compose Setup for local development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DS_Store | |
.bin | |
.git | |
.gitignore | |
.bundleignore | |
.bundle | |
.byebug_history | |
.rspec | |
tmp | |
log | |
test | |
config/deploy | |
public/packs | |
public/packs-test | |
node_modules | |
yarn-error.log | |
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:2.7.2 | |
WORKDIR /app | |
COPY Gemfile Gemfile.lock ./ | |
RUN bundle install | |
# Install Yarn. | |
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - | |
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list | |
RUN apt-get update && apt-get install -y yarn | |
COPY package.json yarn.lock ./ | |
RUN yarn install | |
COPY . /app | |
# Set "rails server -b 0.0.0.0" as the command to | |
# run when this container starts. | |
CMD ["rails", "server", "-b", "0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.3" | |
services: | |
web: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
stdin_open: true | |
tty: true | |
tmpfs: | |
- /tmp | |
volumes: | |
- .:/app:cached | |
- rails_cache:/app/tmp/cache | |
- gem_cache:/usr/local/bundle/gems | |
- node_modules:/app/node_modules | |
environment: | |
- NODE_ENV=development | |
- RAILS_ENV=development | |
- REDIS_URL=redis://redis:6379/ | |
- DATABASE_URL=postgres://postgres:postgres@postgres:5432 | |
depends_on: | |
- postgres | |
- redis | |
- elasticsearch | |
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" | |
ports: | |
- "3000:3000" | |
sidekiq: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
stdin_open: true | |
tty: true | |
tmpfs: | |
- /tmp | |
volumes: | |
- .:/app:cached | |
- rails_cache:/app/tmp/cache | |
- gem_cache:/usr/local/bundle/gems | |
- node_modules:/app/node_modules | |
environment: | |
- NODE_ENV=development | |
- RAILS_ENV=development | |
- REDIS_URL=redis://redis:6379/ | |
- DATABASE_URL=postgres://postgres:postgres@postgres:5432 | |
depends_on: | |
- postgres | |
- redis | |
command: bash -c "rm -f tmp/pids/server.pid && bundle exec sidekiq -C config/sidekiq.yml" | |
webpacker: | |
build: | |
context: . | |
dockerfile: Dockerfile | |
stdin_open: true | |
tty: true | |
tmpfs: | |
- /tmp | |
volumes: | |
- .:/app:cached | |
- rails_cache:/app/tmp/cache | |
- gem_cache:/usr/local/bundle/gems | |
- node_modules:/app/node_modules | |
- packs:/app/public/packs | |
environment: | |
- NODE_ENV=${NODE_ENV:-development} | |
- RAILS_ENV=${RAILS_ENV:-development} | |
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0 | |
command: ./bin/webpack-dev-server | |
ports: | |
- '127.0.0.1:3035:3035' | |
postgres: | |
image: postgres:12.1 | |
volumes: | |
- db_data:/var/lib/postgresql/data | |
- ./init.sql:/docker-entrypoint-initdb.d/init.sql | |
ports: | |
- 5432 | |
healthcheck: | |
test: pg_isready -U postgres -h 127.0.0.1 | |
interval: 5s | |
redis: | |
image: redis:5.0.7 | |
volumes: | |
- redis:/data | |
ports: | |
- 6379 | |
healthcheck: | |
test: redis-cli ping | |
interval: 1s | |
timeout: 3s | |
retries: 30 | |
elasticsearch: | |
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0 | |
ports: | |
- 9200 | |
volumes: | |
rails_cache: | |
gem_cache: | |
db_data: | |
node_modules: | |
redis: | |
packs: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
jobs: | |
test: | |
runs-on: ubuntu-18.04 | |
services: | |
postgres: | |
image: postgres:11 | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
redis: | |
image: redis:alpine | |
ports: ["6379:6379"] | |
options: --entrypoint redis-server | |
steps: | |
- run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p | |
- uses: actions/checkout@v2 | |
- uses: ankane/setup-elasticsearch@v1 | |
with: | |
elasticsearch-version: 7 | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: '2.7.2' | |
- name: Ruby gem cache | |
uses: actions/cache@v1 | |
with: | |
path: vendor/bundle | |
key: ${{ runner.os }}-${{ env.ImageVersion }}-gems-${{ hashFiles('**/Gemfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.ImageVersion }}-gems | |
- name: Setup Node | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 12.16.1 | |
- name: Find yarn cache location | |
id: yarn-cache | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- name: JS package cache | |
uses: actions/cache@v1 | |
with: | |
path: ${{ steps.yarn-cache.outputs.dir }} | |
key: ${{ runner.os }}-${{ env.ImageVersion }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-${{ env.ImageVersion }}-yarn | |
- name: Install dependencies | |
run: | | |
sudo apt-get install libpq-dev | |
gem install bundler | |
bundle config path vendor/bundle | |
bundle install --jobs 4 --retry 3 | |
yarn install --frozen-lockfile | |
- name: "Compile Assets" | |
shell: bash | |
run: | | |
bin/rails webpacker:compile | |
env: | |
RAILS_ENV: test | |
- name: Setup Database | |
run: | | |
bin/rails db:test:prepare | |
env: | |
RAILS_ENV: test | |
- name: Rubocop Linter | |
run: | | |
bundle exec rubocop | |
env: | |
RAILS_ENV: test | |
- name: ESLint | |
run: | | |
yarn run lint | |
- name: Run Tests | |
run: bundle exec rails test | |
env: | |
RAILS_ENV: test | |
deploy: | |
runs-on: ubuntu-latest | |
needs: test | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Deploy to Heroku | |
env: | |
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }} | |
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }} | |
run: git push https://heroku:[email protected]/$HEROKU_APP_NAME.git origin/master:master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment