Parcourir la source

Set up docker-compose for development quickstart

Andrew Swistak il y a 6 ans
Parent
commit
9d82681391
4 fichiers modifiés avec 55 ajouts et 5 suppressions
  1. 12 0
      .env.template
  2. 4 5
      Dockerfile
  3. 6 0
      config/docker/rails-entrypoint.sh
  4. 33 0
      docker-compose.yml

+ 12 - 0
.env.template

@@ -0,0 +1,12 @@
+PKPARSE_URL=
+
+# Password for postgres. The default password for the postgres container is
+# simply 'postgres'. Please change this to something more unique. Avoid unsafe
+# URL characters (`@`, `:`, `/`, etc)
+POSTGRES_PASSWORD=postgres
+
+# Port which Rails is exposed on
+WEB_HOST_PORT=3000
+
+# Port which Postgres is exposed on
+DB_HOST_PORT=5432

+ 4 - 5
Dockerfile

@@ -22,9 +22,11 @@ RUN yarn install
 # Copy our app over now
 COPY . /app
 
+# Copy the docker configurations over
+COPY config/database.yml.docker config/database.yml
+
 # And compile our assets
-RUN rails assets:precompile && \
-      rm -rf node_modules tmp log
+RUN rails assets:precompile
 
 FROM ruby:2.6.3-alpine
 
@@ -40,9 +42,6 @@ WORKDIR /app
 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

+ 6 - 0
config/docker/rails-entrypoint.sh

@@ -0,0 +1,6 @@
+#!/bin/sh
+
+bundle check || bundle install
+yarn check || yarn install --check-files
+
+exec "$@"

+ 33 - 0
docker-compose.yml

@@ -0,0 +1,33 @@
+version: "3.7"
+services:
+  web:
+    build:
+      context: .
+      target: builder
+    # Even though CMD is defined in the Dockerfile, we need to provide a CMD here
+    # because we are using a compose entrypoint. See https://github.com/docker/compose/issues/3140
+    command: rails server -p 3000 -b 0.0.0.0
+    depends_on:
+      - db
+    entrypoint: config/docker/rails-entrypoint.sh
+    environment:
+      - DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@db:5432/pokemon_trade_dev
+    ports:
+      - ${WEB_HOST_PORT}:3000
+    volumes:
+      - type: bind
+        source: .
+        target: /app
+    working_dir: /app
+
+  db:
+    environment:
+      - POSTGRES_PASSWORD
+    image: postgres:11.2-alpine
+    ports:
+      - ${DB_HOST_PORT}:5432
+    volumes:
+      - postgres-persisted-volume:/var/lib/postgresql/data
+
+volumes:
+  postgres-persisted-volume: