Docker support See merge request framasoft/mobilizon!674master
commit
c0591567f4
@ -0,0 +1,42 @@
|
||||
# First build the application assets
|
||||
FROM node:alpine as assets
|
||||
|
||||
RUN apk add --no-cache python build-base
|
||||
|
||||
COPY js .
|
||||
RUN yarn install \
|
||||
&& yarn run build
|
||||
|
||||
# Then, build the application binary
|
||||
FROM elixir:alpine AS builder
|
||||
|
||||
RUN apk add --no-cache build-base git cmake
|
||||
|
||||
COPY mix.exs mix.lock ./
|
||||
ENV MIX_ENV=prod
|
||||
RUN mix local.hex --force \
|
||||
&& mix local.rebar --force \
|
||||
&& mix deps.get
|
||||
|
||||
COPY lib ./lib
|
||||
COPY priv ./priv
|
||||
COPY config ./config
|
||||
COPY rel ./rel
|
||||
COPY docker/production/releases.exs ./config/
|
||||
COPY --from=assets ./priv/static ./priv/static
|
||||
|
||||
RUN mix phx.digest \
|
||||
&& mix release
|
||||
|
||||
# Finally setup the app
|
||||
FROM alpine
|
||||
|
||||
RUN apk add --no-cache openssl ncurses-libs file
|
||||
|
||||
USER nobody
|
||||
EXPOSE 4000
|
||||
|
||||
COPY --from=builder --chown=nobody:nobody _build/prod/rel/mobilizon ./
|
||||
COPY docker/production/docker-entrypoint.sh ./
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
@ -0,0 +1,42 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
mobilizon:
|
||||
image: framasoft/mobilizon
|
||||
environment:
|
||||
- MOBILIZON_INSTANCE_NAME
|
||||
- MOBILIZON_INSTANCE_HOST
|
||||
- MOBILIZON_INSTANCE_EMAIL
|
||||
- MOBILIZON_REPLY_EMAIL
|
||||
- MOBILIZON_ADMIN_EMAIL
|
||||
- MOBILIZON_INSTANCE_REGISTRATIONS_OPEN
|
||||
- MOBILIZON_DATABASE_USERNAME=${POSTGRES_USER}
|
||||
- MOBILIZON_DATABASE_PASSWORD=${POSTGRES_PASSWORD}
|
||||
- MOBILIZON_DATABASE_DBNAME=${POSTGRES_DB}
|
||||
- MOBILIZON_DATABASE_HOST=db
|
||||
- MOBILIZON_INSTANCE_SECRET_KEY_BASE
|
||||
- MOBILIZON_INSTANCE_SECRET_KEY
|
||||
- MOBILIZON_SMTP_SERVER
|
||||
- MOBILIZON_SMTP_HOSTNAME
|
||||
- MOBILIZON_SMTP_PORT
|
||||
- MOBILIZON_SMTP_SSL
|
||||
- MOBILIZON_SMTP_USERNAME
|
||||
- MOBILIZON_SMTP_PASSWORD
|
||||
volumes:
|
||||
- ./public/uploads:/app/uploads
|
||||
ports:
|
||||
- "4000:4000"
|
||||
|
||||
db:
|
||||
image: postgis/postgis
|
||||
volumes:
|
||||
- ./db:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_USER
|
||||
- POSTGRES_PASSWORD
|
||||
- POSTGRES_DB
|
||||
|
||||
networks:
|
||||
default:
|
||||
ipam:
|
||||
driver: default
|
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "-- Running migrations..."
|
||||
/bin/mobilizon_ctl migrate
|
||||
|
||||
echo "-- Starting!"
|
||||
exec /bin/mobilizon start
|
@ -0,0 +1,20 @@
|
||||
# Copy this file to .env, then update it with your own settings
|
||||
|
||||
# Database settings
|
||||
POSTGRES_USER=mobilizon
|
||||
POSTGRES_PASSWORD=changethis
|
||||
POSTGRES_DB=mobilizon
|
||||
|
||||
# Instance configuration
|
||||
MOBILIZON_INSTANCE_NAME=My Mobilizon Instance
|
||||
MOBILIZON_INSTANCE_HOST=mobilizon.lan
|
||||
MOBILIZON_INSTANCE_SECRET_KEY_BASE=changethis
|
||||
MOBILIZON_INSTANCE_SECRET_KEY=changethis
|
||||
MOBILIZON_INSTANCE_EMAIL=noreply@mobilizon.lan
|
||||
MOBILIZON_REPLY_EMAIL=contact@mobilizon.lan
|
||||
|
||||
# Email settings
|
||||
MOBILIZON_SMTP_SERVER=localhost
|
||||
MOBILIZON_SMTP_HOSTNAME=localhost
|
||||
MOBILIZON_SMTP_USERNAME=noreply@mobilizon.lan
|
||||
MOBILIZON_SMTP_PASSWORD=password
|
@ -0,0 +1,51 @@
|
||||
# Mobilizon instance configuration
|
||||
|
||||
import Config
|
||||
|
||||
config :mobilizon, Mobilizon.Web.Endpoint,
|
||||
server: true,
|
||||
url: [host: System.get_env("MOBILIZON_INSTANCE_HOST", "mobilizon.lan")],
|
||||
http: [port: 4000],
|
||||
secret_key_base: System.get_env("MOBILIZON_INSTANCE_SECRET_KEY_BASE", "changethis")
|
||||
|
||||
config :mobilizon, Mobilizon.Web.Auth.Guardian,
|
||||
secret_key: System.get_env("MOBILIZON_INSTANCE_SECRET_KEY", "changethis")
|
||||
|
||||
config :mobilizon, :instance,
|
||||
name: System.get_env("MOBILIZON_INSTANCE_NAME", "Mobilizon"),
|
||||
description: "Change this to a proper description of your instance",
|
||||
hostname: System.get_env("MOBILIZON_INSTANCE_HOST", "mobilizon.lan"),
|
||||
registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN", "false") == "true",
|
||||
demo: false,
|
||||
allow_relay: true,
|
||||
federating: true,
|
||||
email_from: System.get_env("MOBILIZON_INSTANCE_EMAIL", "noreply@mobilizon.lan"),
|
||||
email_reply_to: System.get_env("MOBILIZON_REPLY_EMAIL", "noreply@mobilizon.lan")
|
||||
|
||||
|
||||
config :mobilizon, Mobilizon.Web.Upload.Uploader.Local,
|
||||
uploads: System.get_env("MOBILIZON_UPLOADS", "/app/uploads")
|
||||
|
||||
|
||||
config :mobilizon, Mobilizon.Storage.Repo,
|
||||
adapter: Ecto.Adapters.Postgres,
|
||||
username: System.get_env("MOBILIZON_DATABASE_USERNAME", "username"),
|
||||
password: System.get_env("MOBILIZON_DATABASE_PASSWORD", "password"),
|
||||
database: System.get_env("MOBILIZON_DATABASE_DBNAME", "mobilizon"),
|
||||
hostname: System.get_env("MOBILIZON_DATABASE_HOST", "postgres"),
|
||||
port: 5432,
|
||||
pool_size: 10
|
||||
|
||||
config :mobilizon, Mobilizon.Web.Email.Mailer,
|
||||
adapter: Bamboo.SMTPAdapter,
|
||||
server: System.get_env("MOBILIZON_SMTP_SERVER", "localhost"),
|
||||
hostname: System.get_env("MOBILIZON_SMTP_HOSTNAME", "localhost"),
|
||||
port: System.get_env("MOBILIZON_SMTP_PORT", "25"),
|
||||
username: System.get_env("MOBILIZON_SMTP_USERNAME", nil),
|
||||
password: System.get_env("MOBILIZON_SMTP_PASSWORD", nil),
|
||||
tls: :if_available,
|
||||
allowed_tls_versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"],
|
||||
ssl: System.get_env("MOBILIZON_SMTP_SSL", "false"),
|
||||
retries: 1,
|
||||
no_mx_lookups: false,
|
||||
auth: :if_available
|
@ -0,0 +1,54 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright ยฉ 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-onl
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.Ecto do
|
||||
@moduledoc """
|
||||
Provides tools for Ecto-related tasks (such as migrations)
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Ensures the given repository's migrations path exists on the file system.
|
||||
"""
|
||||
@spec ensure_migrations_path(Ecto.Repo.t(), Keyword.t()) :: String.t()
|
||||
def ensure_migrations_path(repo, opts) do
|
||||
path = opts[:migrations_path] || Path.join(source_repo_priv(repo), "migrations")
|
||||
|
||||
path =
|
||||
case Path.type(path) do
|
||||
:relative ->
|
||||
Path.join(Application.app_dir(:mobilizon), path)
|
||||
|
||||
:absolute ->
|
||||
path
|
||||
end
|
||||
|
||||
if not File.dir?(path) do
|
||||
raise_missing_migrations(Path.relative_to_cwd(path), repo)
|
||||
end
|
||||
|
||||
path
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the private repository path relative to the source.
|
||||
"""
|
||||
def source_repo_priv(repo) do
|
||||
config = repo.config()
|
||||
priv = config[:priv] || "priv/#{repo |> Module.split() |> List.last() |> Macro.underscore()}"
|
||||
Path.join(Application.app_dir(:mobilizon), priv)
|
||||
end
|
||||
|
||||
defp raise_missing_migrations(path, repo) do
|
||||
raise("""
|
||||
Could not find migrations directory #{inspect(path)}
|
||||
for repo #{inspect(repo)}.
|
||||
This may be because you are in a new project and the
|
||||
migration directory has not been created yet. Creating an
|
||||
empty directory at the path above will fix this error.
|
||||
If you expected existing migrations to be found, please
|
||||
make sure your repository has been properly configured
|
||||
and the configured path exists.
|
||||
""")
|
||||
end
|
||||
end
|
@ -0,0 +1,71 @@
|
||||
# Portions of this file are derived from Pleroma:
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright ยฉ 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.Ecto.Migrate do
|
||||
use Mix.Task
|
||||
import Mix.Tasks.Mobilizon.Common
|
||||
alias Mix.Tasks.Mobilizon.Ecto, as: EctoTask
|
||||
require Logger
|
||||
|
||||
@shortdoc "Wrapper on `ecto.migrate` task."
|
||||
|
||||
@aliases [
|
||||
n: :step,
|
||||
v: :to
|
||||
]
|
||||
|
||||
@switches [
|
||||
all: :boolean,
|
||||
step: :integer,
|
||||
to: :integer,
|
||||
quiet: :boolean,
|
||||
log_sql: :boolean,
|
||||
strict_version_order: :boolean,
|
||||
migrations_path: :string
|
||||
]
|
||||
|
||||
@repo Mobilizon.Storage.Repo
|
||||
|
||||
@moduledoc """
|
||||
Changes `Logger` level to `:info` before start migration.
|
||||
Changes level back when migration ends.
|
||||
|
||||
## Start migration
|
||||
|
||||
mix mobilizon.ecto.migrate [OPTIONS]
|
||||
|
||||
Options:
|
||||
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Migrate.html
|
||||
"""
|
||||
|
||||
@impl true
|
||||
def run(args \\ []) do
|
||||
start_mobilizon()
|
||||
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
||||
|
||||
if Application.get_env(:mobilizon, @repo)[:ssl] do
|
||||
Application.ensure_all_started(:ssl)
|
||||
end
|
||||
|
||||
opts =
|
||||
if opts[:to] || opts[:step] || opts[:all],
|
||||
do: opts,
|
||||
else: Keyword.put(opts, :all, true)
|
||||
|
||||
opts =
|
||||
if opts[:quiet],
|
||||
do: Keyword.merge(opts, log: false, log_sql: false),
|
||||
else: opts
|
||||
|
||||
path = EctoTask.ensure_migrations_path(@repo, opts)
|
||||
|
||||
level = Logger.level()
|
||||
Logger.configure(level: :info)
|
||||
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, path, :up, opts))
|
||||
|
||||
Logger.configure(level: level)
|
||||
end
|
||||
end
|
@ -0,0 +1,74 @@
|
||||
# Portions of this file are derived from Pleroma:
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright ยฉ 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Mobilizon.Ecto.Rollback do
|
||||
use Mix.Task
|
||||
import Mix.Tasks.Mobilizon.Common
|
||||
alias Mix.Tasks.Mobilizon.Ecto, as: EctoTask
|
||||
require Logger
|
||||
@shortdoc "Wrapper on `ecto.rollback` task"
|
||||
|
||||
@aliases [
|
||||
n: :step,
|
||||
v: :to
|
||||
]
|
||||
|
||||
@switches [
|
||||
all: :boolean,
|
||||
step: :integer,
|
||||
to: :integer,
|
||||
start: :boolean,
|
||||
quiet: :boolean,
|
||||
log_sql: :boolean,
|
||||
migrations_path: :string
|
||||
]
|
||||
|
||||
@repo Mobilizon.Storage.Repo
|
||||
|
||||
@moduledoc """
|
||||
Changes `Logger` level to `:info` before start rollback.
|
||||
Changes level back when rollback ends.
|
||||
|
||||
## Start rollback
|
||||
|
||||
mix mobilizon.ecto.rollback
|
||||
|
||||
Options:
|
||||
- see https://hexdocs.pm/ecto/2.0.0/Mix.Tasks.Ecto.Rollback.html
|
||||
"""
|
||||
|
||||
@impl true
|
||||
def run(args \\ []) do
|
||||
start_mobilizon()
|
||||
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
|
||||
|
||||
if Application.get_env(:mobilizon, @repo)[:ssl] do
|
||||
Application.ensure_all_started(:ssl)
|
||||
end
|
||||
|
||||
opts =
|
||||
if opts[:to] || opts[:step] || opts[:all],
|
||||
do: opts,
|
||||
else: Keyword.put(opts, :step, 1)
|
||||
|
||||
opts =
|
||||
if opts[:quiet],
|
||||
do: Keyword.merge(opts, log: false, log_sql: false),
|
||||
else: opts
|
||||
|
||||
path = EctoTask.ensure_migrations_path(@repo, opts)
|
||||
|
||||
level = Logger.level()
|
||||
Logger.configure(level: :info)
|
||||
|
||||
if Mobilizon.Config.get(:env) == :test do
|
||||
Logger.info("Rollback succesfully")
|
||||
else
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(@repo, &Ecto.Migrator.run(&1, path, :down, opts))
|
||||
end
|
||||
|
||||
Logger.configure(level: level)
|
||||
end
|
||||
end
|
@ -1,68 +0,0 @@
|
||||
defmodule Mix.Tasks.Mobilizon.MoveParticipantStats do
|
||||
@moduledoc """
|
||||
Temporary task to move participant stats in the events table
|
||||
|
||||
This task will be removed in version 1.0.0-beta.3
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Events.ParticipantRole
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
require Logger
|
||||
|
||||
@shortdoc "Move participant stats to events table"
|
||||
def run([]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
events =
|
||||
Event
|
||||
|> preload([e], :tags)
|
||||
|> Repo.all()
|
||||
|
||||
nb_events = length(events)
|
||||
|
||||
IO.puts(
|
||||
"\nStarting inserting participants stats into #{nb_events} events, this can take a whileโฆ\n"
|
||||
)
|
||||
|
||||
insert_participants_stats_into_events(events, nb_events)
|
||||
end
|
||||
|
||||
defp insert_participants_stats_into_events([%Event{url: url} = event | events], nb_events) do
|
||||
with roles <- ParticipantRole.__enum_map__(),
|
||||
counts <-
|
||||
Enum.reduce(roles, %{}, fn role, acc ->
|
||||
Map.put(acc, role, count_participants(event, role))
|
||||
end),
|
||||
{:ok, _} <-
|
||||
Events.update_event(event, %{
|
||||
participant_stats: counts
|
||||
}) do
|
||||
Logger.debug("Added participants stats to event #{url}")
|
||||
else
|
||||
{:error, res} ->
|
||||
Logger.error("Error while adding participants stats to event #{url} : #{inspect(res)}")
|
||||
end
|
||||
|
||||
ProgressBar.render(nb_events - length(events), nb_events)
|
||||
|
||||
insert_participants_stats_into_events(events, nb_events)
|
||||
end
|
||||
|
||||
defp insert_participants_stats_into_events([], nb_events) do
|
||||
IO.puts("\nFinished inserting participant stats for #{nb_events} events!\n")
|
||||
end
|
||||
|
||||
defp count_participants(%Event{id: event_id}, role) when is_atom(role) do
|
||||
event_id
|
||||
|> Events.count_participants_query()
|
||||
|> Events.filter_role(role)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
defmodule Mix.Tasks.Mobilizon.Relay.Accept do
|
||||
@moduledoc """
|
||||
Task to accept an instance follow request
|
||||
"""
|
||||
use Mix.Task
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
import Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@shortdoc "Accept an instance follow request"
|
||||
|
||||
@impl Mix.Task
|
||||
def run([target]) do
|
||||
start_mobilizon()
|
||||
|
||||
case Relay.accept(target) do
|
||||
{:ok, _activity} ->
|
||||
# put this task to sleep to allow the genserver to push out the messages
|
||||
:timer.sleep(500)
|
||||
|
||||
{:error, e} ->
|
||||
IO.puts(:stderr, "Error while accept #{target} follow: #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(_) do
|
||||
shell_error("mobilizon.relay.accept requires an instance hostname as arguments")
|
||||
end
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
defmodule Mix.Tasks.Mobilizon.Relay.Follow do
|
||||
@moduledoc """
|
||||
Task to follow an instance
|
||||
"""
|
||||
use Mix.Task
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
import Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@shortdoc "Follow an instance"
|
||||
|
||||
@impl Mix.Task
|
||||
def run([target]) do
|
||||
start_mobilizon()
|
||||
|
||||
case Relay.follow(target) do
|
||||
{:ok, _activity, _follow} ->
|
||||
# put this task to sleep to allow the genserver to push out the messages
|
||||
:timer.sleep(500)
|
||||
|
||||
{:error, e} ->
|
||||
IO.puts(:stderr, "Error while following #{target}: #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(_) do
|
||||
shell_error("mobilizon.relay.follow requires an instance hostname as arguments")
|
||||
end
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
defmodule Mix.Tasks.Mobilizon.Relay.Refresh do
|
||||
@moduledoc """
|
||||
Task to refresh an instance details
|
||||
"""
|
||||
use Mix.Task
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
import Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@shortdoc "Refresh an instance informations and crawl their outbox"
|
||||
|
||||
@impl Mix.Task
|
||||
def run([target]) do
|
||||
start_mobilizon()
|
||||
IO.puts("Refreshing #{target}, this can take a while.")
|
||||
|
||||
case Relay.refresh(target) do
|
||||
:ok ->
|
||||
IO.puts("Refreshed #{target}")
|
||||
|
||||
err ->
|
||||
IO.puts(:stderr, "Error while refreshing #{target}: #{inspect(err)}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(_) do
|
||||
shell_error("mobilizon.relay.refresh requires an instance hostname as arguments")
|
||||
end
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
defmodule Mix.Tasks.Mobilizon.Relay.Unfollow do
|
||||
@moduledoc """
|
||||
Task to unfollow an instance
|
||||
"""
|
||||
use Mix.Task
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
import Mix.Tasks.Mobilizon.Common
|
||||
|
||||
@shortdoc "Unfollow an instance"
|
||||
|
||||
@impl Mix.Task
|
||||
def run([target]) do
|
||||
start_mobilizon()
|
||||
|
||||
case Relay.unfollow(target) do
|
||||
{:ok, _activity, _follow} ->
|
||||
# put this task to sleep to allow the genserver to push out the messages
|
||||
:timer.sleep(500)
|
||||
|
||||
{:error, e} ->
|
||||
IO.puts(:stderr, "Error while unfollowing #{target}: #{inspect(e)}")
|
||||
end
|
||||
end
|
||||
|
||||
def run(_) do
|
||||
shell_error("mobilizon.relay.unfollow requires an instance hostname as arguments")
|
||||
end
|
||||
end
|
@ -1,50 +0,0 @@
|
||||
defmodule Mix.Tasks.Mobilizon.SetupSearch do
|
||||
@moduledoc """
|
||||
Temporary task to insert search data from existing events
|
||||
|
||||
This task will be removed in version 1.0.0-beta.3
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Workers
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
require Logger
|
||||
|
||||
@shortdoc "Insert search data"
|
||||
def run([]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
events =
|
||||
Event
|
||||
|> preload([e], :tags)
|
||||
|> Repo.all()
|
||||
|
||||
nb_events = length(events)
|
||||
|
||||
IO.puts("\nStarting setting up search for #{nb_events} events, this can take a whileโฆ\n")
|
||||
insert_search_event(events, nb_events)
|
||||
end
|
||||
|
||||
defp insert_search_event([%Event{url: url} = event | events], nb_events) do
|
||||
case Workers.BuildSearch.insert_search_event(event) do
|
||||
{:ok, _} ->
|
||||
Logger.debug("Added event #{url} to the search")
|
||||
|
||||
{:error, res} ->
|
||||
Logger.error("Error while adding event #{url} to the search: #{inspect(res)}")
|
||||
end
|
||||
|
||||
ProgressBar.render(nb_events - length(events), nb_events)
|
||||
|
||||
insert_search_event(events, nb_events)
|
||||
end
|
||||
|
||||
defp insert_search_event([], nb_events) do
|
||||
IO.puts("\nFinished setting up search for #{nb_events} events!\n")
|
||||
end
|
||||
end
|
@ -1,30 +0,0 @@
|
||||
defmodule Mix.Tasks.Mobilizon.Toot do
|
||||
@moduledoc """
|
||||
Creates a bot from a source.
|
||||
"""
|
||||
|
||||
use Mix.Task
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
alias Mobilizon.GraphQL.API.Comments
|
||||
|
||||
require Logger
|
||||
|
||||
@shortdoc "Toot to an user"
|
||||
def run([from, text]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
with {:local_actor, %Actor{} = actor} <- {:local_actor, Actors.get_local_actor_by_name(from)},
|
||||
{:ok, _, _} <- Comments.create_comment(%{actor: actor, text: text}) do
|
||||
Mix.shell().info("Tooted")
|
||||
else
|
||||
{:local_actor, _, _} ->
|
||||
Mix.shell().error("Failed to toot.\nActor #{from} doesn't exist")
|
||||
|
||||
_ ->
|
||||
Mix.shell().error("Failed to toot.")
|
||||
end
|
||||
end
|
||||
end
|