Skip to content

Instantly share code, notes, and snippets.

@tubbo
Last active November 26, 2018 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tubbo/b1b60c198f831d2f23c59c6b4358ba0c to your computer and use it in GitHub Desktop.
Save tubbo/b1b60c198f831d2f23c59c6b4358ba0c to your computer and use it in GitHub Desktop.
docker compose setup for soundstorm
#
# Development services configuration. Installs various external services
# used to aid developers and sets up build caches for application
# dependencies.
#
version: '3'
services:
# In development, Mailcatcher is used to receive and process emails.
# It can be accessed at http://localhost:1080.
mailcatcher:
image: schickling/mailcatcher
ports:
- '1080:1080'
# Cache application dependencies and use the local database in
# development
web:
build: .
ports:
- "${RAILS_PORT}:3000"
links:
- mailcatcher
volumes:
- .:/srv
- node_modules:/node_modules
- bundle:/gems
environment:
- DATABASE_HOST=db
volumes:
bundle:
node_modules:
#
# Production services configuration for Soundstorm. Adds the `redis` and
# `sidekiq` services, and disables `mailcatcher`. All services in
# production are created using released images from the registry, which
# have been ostensibly verified as working.
version: '3'
services:
# Redis stores the ephemeral Rails/HTTP cache and Sidekiq job queue
redis:
image: redis
volumes:
- redis:/data
# Speed up application deployment by launching an image rather than
# building a full container, such as in development. Dependencies are
# also preloaded onto the image and the entrypoint script for
# installing deps is disabled. Migrations still occur in the
# ENTRYPOINT, however, so as not to depend the entire app on the
# database being fully up.
web:
build:
context: .
args:
- RAILS_ENV=production
image: tubbo/soundstorm
volumes:
- code:/srv
expose:
- 3000
depends_on:
- db
- redis
env_file:
- .env.production
- .env.secrets
# Background job processor for the application, running background
# jobs within the Rails context. This container will always use the
# same image as +web+, ensuring that both services are launched with
# the same codebase.
sidekiq:
image: tubbo/soundstorm
command: bin/bundle exec sidekiq -C config/sidekiq.yml
depends_on:
- db
- redis
- web
env_file:
- .env.production
- .env.secrets
nginx:
image: nginx
ports:
- "443:443"
- "80:80"
volumes:
- code:/srv
- ./config/nginx.conf:/etc/nginx/sites.d/soundstorm.conf
- ./config/ssl:/etc/ssl
volumes:
redis:
code:
#
# Base services configuration for Soundstorm. This describes the bare
# minimum containers that are used to construct any Soundstorm
# environment.
#
version: '3'
services:
# PostgreSQL is the primary persistent data store for the application.
db:
image: postgres
volumes:
- postgresql:/var/lib/postgresql/data
# The "majestic monolith" that powers Soundstorm, a Rails application
# serving HTML (for the most part) and containing all of the logic
# needed to run a Soundstorm instance.
web:
command: bin/rails server -p 3000 -b '0.0.0.0'
depends_on:
- db
volumes:
- yarn_cache:/root/.yarn
environment:
- BUNDLE_APP_CONFIG=/srv/.bundle
- SOUNDSTORM_ADMIN_USERNAME
- SOUNDSTORM_ADMIN_EMAIL
- SOUNDSTORM_ADMIN_PASSWORD
volumes:
postgresql:
yarn_cache:
#
# Docker image build script for Soundstorm
#
# Use latest Ruby
FROM ruby:2.5.3
# Install system dependencies
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update -qq \
&& apt-get install -y build-essential libpq-dev nodejs yarn
# Set the $RAILS_ENV externally, defaults to "development"
ARG RAILS_ENV
# Set up environment
ENV BUNDLE_PATH=/gems \
BUNDLE_BIN=/gems/bin \
APP_PATH=/srv \
RAILS_ENV=$RAILS_ENV \
PATH=/usr/local/bundle/bin:/srv/bin:/gems/bin:$PATH
# Copy in application code
RUN mkdir -p $APP_PATH
WORKDIR $APP_PATH
COPY . $APP_PATH
# Install application dependencies.
RUN if [ "$RAILS_ENV" = "production" ]; then \
./bin/bundle --path=/gems && ./bin/yarn --module-path=/node_modules; \
fi
ENTRYPOINT ["sh", "bin/entrypoint.sh"]
#!/bin/bash
#
# ENTRYPOINT script for Docker containers. This script is run prior to
# any command `exec`-ed or `run` in a container, and ensures the
# database schema and all dependencies are up-to-date.
if [ "$RAILS_ENV" != "production" ]; then
echo "Reconciling dependencies..."
./bin/bundle --path=/gems --quiet
./bin/yarn --module-path=/node_modules --silent
fi
echo "Updating database schema..."
./bin/rails db:update
echo "Running command \`$*\`..."
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment