Skip to content

Commit

Permalink
Update the generated Docker setup to pull in the version of Crystal y…
Browse files Browse the repository at this point in the history
…ou use, and allow for binding to 0.0.0.0 separately from local running apps. Fixes #786 Fixes #792 Fixes #789 Fixes #781 (#793)
  • Loading branch information
jwoertink authored Mar 11, 2023
1 parent 5e7edb1 commit 13a8ceb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/web_app_skeleton/README.md.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 3 additions & 1 deletion src/web_app_skeleton/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: .
Expand All @@ -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"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:[email protected]:5432/postgres
EXPOSE 5001
EXPOSE 3000
EXPOSE 3001

0 comments on commit 13a8ceb

Please sign in to comment.