Skip to content

Commit

Permalink
rename project from "img" to "app" #51
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed May 26, 2023
1 parent c95bf01 commit 3dbf4a8
Show file tree
Hide file tree
Showing 43 changed files with 395 additions and 133 deletions.
45 changes: 45 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This file excludes paths from the Docker build context.
#
# By default, Docker's build context includes all files (and folders) in the
# current directory. Even if a file isn't copied into the container it is still sent to
# the Docker daemon.
#
# There are multiple reasons to exclude files from the build context:
#
# 1. Prevent nested folders from being copied into the container (ex: exclude
# /assets/node_modules when copying /assets)
# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc)
# 3. Avoid sending files containing sensitive information
#
# More information on using .dockerignore is available here:
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

.dockerignore

# Ignore git, but keep git HEAD and refs to access current commit hash if needed:
#
# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat
# d0b8727759e1e0e7aa3d41707d12376e373d5ecc
.git
!.git/HEAD
!.git/refs

# Common development/test artifacts
/cover/
/doc/
/test/
/tmp/
.elixir_ls

# Mix artifacts
/_build/
/deps/
*.ez

# Generated on crash by the VM
erl_crash.dump

# Static artifacts - These should be fetched and built inside the Docker image
/assets/node_modules/
/priv/static/assets/
/priv/static/cache_manifest.json
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ erl_crash.dump
/tmp/

# Ignore package tarball (built via "mix hex.build").
img-*.tar
app-*.tar

# Ignore assets that are produced by build tools.
/priv/static/assets/
Expand All @@ -33,4 +33,5 @@ img-*.tar

# In case you use Node.js/npm, you want to ignore these.
npm-debug.log
/assets/node_modules/
/assets/node_modules/

95 changes: 95 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
# instead of Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
# This file is based on these images:
#
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20230109-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.14.3-erlang-25.2.2-debian-bullseye-20230109-slim
#
ARG ELIXIR_VERSION=1.14.3
ARG OTP_VERSION=25.2.2
ARG DEBIAN_VERSION=bullseye-20230109-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

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

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv

COPY lib lib

COPY assets assets

# compile assets
RUN mix assets.deploy

# Compile the release
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/

COPY rel rel
RUN mix release

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

WORKDIR "/app"
RUN chown nobody /app

# set runner ENV
ENV MIX_ENV="prod"

# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/app ./

USER nobody

CMD ["/app/bin/server"]

# Appended by flyctl
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Img
# App

To start your Phoenix server:

Expand Down
85 changes: 85 additions & 0 deletions _mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
defmodule Img.MixProject do
use Mix.Project

def project do
[
app: :img,
version: "1.0.0",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
c: :test,
coveralls: :test,
"coveralls.detail": :test,
"coveralls.json": :test,
"coveralls.post": :test,
"coveralls.html": :test,
t: :test
]
]
end

# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
[
mod: {Img.Application, []},
extra_applications: [:logger, :runtime_tools]
]
end

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.7.2"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.18.16"},
{:floki, ">= 0.30.0", only: :test},
{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_poller, "~> 1.0"},
{:jason, "~> 1.2"},
{:plug_cowboy, "~> 2.5"},

# Track test coverage: github.com/parroty/excoveralls
{:excoveralls, "~> 0.15", only: [:test, :dev]},

]
end

# Aliases are shortcuts or tasks specific to the current project.
# For example, to install project dependencies and perform other setup tasks, run:
#
# $ mix setup
#
# See the documentation for `Mix` for more info on aliases.
defp aliases do
[
setup: ["deps.get", "ecto.setup", "assets.setup"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
"assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"],
c: ["coveralls.html"],
s: ["phx.server"],
t: ["test"]
]
end
end
12 changes: 6 additions & 6 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
# General application configuration
import Config

config :img,
ecto_repos: [Img.Repo]
config :app,
ecto_repos: [App.Repo]

# Configures the endpoint
config :img, ImgWeb.Endpoint,
config :app, AppWeb.Endpoint,
url: [host: "localhost"],
render_errors: [
formats: [html: ImgWeb.ErrorHTML, json: ImgWeb.ErrorJSON],
formats: [html: AppWeb.ErrorHTML, json: AppWeb.ErrorJSON],
layout: false
],
pubsub_server: Img.PubSub,
live_view: [signing_salt: "AQ9KYD+o"]
pubsub_server: App.PubSub,
live_view: [signing_salt: "nMHdEa6r"]

# Configure esbuild (the version is required)
config :esbuild,
Expand Down
14 changes: 7 additions & 7 deletions config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Config

# Configure your database
config :img, Img.Repo,
config :app, App.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "img_dev",
database: "app_dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
Expand All @@ -16,14 +16,14 @@ config :img, Img.Repo,
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with esbuild to bundle .js and .css sources.
config :img, ImgWeb.Endpoint,
config :app, AppWeb.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: {127, 0, 0, 1}, port: 4000],
check_origin: false,
code_reloader: true,
debug_errors: true,
secret_key_base: "0ho7Rf3luf5JIO1DbahqgeYbiEq1Bjf8ycvSfyXGRLQ1V1i8xK2U30A36LvlRPOK",
secret_key_base: "yK9K0maMhGbQ1FHCpq+Rv6pV6vXpaswkmH48iYy5FVu2CBugSr2JOB1OwlWUEXMj",
watchers: [
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
Expand Down Expand Up @@ -53,16 +53,16 @@ config :img, ImgWeb.Endpoint,
# different ports.

# Watch static and templates for browser reloading.
config :img, ImgWeb.Endpoint,
config :app, AppWeb.Endpoint,
live_reload: [
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"lib/img_web/(controllers|live|components)/.*(ex|heex)$"
~r"lib/app_web/(controllers|live|components)/.*(ex|heex)$"
]
]

# Enable dev routes for dashboard and mailbox
config :img, dev_routes: true
config :app, dev_routes: true

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Config
# manifest is generated by the `mix assets.deploy` task,
# which you should run after static files are built and
# before starting your production server.
config :img, ImgWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
config :app, AppWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production
config :logger, level: :info
Expand Down
12 changes: 6 additions & 6 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import Config
# If you use `mix release`, you need to explicitly enable the server
# by passing the PHX_SERVER=true when you start it:
#
# PHX_SERVER=true bin/img start
# PHX_SERVER=true bin/app start
#
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
# script that automatically sets the env var above.
if System.get_env("PHX_SERVER") do
config :img, ImgWeb.Endpoint, server: true
config :app, AppWeb.Endpoint, server: true
end

if config_env() == :prod do
Expand All @@ -30,7 +30,7 @@ if config_env() == :prod do

maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []

config :img, Img.Repo,
config :app, App.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
Expand All @@ -51,7 +51,7 @@ if config_env() == :prod do
host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")

config :img, ImgWeb.Endpoint,
config :app, AppWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
Expand All @@ -68,7 +68,7 @@ if config_env() == :prod do
# To get SSL working, you will need to add the `https` key
# to your endpoint configuration:
#
# config :img, ImgWeb.Endpoint,
# config :app, AppWeb.Endpoint,
# https: [
# ...,
# port: 443,
Expand All @@ -90,7 +90,7 @@ if config_env() == :prod do
# We also recommend setting `force_ssl` in your endpoint, ensuring
# no data is ever sent via http, always redirecting to https:
#
# config :img, ImgWeb.Endpoint,
# config :app, AppWeb.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.
Expand Down
Loading

0 comments on commit 3dbf4a8

Please sign in to comment.