Parcourir la source

Create a working Dockerfile

Andrew Swistak il y a 6 ans
Parent
commit
3aae66e485
3 fichiers modifiés avec 69 ajouts et 0 suppressions
  1. 6 0
      .dockerignore
  2. 48 0
      Dockerfile
  3. 15 0
      config/database.yml.docker

+ 6 - 0
.dockerignore

@@ -0,0 +1,6 @@
+node_modules
+.git
+public/packs
+public/packs-test
+tmp
+log

+ 48 - 0
Dockerfile

@@ -0,0 +1,48 @@
+FROM ruby:2.6.3-alpine as builder
+
+# Add git to clone Rspec repositories and build-base to compile nokogiri gem
+# Additionally, we need to set timezone information
+RUN apk add --update git build-base postgresql-dev yarn tzdata && \
+      cp /usr/share/zoneinfo/UTC /etc/localtime && \
+      echo "UTC" > /etc/timezone
+
+# Make an app directory, just like Heroku.
+RUN mkdir /app
+WORKDIR /app
+
+# Copying the Gemfile separately allows the image to be cached.
+# These steps are not rerun unless the Gemfile or Gemfile.lock is changed.
+COPY Gemfile Gemfile.lock /app/
+RUN bundle install --jobs 4 --retry 5 --without development test
+
+# Again, copy seperately so we can cache this step.
+COPY package.json yarn.lock /app/
+RUN yarn install
+
+# Copy our app over now
+COPY . /app
+
+# And compile our assets
+RUN rails assets:precompile && \
+      rm -rf node_modules tmp log
+
+FROM ruby:2.6.3-alpine
+
+RUN apk add --update postgresql-dev tzdata && \
+      cp /usr/share/zoneinfo/UTC /etc/localtime && \
+      echo "UTC" > /etc/timezone
+
+# Make an app directory, just like Heroku.
+RUN mkdir /app
+WORKDIR /app
+
+# Grab everything from the builder
+COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
+COPY --from=builder /app/ /app/
+
+# Copy the docker configurations over
+COPY config/database.yml.docker config/database.yml
+
+# Run the server
+EXPOSE 3000
+CMD rails server -p 3000

+ 15 - 0
config/database.yml.docker

@@ -0,0 +1,15 @@
+default: &default
+  adapter: postgresql
+  database: <%= ENV["DATABASE_URL"] %>
+
+development:
+  <<: *default
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+  <<: *default
+
+production:
+  <<: *default