diff --git a/Dockerfile b/Dockerfile index 9fc8d5e51..4eabfe983 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,34 @@ FROM ruby:2.7.4-buster ENV DEBIAN_FRONTEND noninteractive # Install essential Linux packages -RUN apt-get update -qq -RUN apt-get install -y build-essential libpq-dev postgresql-client nodejs imagemagick sudo libxss1 libappindicator1 libindicator7 unzip memcached cmake pkg-config shared-mime-info +RUN apt-get update -qq \ + && apt-get install -y \ + build-essential \ + cmake \ + imagemagick \ + libappindicator1 \ + libindicator7 \ + libpq-dev \ + libxss1 \ + memcached \ + nodejs \ + pkg-config \ + postgresql-client \ + shared-mime-info \ + sudo \ + unzip + +# Install Chromium for E2E integration tests +RUN apt-get update -qq && apt-get install -y chromium # Files created inside the container repect the ownership RUN adduser --shell /bin/bash --disabled-password --gecos "" consul \ - && adduser consul sudo \ - && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + && adduser consul sudo \ + && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN echo 'Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bundle/bin"' > /etc/sudoers.d/secure_path RUN chmod 0440 /etc/sudoers.d/secure_path -COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh - # Define where our application will live inside the image ENV RAILS_ROOT /var/www/consul @@ -27,22 +42,13 @@ WORKDIR $RAILS_ROOT # Use the Gemfiles as Docker cache markers. Always bundle before copying app src. # (the src likely changed and we don't want to invalidate Docker's cache too early) -# http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker/ -COPY Gemfile Gemfile - -COPY Gemfile.lock Gemfile.lock - -COPY Gemfile_custom Gemfile_custom - -# Finish establishing our Ruby environment -RUN bundle install --full-index - -# Install Chromium for E2E integration tests -RUN apt-get update -qq && apt-get install -y chromium +COPY Gemfile* ./ +RUN bundle install # Copy the Rails application into place COPY . . +ENTRYPOINT ["./docker-entrypoint.sh"] # Define the script we want run once the container boots # Use the "exec" form of CMD so our script shuts down gracefully on SIGTERM (i.e. `docker stop`) # CMD [ "config/containers/app_cmd.sh" ] diff --git a/config/boot.rb b/config/boot.rb index 282011619..023130575 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +$stdout.sync = true + ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/docker-compose.yml b/docker-compose.yml index 982d5731a..89b377968 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,16 +10,13 @@ services: - POSTGRES_PASSWORD=$POSTGRES_PASSWORD # persist the database between containers by storing it in a volume volumes: - - docker-example-postgres:/var/lib/postgresql/data + - db_data:/var/lib/postgresql/data # service configuration for our dockerized Rails app app: # use the Dockerfile next to this file build: . - entrypoint: /usr/local/bin/entrypoint.sh - command: bundle exec rails s -p 3000 -b "0.0.0.0" - working_dir: /var/www/consul # rely on the RAILS_ENV value of the host machine # environment: @@ -34,12 +31,10 @@ services: - "3000:3000" # map our application source code, in full, to the application root of our container volumes: - - .:/var/www/consul:delegated - - bundle:/usr/local/bundle:delegated - - "$SSH_AUTH_SOCK:/tmp/agent.sock" + - .:/var/www/consul + - bundle:/usr/local/bundle environment: - POSTGRES_PASSWORD=$POSTGRES_PASSWORD - - SSH_AUTH_SOCK=/tmp/agent.sock volumes: - docker-example-postgres: {} + db_data: {} bundle: {} diff --git a/scripts/entrypoint.sh b/docker-entrypoint.sh similarity index 100% rename from scripts/entrypoint.sh rename to docker-entrypoint.sh