Browse Source

DRY up docker-compose.yml

Andrew Swistak 6 năm trước cách đây
mục cha
commit
fdf8c44cc0
2 tập tin đã thay đổi với 37 bổ sung10 xóa
  1. 6 0
      config/docker/rails-dev-entrypoint.sh
  2. 31 10
      docker-compose.yml

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

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

+ 31 - 10
docker-compose.yml

@@ -1,27 +1,46 @@
 version: "3.7"
+x-app:
+  &app
+  build:
+    context: .
+    target: dev
+  entrypoint: config/docker/rails-dev-entrypoint.sh
+  volumes:
+    - type: bind
+      source: .
+      target: /app
+    - gems:/usr/local/bundle
+    - node_modules:/app/node_modules
+  working_dir: /app
+
 services:
   web:
-    build:
-      context: .
-      target: dev
+    <<: *app
     command: rails server -p 3000 -b 0.0.0.0
     depends_on:
       - db
+      - webpack_dev_server
     environment:
       - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
+      - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
     ports:
       - ${WEB_HOST_PORT}:3000
-    volumes:
-      - type: bind
-        source: .
-        target: /app
-    working_dir: /app
+
+  webpack_dev_server:
+    <<: *app
+    command: bin/webpack-dev-server --public 0.0.0.0
+    entrypoint: config/docker/rails-dev-entrypoint.sh
+    environment:
+      - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
+    ports:
+      - 3035:3035
 
   db:
+    image: postgres:11.2-alpine
     environment:
-      - POSTGRES_USER
+      - POSTGRES_DB
       - POSTGRES_PASSWORD
-    image: postgres:11.2-alpine
+      - POSTGRES_USER
     ports:
       - ${DB_HOST_PORT}:5432
     volumes:
@@ -29,3 +48,5 @@ services:
 
 volumes:
   postgres-persisted-volume:
+  gems:
+  node_modules: