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
108 changes: 108 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# 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-20210902-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.13.3-erlang-25.0.3-debian-bullseye-20210902-slim
#
ARG ELIXIR_VERSION=1.13.3
ARG OTP_VERSION=25.0.3
ARG DEBIAN_VERSION=bullseye-20210902-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 npm webp \
&& 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

# Install / update JavaScript dependencies
RUN npm install --prefix ./assets

COPY priv priv

COPY lib lib

COPY assets assets

# compile assets
RUN mix assets.deploy

COPY assets assets

# 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 webp git npm\
&& 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/api ./


USER nobody


CMD ["/app/bin/server"]


# Appended by flyctl
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
5 changes: 3 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ config :terminator,
config :terminator, Terminator.Repo,
username: "postgres",
password: "postgres",
database: "api_dev",
hostname: "localhost"
database: "terminator",
hostname: "localhost",
port: 5432

if File.exists?(Path.join(Path.dirname(__ENV__.file), "#{Mix.env()}.exs")) do
import_config "#{Mix.env()}.exs"
Expand Down
3 changes: 2 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use Mix.Config
config :terminator, Terminator.Repo,
username: "postgres",
password: "postgres",
database: "api_test",
database: "terminator",
hostname: "localhost",
port: 5432,
pool: Ecto.Adapters.SQL.Sandbox

config :logger,
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3"
services:
database:
image: postgres:14-alpine
container_name: terminator
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=terminator
networks:
- default
ports:
- 5432:5432
volumes:
- data:/var/lib/postgresql/data

networks:
default:
volumes:
data:
28 changes: 28 additions & 0 deletions lib/mix/tasks/install.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Mix.Tasks.Terminator.Install do
@moduledoc """
After configuring your default ecto repo in `:ecto_repos`
Run mix Terminator.install to generates a `setup_terminator_tables` migration,
which Terminator tables, as well as required indexes.
"""

def run(_args) do
source = Path.join(Application.app_dir(:terminator, "/priv/"), "setup_tables.exs")

target =
Path.join(File.cwd!(), "/priv/repo/migrations/#{timestamp()}_setup_terminator_tables.exs")

if !File.dir?(target) do
File.mkdir_p("priv/repo/migrations/")
end

Mix.Generator.create_file(target, EEx.eval_file(source))
end

defp timestamp do
{{y, m, d}, {hh, mm, ss}} = :calendar.universal_time()
"#{y}#{pad(m)}#{pad(d)}#{pad(hh)}#{pad(mm)}#{pad(ss)}"
end

defp pad(i) when i < 10, do: <<?0, ?0 + i>>
defp pad(i), do: to_string(i)
end
1 change: 1 addition & 0 deletions lib/terminator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ defmodule Terminator do
{:error, message: _message} -> "Performer is not authorized"
end
end
end
"""
@spec is_authorized?() :: :ok | {:error, String.t()}
def is_authorized? do
Expand Down
15 changes: 9 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule Terminator.MixProject do
use Mix.Project

@version "0.5.2"
@version "0.5.3"
def project do
[
app: :terminator,
version: @version,
elixir: "~> 1.7",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
deps: deps(),
elixirc_paths: elixirc_paths(Mix.env()),
Expand Down Expand Up @@ -35,15 +35,15 @@ defmodule Terminator.MixProject do
defp deps do
[
{:ecto, "~> 3.0"},
{:ecto_sql, "~> 3.0"},
{:postgrex, "~> 0.14.1"},
{:ecto_sql, "~> 3.6"},
{:postgrex, "~> 0.16"},
{:ex_doc, "~> 0.19", only: :dev, runtime: false},
{:optimus, "~> 0.1.0", only: :dev},
{:mix_test_watch, "~> 0.8", only: :dev, runtime: false},
{:ex_machina, "~> 2.2", only: :test},
{:excoveralls, "~> 0.10", only: :test},
{:mock, "~> 0.3.0", only: :test},
{:inch_ex, only: :docs},
{:inch_ex, ">= 0.0.0", only: :docs},
{:dialyxir, "~> 1.0.0-rc.4", only: [:dev, :test], runtime: false}
]
end
Expand Down Expand Up @@ -90,7 +90,10 @@ defmodule Terminator.MixProject do

defp aliases do
[
test: ["ecto.create", "ecto.migrate", "test"]
c: "compile",
"ecto.setup": ["ecto.create", "ecto.migrate"],
test: ["ecto.create", "ecto.migrate", "test"],
install: ["Terminator.install", "ecto.setup"]
]
end
end
Loading