From ccb8b47e6e6d30826d454dd82fcc3f88f12ba343 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 9 May 2020 10:16:30 +0200 Subject: [PATCH] Improve Docker setup --- .docker/entrypoint.sh | 8 ++++++++ .docker/ruby/Dockerfile | 38 +++++++++++++++++--------------------- docker-compose.yml | 9 ++++----- 3 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 .docker/entrypoint.sh diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100644 index 00000000..eb40a5ea --- /dev/null +++ b/.docker/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +# Remove a potentially pre-existing server.pid for Rails. +rm -f /app/tmp/pids/server.pid + +# Then exec the container's main process (what's set as CMD in the Dockerfile). +exec "$@" \ No newline at end of file diff --git a/.docker/ruby/Dockerfile b/.docker/ruby/Dockerfile index 0b7cdad3..a6775f9c 100644 --- a/.docker/ruby/Dockerfile +++ b/.docker/ruby/Dockerfile @@ -1,30 +1,26 @@ FROM ruby:2.7 -RUN apt-get update -qq && apt-get install -y build-essential +RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - -# for postgres -RUN apt-get install -y libpq-dev +RUN apt-get update -qq && \ + apt-get install -y --no-install-recommends build-essential \ + libpq-dev postgresql-client \ + libxml2-dev libxslt1-dev \ + libmagickwand-dev imagemagick \ + nodejs -# for nokogiri -RUN apt-get install -y libxml2-dev libxslt1-dev +RUN rm -rf /var/lib/apt/lists/* -# for images -RUN apt-get install -y libmagickwand-dev imagemagick +RUN mkdir /app +WORKDIR /app -# for a JS runtime -RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - -RUN apt-get install -y nodejs - -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - postgresql-client \ - && rm -rf /var/lib/apt/lists/* - -ENV APP_HOME /app -RUN mkdir $APP_HOME -WORKDIR $APP_HOME - -ADD Gemfile* $APP_HOME/ +ADD Gemfile* /app/ RUN bundle install +COPY . /app +COPY .docker/entrypoint.sh /usr/bin/ +RUN chmod +x /usr/bin/entrypoint.sh +ENTRYPOINT ["entrypoint.sh"] EXPOSE 3000 + +CMD ["rails", "server", "-b", "0.0.0.0"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 659d7afe..85e5d8b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,11 @@ version: "3.7" services: web: - build: - context: . + build: + context: . dockerfile: .docker/ruby/Dockerfile - command: - ruby bin/rails server --port 3000 --binding 0.0.0.0 - links: + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" + depends_on: - postgres - redis environment: