Last active
March 4, 2025 21:05
-
-
Save timm-oh/74b9083b9f37849f4b4b829822875776 to your computer and use it in GitHub Desktop.
Elixir phoenix docker setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:logger.debug(""" | |
> `docker attach $(docker compose ps web -q)` to attach IEx.pry() | |
> Ctrl + P + Q to detach from the container terminal | |
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default stuff | |
config :chatter, ChatterWeb.Endpoint, | |
# Binding to loopback ipv4 address prevents access from other machines. | |
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines. | |
http: [ip: {0, 0, 0, 0}, port: 4000], | |
# default stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
web: | |
image: chit_chat-dev:1.0.1 | |
build: | |
context: . | |
dockerfile: Dockerfile | |
target: builder | |
args: | |
MIX_ENV: ${MIX_ENV:-dev} | |
environment: | |
DATABASE_URL: postgres://postgres:postgres@db:5432/chit_chat_dev | |
SECRET_KEY_BASE: cQ3VLNX5nkxRgQC4idmVfHYnzf51KkFFp4ACZuIBT61in2cWWbWpkEYDx2RQiPFz | |
ports: | |
- '4000:4000' | |
depends_on: | |
- db | |
volumes: | |
- .:/app:cached | |
command: iex -S mix phx.server | |
stdin_open: true | |
tty: true | |
db: | |
image: postgres:17-alpine | |
environment: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USER: postgres | |
POSTGRES_DB: chit_chat_dev | |
ports: | |
- 5432 | |
volumes: | |
- pgdata:/var/lib/postgresql/data | |
healthcheck: | |
test: pg_isready -U postgres -h 127.0.0.1 | |
interval: 5s | |
volumes: | |
pgdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG DEBIAN_VERSION=bookworm-20250203-slim | |
ARG BUILDER_IMAGE="hexpm/elixir:1.18.2-erlang-27.2.4-debian-${DEBIAN_VERSION}" | |
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" | |
FROM $BUILDER_IMAGE as builder | |
# Build Args | |
ARG PHOENIX_VERSION=1.7.20 | |
ARG MIX_ENV | |
ENV MIX_ENV=${MIX_ENV:-prod} | |
ARG DEBIAN_FRONTEND="noninteractive" | |
# ARG NODEJS_VERSION=16.x | |
# Apt | |
RUN apt-get update -qq \ | |
&& apt-get -yq dist-upgrade \ | |
&& apt-get install -yq --no-install-recommends \ | |
apt-utils \ | |
build-essential \ | |
git \ | |
postgresql-client-15 \ | |
inotify-tools \ | |
&& apt-get clean \ | |
&& rm -rf /var/cache/apt/archives/* \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | |
&& truncate -s 0 /var/log/*log | |
# Nodejs | |
# RUN curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION} | bash | |
# RUN apt-get install -y nodejs | |
RUN mix local.hex --force && \ | |
mix archive.install --force hex phx_new $PHOENIX_VERSION && \ | |
mix local.rebar --force | |
# App Directory | |
WORKDIR /app | |
COPY mix.* ./ | |
RUN mix deps.get --only $MIX_ENV | |
RUN mkdir config | |
COPY config/config.exs config/$MIX_ENV.exs config/ | |
RUN mix deps.compile | |
COPY . ./ | |
RUN if [ "${MIX_ENV}" = "prod" ]; then \ | |
mix compile && \ | |
MIX_ENV=prod mix assets.deploy && \ | |
mix release ; fi | |
COPY entrypoint.sh /usr/bin/ | |
ENTRYPOINT ["entrypoint.sh"] | |
CMD ["mix phx.server"] | |
FROM $RUNNER_IMAGE as app | |
ARG DEBIAN_FRONTEND="noninteractive" | |
ENV LANG=en_US.UTF-8 \ | |
LANGUAGE=en_US:en \ | |
LC_ALL=en_US.UTF-8 \ | |
MIX_ENV=prod | |
RUN apt-get update -qq \ | |
&& apt-get install -yq --no-install-recommends \ | |
libstdc++6 openssl libncurses5 locales \ | |
&& apt-get clean \ | |
&& rm -rf /var/cache/apt/archives/* \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | |
&& truncate -s 0 /var/log/*log | |
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen | |
WORKDIR /app | |
COPY --from=builder /app/_build/prod/rel/chit_chat ./ | |
COPY --from=builder /app/rel ./rel | |
CMD ["/app/bin/server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default stuff | |
database_url = | |
System.get_env("DATABASE_URL") || | |
raise """ | |
environment variable DATABASE_URL is missing. | |
For example: ecto://USER:PASS@HOST/DATABASE | |
""" | |
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: [] | |
config :mocha, Mocha.Repo, | |
# ssl: true, | |
url: database_url, | |
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), | |
socket_options: maybe_ipv6 | |
if config_env() == :prod do | |
# default stuff | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# default stuff | |
config :pay, Chatter.Repo, | |
pool: Ecto.Adapters.SQL.Sandbox, | |
pool_size: 10 | |
# default stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment