From 13a8ceb4b6a7300ad96f69b660eca10fa6c10318 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Sat, 11 Mar 2023 14:27:25 -0800 Subject: [PATCH] Update the generated Docker setup to pull in the version of Crystal you use, and allow for binding to 0.0.0.0 separately from local running apps. Fixes #786 Fixes #792 Fixes #789 Fixes #781 (#793) --- src/web_app_skeleton/README.md.ecr | 9 +++++++ src/web_app_skeleton/docker-compose.yml | 4 +++- ...ev_entrypoint.sh => dev_entrypoint.sh.ecr} | 15 ++++-------- ....dockerfile => development.dockerfile.ecr} | 24 +++++++++++-------- 4 files changed, 31 insertions(+), 21 deletions(-) rename src/web_app_skeleton/docker/{dev_entrypoint.sh => dev_entrypoint.sh.ecr} (84%) rename src/web_app_skeleton/docker/{development.dockerfile => development.dockerfile.ecr} (68%) diff --git a/src/web_app_skeleton/README.md.ecr b/src/web_app_skeleton/README.md.ecr index 3585ed14..aebf2a22 100644 --- a/src/web_app_skeleton/README.md.ecr +++ b/src/web_app_skeleton/README.md.ecr @@ -9,6 +9,15 @@ This is a project written using [Lucky](https://luckyframework.org). Enjoy! 1. Run `script/setup` 1. Run `lucky dev` to start the app +### Using Docker for development + +1. [Install Docker](https://docs.docker.com/engine/install/) +1. Run `docker compose up` + +The Docker container will boot all of the necessary components needed to run your Lucky application. +To configure the container, update the `docker-compose.yml` file, and the `docker/development.dockerfile` file. + + ### Learning Lucky Lucky uses the [Crystal](https://crystal-lang.org) programming language. You can learn about Lucky from the [Lucky Guides](https://luckyframework.org/guides/getting-started/why-lucky). diff --git a/src/web_app_skeleton/docker-compose.yml b/src/web_app_skeleton/docker-compose.yml index d65ccb56..7230d019 100644 --- a/src/web_app_skeleton/docker-compose.yml +++ b/src/web_app_skeleton/docker-compose.yml @@ -6,6 +6,7 @@ services: dockerfile: docker/development.dockerfile environment: DATABASE_URL: postgres://lucky:password@postgres:5432/lucky + DEV_HOST: "0.0.0.0" volumes: - type: bind source: . @@ -19,7 +20,8 @@ services: depends_on: - postgres ports: - - 5001:5001 + - 3000:3000 # This is the Lucky Server port + - 3001:3001 # This is the Lucky watcher reload port entrypoint: ["docker/dev_entrypoint.sh"] diff --git a/src/web_app_skeleton/docker/dev_entrypoint.sh b/src/web_app_skeleton/docker/dev_entrypoint.sh.ecr similarity index 84% rename from src/web_app_skeleton/docker/dev_entrypoint.sh rename to src/web_app_skeleton/docker/dev_entrypoint.sh.ecr index 1c0df168..d4d9dbed 100755 --- a/src/web_app_skeleton/docker/dev_entrypoint.sh +++ b/src/web_app_skeleton/docker/dev_entrypoint.sh.ecr @@ -2,9 +2,9 @@ set -euo pipefail -# This is the entrypoint script used for development docker workflows. By -# default it will: -# - Install shards. +# This is the entrypoint script used for development docker workflows. +# By default it will: +# - Install dependencies. # - Run migrations. # - Start the dev server. # It also accepts any commands to be run instead. @@ -27,10 +27,10 @@ if ! [ -d bin ] ; then echo "Creating bin directory" mkdir bin fi - +<%- if browser? -%> echo "Installing npm packages..." yarn install - +<%- end -%> if ! shards check ; then echo "Installing shards..." shards install @@ -44,10 +44,5 @@ if ! psql -d "$DATABASE_URL" -c '\d migrations' > /dev/null ; then lucky db.migrate fi -if [ -S .overmind.sock ] ; then - echo "Removing old overmind socket file..." - rm .overmind.sock -fi - echo "Starting lucky dev server..." exec lucky dev diff --git a/src/web_app_skeleton/docker/development.dockerfile b/src/web_app_skeleton/docker/development.dockerfile.ecr similarity index 68% rename from src/web_app_skeleton/docker/development.dockerfile rename to src/web_app_skeleton/docker/development.dockerfile.ecr index b3fb3abc..5cc00c85 100644 --- a/src/web_app_skeleton/docker/development.dockerfile +++ b/src/web_app_skeleton/docker/development.dockerfile.ecr @@ -1,9 +1,9 @@ -FROM crystallang/crystal:1.4.1 +FROM crystallang/crystal:<%= Crystal::VERSION %> # Install utilities required to make this Dockerfile run RUN apt-get update && \ apt-get install -y wget - +<%- if browser? -%> # Add the nodesource ppa to apt. Update this to change the nodejs version. RUN wget https://deb.nodesource.com/setup_16.x -O- | bash @@ -20,21 +20,25 @@ RUN apt-get update && \ # browser app. # - Mix is the default asset compiler. RUN npm install -g yarn mix +<%- else -%> -# Installs overmind, not needed if nox is the process manager. -RUN wget https://github.com/DarthSim/overmind/releases/download/v2.2.2/overmind-v2.2.2-linux-amd64.gz && \ - gunzip overmind-v2.2.2-linux-amd64.gz && \ - mv overmind-v2.2.2-linux-amd64 /usr/bin/overmind && \ - chmod +x /usr/bin/overmind +# Apt installs: +# - Postgres cli tools are required for lucky-cli. +# - tmux is required for the Overmind process manager. +RUN apt-get update && \ + apt-get install -y postgresql-client tmux && \ + rm -rf /var/lib/apt/lists/* +<%- end -%> -# Install lucky cli, TODO: fetch current lucky version from source code. +# Install lucky cli WORKDIR /lucky/cli RUN git clone https://github.com/luckyframework/lucky_cli . && \ - git checkout v1.0.0-rc1 && \ + git checkout v<%= LuckyCli::VERSION %> && \ shards build --without-development && \ cp bin/lucky /usr/bin WORKDIR /app ENV DATABASE_URL=postgres://postgres:postgres@host.docker.internal:5432/postgres -EXPOSE 5001 +EXPOSE 3000 +EXPOSE 3001