Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_build
deps
node_modules
assets/node_modules
.env
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ SECRET_KEY_BASE=
# Destination API keys
FORWARD_WEBHOOK_URL=https://webhook.site/your-test-url
MIXPANEL_TOKEN=

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ crumb-*.tar
## Environment
.env
config/dev.secret.exs
config/runtime.exs

## JS SDKs
/sdk/js/dist
Expand Down
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Dockerfile

# Base image
FROM elixir:1.16-alpine AS build

# Install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force

# Set environment
ENV MIX_ENV=prod \
LANG=C.UTF-8

# Install Node and dependencies for assets
RUN apk add --no-cache build-base git npm

# Create build dir
WORKDIR /app

# Copy files
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get --only prod
RUN mix deps.compile

COPY priv priv
COPY lib lib

# Compile and digest assets
RUN mix compile

# Release the app
RUN mix release

# ─── FINAL IMAGE ────────────────────────────────────────────

FROM alpine:3.18 AS app

RUN apk add --no-cache openssl ncurses-libs libstdc++

WORKDIR /app

COPY --from=build /app/_build/prod/rel/crumb ./

CMD ["bin/crumb", "start"]
5 changes: 3 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ end

if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
System.get_env("DATABASE") ||
raise """
environment variable DATABASE_URL is missing.
environment variable DATABASE is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""

Expand Down Expand Up @@ -81,6 +81,7 @@ if config_env() == :prod do
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
],
server: true,
secret_key_base: secret_key_base

# ## SSL Support
Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
crumb:
build:
context: .
dockerfile: Dockerfile
environment:
DATABASE: ecto://postgres:postgres@db:5432/crumb_prod
USERNAME: postgres
PASSWORD: postgres
SECRET_KEY_BASE: a_very_secret_key_that_you_generate
PHX_HOST: localhost
PORT: 4000
ports:
- "4000:4000"
depends_on:
- db

db:
image: postgres:15
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: crumb_prod
volumes:
- pgdata:/var/lib/postgresql/data

volumes:
pgdata: