Created
April 22, 2020 06:19
-
-
Save wonderphil/70d95f731076493332c8f9149e8727e4 to your computer and use it in GitHub Desktop.
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' | |
services: | |
postgres: | |
image: postgres | |
volumes: | |
- postgres:/var/lib/postgresql/data | |
environment: | |
POSTGRES_PASSWORD: rails | |
POSTGRES_USER: rails | |
ports: | |
- '5434:5432' | |
redis-development: | |
image: 'redis:4.0-alpine' | |
command: redis-server --requirepass rails | |
volumes: | |
- 'redis-development:/data' | |
sidekiq: | |
links: | |
- "postgres:db.local" | |
- redis-development | |
build: . | |
command: sidekiq -C config/sidekiq.yml.erb | |
volumes: | |
- .:/app | |
env_file: | |
- ./docker_env/.env | |
# cable: | |
# depends_on: | |
# - redis | |
# build: . | |
# command: unicorn -p 28080 cable/config.ru | |
# ports: | |
# - '28080:28080' | |
# volumes: | |
# - .:/app | |
# env_file: | |
# - ./docker_env/.env | |
# - ./docker_env/.cable.env | |
web: | |
build: . | |
links: | |
- "postgres:db.local" | |
- redis-development | |
volumes: | |
- .:/app | |
ports: | |
- '8999:8999' | |
env_file: | |
- ./docker_env/.env | |
volumes: | |
postgres: | |
redis-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
ROM ruby:2.6.1 | |
LABEL maintainer="Philip Davies <[email protected]>" | |
# RUN printenv | |
# Install dependencies: | |
# - build-essential: To ensure certain gems can be compiled | |
# - nodejs: Compile assets | |
# - libpq-dev: Communicate with postgres through the postgres gem | |
# because node is shit | |
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs | |
RUN apt-get update && apt-get install -qq -y build-essential libpq-dev --fix-missing --no-install-recommends | |
# Unknow reason this wouldnt install psql client inless it was in its own line :( | |
RUN apt-get install -y postgresql-client-9.6 --fix-missing --no-install-recommends | |
RUN apt-get install -y nano --fix-missing --no-install-recommends | |
RUN apt-get install -y graphviz --fix-missing --no-install-recommends | |
# Set an environment variable to store where the app is installed to inside | |
# of the Docker image. | |
ENV INSTALL_PATH /app | |
RUN mkdir -p $INSTALL_PATH | |
# This sets the context of where commands will be ran in and is documented | |
# on Docker's website extensively. | |
WORKDIR $INSTALL_PATH | |
# Ensure gems are cached and only get updated when they change. This will | |
# drastically increase build times when your gems do not change. | |
# RUN gem update --system | |
RUN gem install bundler | |
COPY Gemfile Gemfile.lock ./ | |
RUN bundle install --binstubs | |
# Copy in the application code from your work station at the current directory | |
# over to the working directory. | |
COPY . . | |
# Provide dummy data to Rails so it can pre-compile assets. | |
#RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]/dbname SECRET_TOKEN=pickasecuretoken assets:precompile | |
# Expose a volume so that nginx will be able to read in assets in production. | |
VOLUME ["$INSTALL_PATH/public"] | |
# The default command that gets ran will be to start the Unicorn server. | |
CMD ["/bin/bash", "./startup.sh"] |
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
#!/bin/bash | |
set -e | |
export DB="$DB_DATABASE"_"$RAILS_ENV" | |
echo $DB | |
if [ "$SKIP_PSQL_AVAILABLE" = "true" ] | |
then | |
echo "SKIPPING CHECK OF DATABASE BEING ALIVE" | |
else | |
echo "Checking if Postgres is alive:" | |
until PGPASSWORD="$DB_PASS" psql -h "$DB_HOST" -U "$DB_USER" -d "$DB" -c '\q'; do | |
>&2 echo "Postgres is unavailable - sleeping" | |
sleep 5 | |
done | |
echo "Postgres is alive!" | |
fi | |
if [ "$SKIP_DB_SETUP" = "true" ] | |
then | |
echo "SKIPPING SETUP DATABASE" | |
else | |
echo "Checking if Database exists:" | |
until PGPASSWORD="$DB_PASS" psql -h "$DB_HOST" -U "$DB_USER" -lqt | cut -d \| -f 1 | grep -qw "$DB"; do | |
echo "Database doesn't exist, will run rake db:setup!" | |
rake db:setup | |
rake db:migrate | |
done | |
echo "Database has now been setup" | |
fi | |
if [ "$SKIP_DB_RESET" = "true" ] | |
then | |
echo "SKIPPING RESETING DATABASE" | |
else | |
echo "db reset" | |
rake db:migrate | |
rake db:reset | |
echo "Database has now been reset" | |
fi | |
if [ "$SKIP_DB_SEED" = "true" ] | |
then | |
echo "SKIPPING SEEDING DATABASE" | |
else | |
echo "db seed" | |
rake db:seed | |
echo "Database has now been seeded" | |
fi | |
if [ "$SKIP_DB_DEPLOY" = "true" ] | |
then | |
echo "SKIPPING DATABASE MIGRATIONS" | |
else | |
echo "Deploying Database migrations" | |
rake db:migrate | |
fi | |
if [ "$SKIP_ASSET_COMPLIE" = "true" ] | |
then | |
echo "SKIPPING ASSET PRE-COMPILE" | |
else | |
echo "RUNNING ASSET PRE-COMPILE" | |
bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:[email protected]/dbname SECRET_TOKEN=pickasecuretoken assets:precompile | |
fi | |
if [ "$SKIP_APP_START" = "true" ] | |
then | |
echo "NOT STARTING APP" | |
else | |
#bundle exec rake assets:precompile | |
echo "Now starting unicorn!" | |
bundle exec unicorn -c config/unicorn.rb | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the basics of getting Ruby in Rails Site running in docker. the startup script is a bit of a mess and could be cleaned up and made to be more simple.