diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index a9288af6c..e3bec72ff 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -7,7 +7,7 @@ on: jobs: test: name: Test - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - uses: erlef/setup-beam@v1 @@ -28,14 +28,14 @@ jobs: uses: actions/cache@v3 with: path: deps - key: ${{ runner.os }}-mix-6-${{ hashFiles('**/mix.lock') }} - restore-keys: ${{ runner.os }}-mix-6 + key: ${{ runner.os }}-mix-7-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-7 - name: Restore _build uses: actions/cache@v3 with: path: _build - key: ${{ runner.os }}-mix-6-${{ hashFiles('**/mix.lock') }} - restore-keys: ${{ runner.os }}-mix-6 + key: ${{ runner.os }}-mix-7-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-7 - run: mix deps.get - run: mix test - uses: 8398a7/action-slack@v3 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ebb9acf62..9afea66b2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -125,7 +125,7 @@ jobs: sarif_file: 'trivy-results.sarif' test: name: Test - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - uses: erlef/setup-beam@v1 @@ -146,14 +146,14 @@ jobs: uses: actions/cache@v3 with: path: deps - key: ${{ runner.os }}-mix-6-${{ hashFiles('**/mix.lock') }} - restore-keys: ${{ runner.os }}-mix-6 + key: ${{ runner.os }}-mix-7-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-7 - name: Restore _build uses: actions/cache@v3 with: path: _build - key: ${{ runner.os }}-mix-6-${{ hashFiles('**/mix.lock') }} - restore-keys: ${{ runner.os }}-mix-6 + key: ${{ runner.os }}-mix-7-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix-7 - run: mix deps.get - run: mix test - run: mix coveralls.html diff --git a/.tool-versions b/.tool-versions index 969f79b0f..6ea75de46 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 24.3.4.8 -elixir 1.12.3 +erlang 25.1.2 +elixir 1.13.4 diff --git a/Dockerfile b/Dockerfile index 0719927cc..6ad0cc14c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM bitwalker/alpine-elixir:1.12.3 AS builder +FROM bitwalker/alpine-elixir:1.13.4 AS builder # The following are build arguments used to change variable parts of the image. # The name of your application/release (required) @@ -31,11 +31,8 @@ RUN mix do deps.get, compile RUN \ mkdir -p /opt/built && \ - mix distillery.release --name ${APP_NAME} && \ - cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/*/${APP_NAME}.tar.gz /opt/built && \ - cd /opt/built && \ - tar -xzf ${APP_NAME}.tar.gz && \ - rm ${APP_NAME}.tar.gz + mix release ${APP_NAME} && \ + mv _build/${MIX_ENV}/rel/${APP_NAME}/* /opt/built FROM alpine:3.17.0 as tools @@ -89,7 +86,7 @@ RUN apk add --update --no-cache curl ca-certificates unzip wget openssl && \ chmod +x /usr/local/bin/terrascan && \ chmod +x /usr/local/bin/trivy -FROM erlang:24.3.4.6-alpine +FROM erlang:25.1.2.0-alpine # The name of your application/release (required) ARG APP_NAME @@ -117,4 +114,4 @@ COPY --from=tools /usr/local/bin/terrascan /usr/local/bin/terrascan COPY --from=tools /usr/local/bin/trivy /usr/local/bin/trivy COPY --from=builder /opt/built . -CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground +CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} start diff --git a/rel/config/plural.exs b/apps/core/config/releases.exs similarity index 100% rename from rel/config/plural.exs rename to apps/core/config/releases.exs diff --git a/rel/config/cron.exs b/apps/cron/config/releases.exs similarity index 100% rename from rel/config/cron.exs rename to apps/cron/config/releases.exs diff --git a/rel/config/rtc.exs b/apps/rtc/config/releases.exs similarity index 100% rename from rel/config/rtc.exs rename to apps/rtc/config/releases.exs diff --git a/rel/config/worker.exs b/apps/worker/config/releases.exs similarity index 100% rename from rel/config/worker.exs rename to apps/worker/config/releases.exs diff --git a/rel/config/config.exs b/config/releases.exs similarity index 100% rename from rel/config/config.exs rename to config/releases.exs diff --git a/mix.exs b/mix.exs index 0f46abf6d..661bcd627 100644 --- a/mix.exs +++ b/mix.exs @@ -43,13 +43,93 @@ defmodule Plural.MixProject do "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test - ] + ], + releases: releases() ] end + defp releases() do + [ + plural: [ + include_executables_for: [:unix], + include_erts: true, + strip_beams: true, + quiet: false, + config_providers: [ + {Config.Reader, {:system, "RELEASE_ROOT", "apps/core/config/releases.exs"}}, + ], + steps: [:assemble, ©_configs/1], + applications: [ + api: :permanent, + core: :permanent, + email: :permanent, + graphql: :permanent + ] + ], + rtc: [ + include_executables_for: [:unix], + include_erts: true, + strip_beams: true, + quiet: false, + config_providers: [ + {Config.Reader, {:system, "RELEASE_ROOT", "apps/rtc/config/releases.exs"}}, + ], + steps: [:assemble, ©_configs/1], + applications: [ + rtc: :permanent, + core: :permanent, + graphql: :permanent + ] + ], + worker: [ + include_executables_for: [:unix], + include_erts: true, + strip_beams: true, + quiet: false, + config_providers: [ + {Config.Reader, {:system, "RELEASE_ROOT", "apps/worker/config/releases.exs"}}, + ], + steps: [:assemble, ©_configs/1], + applications: [ + worker: :permanent, + core: :permanent + ] + ], + cron: [ + include_executables_for: [:unix], + include_erts: true, + strip_beams: true, + quiet: false, + config_providers: [ + {Config.Reader, {:system, "RELEASE_ROOT", "apps/cron/config/releases.exs"}}, + ], + steps: [:assemble, ©_configs/1], + applications: [ + cron: :permanent, + core: :permanent, + email: :permanent + ] + ], + ] + end + + defp copy_configs(%{path: path, config_providers: config_providers} = release) do + for {_module, {_context, _root, file_path}} <- config_providers do + # Creating new path + new_path = path <> "/" <> Path.dirname(file_path) + # Removing possible leftover files from previous builds + File.rm_rf!(new_path) + # Creating directory if it doesn't exist + File.mkdir_p!(new_path) + # Copying files to the directory with the same name + File.cp!(Path.expand(file_path), new_path <> "/" <> Path.basename(file_path)) + end + + release + end + defp deps do [ - {:distillery, "~> 2.1"}, {:x509, "~> 0.8.5"}, {:shards, "~> 1.0"}, {:ecto, "~> 3.9.0", override: true}, diff --git a/mix.lock b/mix.lock index b3bb9b95e..918a5d8dd 100644 --- a/mix.lock +++ b/mix.lock @@ -42,7 +42,6 @@ "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "decorator": {:hex, :decorator, "1.4.0", "a57ac32c823ea7e4e67f5af56412d12b33274661bb7640ec7fc882f8d23ac419", [:mix], [], "hexpm", "0a07cedd9083da875c7418dea95b78361197cf2bf3211d743f6f7ce39656597f"}, "dictionary": {:hex, :dictionary, "0.1.1", "fb333a3ee04c514231f0a5e166dd1c27429620b0dabb12fd42e5d28b11657a0a", [:mix], [], "hexpm", "17bae452ab5ecf7bdd75315c6adb44622242de9cf700ab107865ab5557443c2b"}, - "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, "dns": {:hex, :dns, "2.4.0", "44790a0375b28bdc7b59fc894460bfcb03ffeec4c5984e2c3e8b0797b1518327", [:mix], [], "hexpm", "e178e353c469820d02ba889d6a80d01c8c27b47dfcda4016a9cbc6218e3eed64"}, "earmark": {:hex, :earmark, "1.4.2", "3aa0bd23bc4c61cf2f1e5d752d1bb470560a6f8539974f767a38923bb20e1d7f", [:mix], [], "hexpm", "5e8806285d8a3a8999bd38e4a73c58d28534c856bc38c44818e5ba85bbda16fb"}, "ecto": {:hex, :ecto, "3.9.1", "67173b1687afeb68ce805ee7420b4261649d5e2deed8fe5550df23bab0bc4396", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c80bb3d736648df790f7f92f81b36c922d9dd3203ca65be4ff01d067f54eb304"}, diff --git a/rel/config.exs b/rel/config.exs deleted file mode 100644 index e930300f3..000000000 --- a/rel/config.exs +++ /dev/null @@ -1,76 +0,0 @@ -~w(rel plugins *.exs) -|> Path.join() -|> Path.wildcard() -|> Enum.map(&Code.eval_file(&1)) - -use Distillery.Releases.Config, - # This sets the default release built by `mix distillery.release` - default_release: :default, - # This sets the default environment used by `mix distillery.release` - default_environment: Mix.env() - -environment :dev do - set dev_mode: true - set include_erts: false - set cookie: :"[0u(BUb%Eh955Mg5V>:Mgxqa8NY`de)3ikLXo:iM]pU6HUy9NC}C4T(5A=|Xau8/" -end - -environment :prod do - set include_erts: true - set include_src: false - set cookie: :"apMPW^f~jR;8CVeiv`d4(6y]Rv`v_Z;ghL:~3&j!1QM)YRG5_TTpz2q2nGu)9>}l" - set vm_args: "rel/vm.args" - set config_providers: [ - {Distillery.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}, - {Distillery.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/app.exs"]} - ] - set overlays: [ - {:copy, "rel/config/config.exs", "etc/config.exs"}, - {:copy, "rel/config/<%= release_name %>.exs", "etc/app.exs"} - ] -end - -release :plural do - set version: current_version(:api) - set applications: [ - :runtime_tools, - api: :permanent, - core: :permanent, - email: :permanent, - graphql: :load - ] - - set commands: [ - migrate: "rel/commands/migrate.sh", - drop: "rel/commands/drop.sh" - ] -end - -release :rtc do - set version: current_version(:rtc) - set applications: [ - :runtime_tools, - rtc: :permanent, - core: :permanent, - graphql: :load - ] -end - -release :worker do - set version: current_version(:worker) - set applications: [ - :runtime_tools, - worker: :permanent, - core: :permanent - ] -end - -release :cron do - set version: current_version(:cron) - set applications: [ - :runtime_tools, - cron: :permanent, - core: :permanent, - email: :permanent - ] -end diff --git a/rel/env.bat.eex b/rel/env.bat.eex new file mode 100644 index 000000000..6e4098c2b --- /dev/null +++ b/rel/env.bat.eex @@ -0,0 +1,6 @@ +@echo off +rem Set the release to work across nodes. If using the long name format like +rem the one below (my_app@127.0.0.1), you need to also uncomment the +rem RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none". +rem set RELEASE_DISTRIBUTION=name +set RELEASE_NODE=<%= @release.name %>@${POD_IP} diff --git a/rel/env.sh.eex b/rel/env.sh.eex new file mode 100644 index 000000000..2c48b5f66 --- /dev/null +++ b/rel/env.sh.eex @@ -0,0 +1,18 @@ +#!/bin/sh + +# Sets and enables heart (recommended only in daemon mode) +# case $RELEASE_COMMAND in +# daemon*) +# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND" +# export HEART_COMMAND +# export ELIXIR_ERL_OPTIONS="-heart" +# ;; +# *) +# ;; +# esac + +# Set the release to work across nodes. If using the long name format like +# the one below (my_app@127.0.0.1), you need to also uncomment the +# RELEASE_DISTRIBUTION variable below. Must be "sname", "name" or "none". +# export RELEASE_DISTRIBUTION=name +export RELEASE_NODE=<%= @release.name %>@${POD_IP} diff --git a/rel/plugins/.gitignore b/rel/plugins/.gitignore deleted file mode 100644 index 4fa3b5c29..000000000 --- a/rel/plugins/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.* -!*.exs -!.gitignore \ No newline at end of file diff --git a/rel/remote.vm.args.eex b/rel/remote.vm.args.eex new file mode 100644 index 000000000..5886aa87e --- /dev/null +++ b/rel/remote.vm.args.eex @@ -0,0 +1,11 @@ +## Customize flags given to the VM: https://erlang.org/doc/man/erl.html +## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here + +## Number of dirty schedulers doing IO work (file, sockets, and others) +##+SDio 5 + +## Increase number of concurrent ports/sockets +##+Q 65536 + +## Tweak GC to run more often +##-env ERL_FULLSWEEP_AFTER 10 diff --git a/rel/vm.args b/rel/vm.args deleted file mode 100644 index d2108a099..000000000 --- a/rel/vm.args +++ /dev/null @@ -1,30 +0,0 @@ -## This file provide the arguments provided to the VM at startup -## You can find a full list of flags and their behaviours at -## http://erlang.org/doc/man/erl.html - -## Name of the node --name <%= release_name %>@${POD_IP} - -## Cookie for distributed erlang --setcookie ${ERLANG_COOKIE} - -## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive -## (Disabled by default..use with caution!) -##-heart - -## Enable kernel poll and a few async threads -##+K true -##+A 5 -## For OTP21+, the +A flag is not used anymore, -## +SDio replace it to use dirty schedulers -##+SDio 5 - -## Increase number of concurrent ports/sockets -##-env ERL_MAX_PORTS 4096 - -## Tweak GC to run more often -##-env ERL_FULLSWEEP_AFTER 10 - -# Enable SMP automatically based on availability -# On OTP21+, this is not needed anymore. --smp auto diff --git a/rel/vm.args.eex b/rel/vm.args.eex new file mode 100644 index 000000000..5886aa87e --- /dev/null +++ b/rel/vm.args.eex @@ -0,0 +1,11 @@ +## Customize flags given to the VM: https://erlang.org/doc/man/erl.html +## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here + +## Number of dirty schedulers doing IO work (file, sockets, and others) +##+SDio 5 + +## Increase number of concurrent ports/sockets +##+Q 65536 + +## Tweak GC to run more often +##-env ERL_FULLSWEEP_AFTER 10