mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
fix(ci): Populate elixir vsn from env at build time (#7773)
Dependabot's workflow is set up in such a way it seems that it can't find our `sha.exs` file. This is a cleaner approach that doesn't rely on using external files for the application version. Interesting note: `mix compile` will happily use the cached `version` even though it's computed from an env var, because `mix compile` uses file hash and mtime to know when to recompile. See https://github.com/firezone/firezone/network/updates/942719116
This commit is contained in:
@@ -226,10 +226,10 @@ COPY apps/domain/mix.exs ./apps/domain/mix.exs
|
||||
COPY apps/web/mix.exs ./apps/web/mix.exs
|
||||
COPY apps/api/mix.exs ./apps/api/mix.exs
|
||||
COPY config config
|
||||
COPY sha.exs .
|
||||
|
||||
# Fetch and compile the dependencies
|
||||
ARG MIX_ENV="prod"
|
||||
ARG GIT_SHA
|
||||
RUN mix deps.get --only ${MIX_ENV}
|
||||
RUN mix deps.compile --skip-umbrella-children
|
||||
|
||||
@@ -251,7 +251,9 @@ RUN cd apps/web \
|
||||
&& mix assets.deploy
|
||||
|
||||
# Copy the rest of the application files and compile them
|
||||
RUN mix compile
|
||||
# mix doesn't know when GIT_SHA changes, so --force is needed to avoid
|
||||
# pulling in a cached version.
|
||||
RUN mix compile --force
|
||||
|
||||
FROM elixir AS builder
|
||||
|
||||
@@ -269,6 +271,7 @@ COPY rel rel
|
||||
|
||||
ARG APPLICATION_NAME
|
||||
ARG MIX_ENV="prod"
|
||||
ARG GIT_SHA
|
||||
RUN mix release ${APPLICATION_NAME}
|
||||
|
||||
# start a new build stage so that the final image will only contain
|
||||
@@ -301,10 +304,6 @@ COPY --from=builder /app/_build/${MIX_ENV}/rel/${APPLICATION_NAME} ./
|
||||
# Allow the default user to write to the priv directory of some libraries
|
||||
RUN chmod -R ugo+rw /app/lib/tzdata-*/priv
|
||||
|
||||
# Populate the SHA pointing to this build
|
||||
ARG GIT_SHA
|
||||
RUN echo ${GIT_SHA} > ./GIT_SHA
|
||||
|
||||
# Change user to "default" to limit runtime privileges
|
||||
USER default
|
||||
|
||||
|
||||
@@ -2,11 +2,9 @@ defmodule API.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
{sha, _} = Code.eval_file(Path.join([__DIR__, "..", "..", "sha.exs"]))
|
||||
|
||||
[
|
||||
app: :api,
|
||||
version: "0.1.0+#{sha}",
|
||||
version: version(),
|
||||
build_path: "../../_build",
|
||||
config_path: "../../config/config.exs",
|
||||
deps_path: "../../deps",
|
||||
@@ -79,4 +77,9 @@ defmodule API.MixProject do
|
||||
test: ["ecto.create --quiet", "ecto.migrate", "test"]
|
||||
]
|
||||
end
|
||||
|
||||
defp version do
|
||||
sha = System.get_env("GIT_SHA", "deadbeef") |> String.trim()
|
||||
"0.1.0+#{sha}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,9 @@ defmodule Domain.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
{sha, _} = Code.eval_file(Path.join([__DIR__, "..", "..", "sha.exs"]))
|
||||
|
||||
[
|
||||
app: :domain,
|
||||
version: "0.1.0+#{sha}",
|
||||
version: version(),
|
||||
build_path: "../../_build",
|
||||
config_path: "../../config/config.exs",
|
||||
deps_path: "../../deps",
|
||||
@@ -112,4 +110,9 @@ defmodule Domain.MixProject do
|
||||
test: ["ecto.create --quiet", "ecto.migrate", "test"]
|
||||
]
|
||||
end
|
||||
|
||||
defp version do
|
||||
sha = System.get_env("GIT_SHA", "deadbeef") |> String.trim()
|
||||
"0.1.0+#{sha}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,9 @@ defmodule Web.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
{sha, _} = Code.eval_file(Path.join([__DIR__, "..", "..", "sha.exs"]))
|
||||
|
||||
[
|
||||
app: :web,
|
||||
version: "0.1.0+#{sha}",
|
||||
version: version(),
|
||||
build_path: "../../_build",
|
||||
config_path: "../../config/config.exs",
|
||||
deps_path: "../../deps",
|
||||
@@ -104,4 +102,9 @@ defmodule Web.MixProject do
|
||||
test: ["ecto.create --quiet", "ecto.migrate", "test"]
|
||||
]
|
||||
end
|
||||
|
||||
defp version do
|
||||
sha = System.get_env("GIT_SHA", "deadbeef") |> String.trim()
|
||||
"0.1.0+#{sha}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,12 +2,10 @@ defmodule Firezone.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
{sha, _} = Code.eval_file(Path.join([__DIR__, "sha.exs"]))
|
||||
|
||||
[
|
||||
name: :firezone,
|
||||
apps_path: "apps",
|
||||
version: "0.1.0+#{sha}",
|
||||
version: version(),
|
||||
start_permanent: Mix.env() == :prod,
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [
|
||||
@@ -95,4 +93,9 @@ defmodule Firezone.MixProject do
|
||||
]
|
||||
]
|
||||
end
|
||||
|
||||
defp version do
|
||||
sha = System.get_env("GIT_SHA", "deadbeef") |> String.trim()
|
||||
"0.1.0+#{sha}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
case File.read(Path.join([__DIR__, "GIT_SHA"])) do
|
||||
{:ok, sha} ->
|
||||
sha |> String.trim()
|
||||
|
||||
_ ->
|
||||
"deadbeef"
|
||||
end
|
||||
Reference in New Issue
Block a user