Skip to content

Commit

Permalink
Short sha + dev
Browse files Browse the repository at this point in the history
  • Loading branch information
roznawsk committed Mar 12, 2024
1 parent ee079ef commit 3d67d56
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
tags: |
type=semver,pattern={{version}}
type=edge,branch=main
- name: Set short sha
shell: bash
run: |
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: Build and push Docker image
uses: docker/build-push-action@v4
Expand All @@ -47,4 +51,4 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: JF_GIT_COMMIT=${{ github.sha }}
build-args: JF_GIT_COMMIT=${{ env.sha_short }}
4 changes: 4 additions & 0 deletions lib/jellyfish.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ defmodule Jellyfish do
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""

@version Mix.Project.config()[:version]

def version(), do: @version
end
4 changes: 1 addition & 3 deletions lib/jellyfish/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ defmodule Jellyfish.Application do

require Logger

@version Mix.Project.config()[:version]

@impl true
def start(_type, _args) do
scrape_interval = Application.fetch_env!(:jellyfish, :webrtc_metrics_scrape_interval)
dist_config = Application.fetch_env!(:jellyfish, :dist_config)
webrtc_config = Application.fetch_env!(:jellyfish, :webrtc_config)
git_commit = Application.get_env(:jellyfish, :git_commit)

Logger.info("Starting Jellyfish v#{@version} (#{git_commit})")
Logger.info("Starting Jellyfish v#{Jellyfish.version()} (#{git_commit})")
Logger.info("Distribution config: #{inspect(Keyword.delete(dist_config, :cookie))}")
Logger.info("WebRTC config: #{inspect(webrtc_config)}")

Expand Down
8 changes: 1 addition & 7 deletions lib/jellyfish/config_reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,7 @@ defmodule Jellyfish.ConfigReader do
end

def read_git_commit() do
System.get_env("JF_GIT_COMMIT") ||
with {_path, 0} <- System.cmd("which", ["git"]),
{commit, 0} <- System.cmd("git", ["rev-parse", "HEAD"]) do
commit |> String.trim()
else
_error -> nil
end
System.get_env("JF_GIT_COMMIT") || "dev"
end

defp do_read_nodes_list_config(node_name_value, cookie, mode) do
Expand Down
4 changes: 1 addition & 3 deletions lib/jellyfish_web/api_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ defmodule JellyfishWeb.ApiSpec do

alias OpenApiSpex.{Components, Info, License, Paths, Schema, SecurityScheme}

@version Mix.Project.config()[:version]

# OpenAPISpex master specification

@impl OpenApiSpex.OpenApi
def spec() do
%OpenApiSpex.OpenApi{
info: %Info{
title: "Jellyfish Media Server",
version: @version,
version: Jellyfish.version(),
license: %License{
name: "Apache 2.0",
url: "https://www.apache.org/licenses/LICENSE-2.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/jellyfish_web/api_spec/health_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ defmodule JellyfishWeb.ApiSpec.HealthReport do
uptime: %Schema{type: :integer, description: "Uptime of Jellyfish (in seconds)"},
distribution: Distribution,
version: %Schema{type: :string, description: "Version of Jellyfish"},
git_commit: %Schema{type: :string, description: "Commit hash of the build"}
gitCommit: %Schema{type: :string, description: "Commit hash of the build"}
},
required: [:status, :uptime, :distribution, :version]
required: [:status, :uptime, :distribution, :version, :gitCommit]
})
end
6 changes: 2 additions & 4 deletions lib/jellyfish_web/controllers/healthcheck_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ defmodule JellyfishWeb.HealthcheckController do

alias JellyfishWeb.ApiSpec

@version Mix.Project.config()[:version]

action_fallback JellyfishWeb.FallbackController

tags [:health]
Expand Down Expand Up @@ -33,8 +31,8 @@ defmodule JellyfishWeb.HealthcheckController do
status: :up,
uptime: get_uptime(),
distribution: get_distribution_report(),
version: @version,
git_commit: Application.get_env(:jellyfish, :git_commit)
version: Jellyfish.version(),
gitCommit: Application.get_env(:jellyfish, :git_commit)
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jellyfish_web/controllers/healthcheck_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule JellyfishWeb.HealthcheckJSON do

def data(%{status: status, distribution: distribution} = report) do
report
|> Map.take([:uptime, :version, :git_commit])
|> Map.take([:uptime, :version, :gitCommit])
|> Map.merge(%{
status: status_str(status),
distribution: %{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule JellyfishWeb.HealthcheckControllerTest do

@schema JellyfishWeb.ApiSpec.spec()

@commit_hash_length 40
@commit_hash_length 7

setup %{conn: conn} do
server_api_token = Application.fetch_env!(:jellyfish, :server_api_token)
Expand All @@ -19,7 +19,7 @@ defmodule JellyfishWeb.HealthcheckControllerTest do
response = json_response(conn, :ok)
assert_response_schema(response, "HealthcheckResponse", @schema)

version = Mix.Project.config()[:version]
version = Jellyfish.version()

assert %{
"status" => "UP",
Expand All @@ -33,6 +33,6 @@ defmodule JellyfishWeb.HealthcheckControllerTest do
"git_commit" => commit
} = response["data"]

assert String.length(commit) == @commit_hash_length
assert commit == "dev" || String.length(commit) == @commit_hash_length
end
end

0 comments on commit 3d67d56

Please sign in to comment.