Skip to content

Commit

Permalink
Replace distillery with mix release
Browse files Browse the repository at this point in the history
  • Loading branch information
marteinn committed Feb 25, 2024
1 parent d4fa236 commit d435baa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 113 deletions.
10 changes: 9 additions & 1 deletion src/_templates/config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use Mix.Config
use Config

config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: ExampleApp.Finch

# Disable Swoosh Local Memory Storage
config :swoosh, local: false

# Do not print debug messages in production
config :logger, level: :info

# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
Expand Down
85 changes: 0 additions & 85 deletions src/_templates/lib/example_app/release_tasks.exs

This file was deleted.

25 changes: 25 additions & 0 deletions src/_templates/lib/release.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# From: https://hexdocs.pm/phoenix/releases.html
defmodule ExampleApp.Release do
@app :example_app

def migrate do
load_app()

for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end

def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end

defp repos do
Application.fetch_env!(@app, :ecto_repos)
end

defp load_app do
Application.load(@app)
end
end
1 change: 0 additions & 1 deletion src/_templates/rel/commands/migrate.sh

This file was deleted.

9 changes: 0 additions & 9 deletions src/_templates/rel/config.part.exs

This file was deleted.

25 changes: 8 additions & 17 deletions src/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ scaffold_project() {
SCAFFOLD_APP_PC_NAME=$(echo $SCAFFOLD_APP_NAME | sed -r 's/(^|_)([a-z])/\U\2/g')

echo "Generating app"
mix phx.new $SCAFFOLD_APP_NAME --no-assets
mix phx.new $SCAFFOLD_APP_NAME --no-assets --no-install --adapter=bandit

echo "Move app to src"
cp -Rp ./$SCAFFOLD_APP_NAME/. .
Expand All @@ -36,10 +36,9 @@ scaffold_project() {
sed -i -e "s/hostname:.*/hostname: System.get_env(\"DATABASE_HOST\"),/" config/test.exs
sed -i '/hostname:.*/a\ \ port: System.get_env("DATABASE_PORT") |> String.to_integer,' config/test.exs

echo "Installing distillery"
sed -i '/plug_cowboy/c \ \ \ \ \ \ {:plug_cowboy,\ "~> 2.0"},' mix.exs
sed -i '/plug_cowboy/a \ \ \ \ \ \ {:distillery,\ "~> 2.0"},' mix.exs
sed -i '/distillery/a \ \ \ \ \ \ {:toml,\ "~> 0.3"}' mix.exs
echo "Adding release"
sed -i '/bandit/c \ \ \ \ \ \ {:bandit,\ "~> 1.2"},' mix.exs
sed -i '/bandit/a \ \ \ \ \ \ {:toml,\ "~> 0.7"},' mix.exs

rm config/prod.exs
cp _templates/config/prod.exs config/prod.exs
Expand All @@ -48,20 +47,12 @@ scaffold_project() {

mix deps.get
mix release.init
cp _templates/lib/release.ex lib/release.ex

echo "Copy commands"
mkdir -p rel/commands
cp _templates/rel/commands/migrate.sh rel/commands/migrate.sh
sed -i -e "s/ExampleApp/$SCAFFOLD_APP_PC_NAME/" rel/commands/migrate.sh
sed -i '/deps()/c \ \ \ \ \ \ deps: deps(),' mix.exs
sed -i '/deps()/a \ \ \ \ \ \ releases: [ realtime_api: [ include_executables_for: [:unix], applications: [runtime_tools: :permanent], steps: [:assemble, :tar], config_providers: [ {Toml.Provider, path: "config.toml"} ] ] ],' mix.exs

echo "Add commands to rel/config.exs"
echo "$(cat _templates/rel/config.part.exs)" >> rel/config.exs
sed -i -e "s/example_app/$SCAFFOLD_APP_NAME/" rel/config.exs
sed -i -e "s/ExampleApp/$SCAFFOLD_APP_PC_NAME/" rel/config.exs

echo "Configure toml"
sed -i '/environment\ :prod/a \ \ set config_providers: [ {Toml.Provider, [path: "${RELEASE_ROOT_DIR}/config.toml"]} ]' rel/config.exs
sed -i '/environment\ :prod/a \ \ set overlays: [ {:copy, "config/defaults.toml", "config.toml"} ]' rel/config.exs
mix format

cp _templates/config/defaults.toml config/defaults.toml
sed -i -e "s/example_app/$SCAFFOLD_APP_NAME/" config/defaults.toml
Expand Down

0 comments on commit d435baa

Please sign in to comment.