[#2497] Customized exexec launch to support root operation (currently required by Gitlab CI).
This commit is contained in:
parent
610343edb3
commit
3a1e810aaa
6 changed files with 59 additions and 4 deletions
38
lib/pleroma/exec.ex
Normal file
38
lib/pleroma/exec.ex
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Exec do
|
||||
@moduledoc "Pleroma wrapper around Exexec commands."
|
||||
|
||||
alias Pleroma.Config
|
||||
|
||||
def ensure_started(options_overrides \\ %{}) do
|
||||
options =
|
||||
if Config.get([:exexec, :root_mode]) || System.get_env("USER") == "root" do
|
||||
# Note: running as `root` is discouraged (yet Gitlab CI does that by default)
|
||||
%{root: true, user: "root", limit_users: ["root"]}
|
||||
else
|
||||
%{}
|
||||
end
|
||||
|
||||
options =
|
||||
options
|
||||
|> Map.merge(Config.get([:exexec, :options], %{}))
|
||||
|> Map.merge(options_overrides)
|
||||
|
||||
with {:error, {:already_started, pid}} <- Exexec.start(options) do
|
||||
{:ok, pid}
|
||||
end
|
||||
end
|
||||
|
||||
def run(cmd, options \\ %{}) do
|
||||
ensure_started()
|
||||
Exexec.run(cmd, options)
|
||||
end
|
||||
|
||||
def cmd(cmd, options \\ %{}) do
|
||||
options = Map.merge(%{sync: true, stdout: true}, options)
|
||||
run(cmd, options)
|
||||
end
|
||||
end
|
||||
|
|
@ -7,8 +7,6 @@ defmodule Pleroma.Helpers.MediaHelper do
|
|||
Handles common media-related operations.
|
||||
"""
|
||||
|
||||
@ffmpeg_opts [{:sync, true}, {:stdout, true}]
|
||||
|
||||
def ffmpeg_resize_remote(uri, %{max_width: max_width, max_height: max_height}) do
|
||||
cmd = ~s"""
|
||||
curl -L "#{uri}" |
|
||||
|
|
@ -20,7 +18,7 @@ defmodule Pleroma.Helpers.MediaHelper do
|
|||
cat
|
||||
"""
|
||||
|
||||
with {:ok, [stdout: stdout_list]} <- Exexec.run(cmd, @ffmpeg_opts) do
|
||||
with {:ok, [stdout: stdout_list]} <- Pleroma.Exec.cmd(cmd) do
|
||||
{:ok, Enum.join(stdout_list)}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue