Skip to content

Commit

Permalink
Refine docker-compose.yml: (#799)
Browse files Browse the repository at this point in the history
* Refine docker-compose.yml:

1. use short volume bind syntax.
2. fix postgres volume issue.
   check #798
3. Add POSTGRES_DB env for clarify.
   check luckyframework/lucky#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.
  • Loading branch information
zw963 authored May 14, 2023
1 parent b151d41 commit 161fe88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
23 changes: 10 additions & 13 deletions src/web_app_skeleton/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"
services:
lucky:
build:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -46,3 +41,5 @@ volumes:
postgres_data:
node_modules:
shards_lib:
app_bin:
build_cache:
12 changes: 6 additions & 6 deletions src/web_app_skeleton/docker/dev_entrypoint.sh.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 161fe88

Please sign in to comment.