From 161fe88468b6d5094874b93ef46c732a1dbdf591 Mon Sep 17 00:00:00 2001 From: "Billy.Zheng" Date: Mon, 15 May 2023 04:40:50 +0800 Subject: [PATCH] Refine docker-compose.yml: (#799) * Refine docker-compose.yml: 1. use short volume bind syntax. 2. fix postgres volume issue. check https://github.com/luckyframework/lucky_cli/issues/798 3. Add POSTGRES_DB env for clarify. check https://github.com/luckyframework/lucky/discussions/1791 4. Add crystal build cache into volume for better performance. * Refine dev_entrypoint.sh * Add shards cache as volume * Add app/bin into volume for isolation the binaries created from container with locals. --- src/web_app_skeleton/docker-compose.yml | 23 ++++++++----------- .../docker/dev_entrypoint.sh.ecr | 12 +++++----- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/web_app_skeleton/docker-compose.yml b/src/web_app_skeleton/docker-compose.yml index 7230d019..d00779db 100644 --- a/src/web_app_skeleton/docker-compose.yml +++ b/src/web_app_skeleton/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" services: lucky: build: @@ -8,15 +8,11 @@ services: DATABASE_URL: postgres://lucky:password@postgres:5432/lucky DEV_HOST: "0.0.0.0" volumes: - - type: bind - source: . - target: /app - - type: volume - source: node_modules - target: /app/node_modules - - type: volume - source: shards_lib - target: /app/lib + - .:/app + - node_modules:/app/node_modules + - shards_lib:/app/lib + - app_bin:/app/bin + - build_cache:/root/.cache depends_on: - postgres ports: @@ -30,10 +26,9 @@ services: environment: POSTGRES_USER: lucky POSTGRES_PASSWORD: password + POSTGRES_DB: lucky volumes: - - type: volume - source: postgres_data - target: /var/lib/postgresql + - postgres_data:/var/lib/postgresql/data ports: # The postgres database container is exposed on the host at port 6543 to # allow connecting directly to it with postgres clients. The port differs @@ -46,3 +41,5 @@ volumes: postgres_data: node_modules: shards_lib: + app_bin: + build_cache: diff --git a/src/web_app_skeleton/docker/dev_entrypoint.sh.ecr b/src/web_app_skeleton/docker/dev_entrypoint.sh.ecr index d4d9dbed..94d15ffd 100755 --- a/src/web_app_skeleton/docker/dev_entrypoint.sh.ecr +++ b/src/web_app_skeleton/docker/dev_entrypoint.sh.ecr @@ -24,25 +24,25 @@ case ${1:-} in esac if ! [ -d bin ] ; then - echo "Creating bin directory" + echo 'Creating bin directory' mkdir bin fi <%- if browser? -%> -echo "Installing npm packages..." +echo 'Installing npm packages...' yarn install <%- end -%> if ! shards check ; then - echo "Installing shards..." + echo 'Installing shards...' shards install fi -echo "Waiting for postgres to be available..." +echo 'Waiting for postgres to be available...' ./docker/wait-for-it.sh -q postgres:5432 if ! psql -d "$DATABASE_URL" -c '\d migrations' > /dev/null ; then - echo "Finishing database setup..." + echo 'Finishing database setup...' lucky db.migrate fi -echo "Starting lucky dev server..." +echo 'Starting lucky dev server...' exec lucky dev