Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Oct 29, 2024
1 parent 4ea638c commit e35b181
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ COPY --link lib lib

# workaround for compilation errors (eg. "could not load module Needle.UID due to reason :unavailable")
RUN MIX_ENV=prod mix deps.clean needle_uid jason poison bonfire --build
RUN MIX_ENV=prod mix deps.compile --include-children needle_uid needle_ulid paper_trail
RUN MIX_ENV=prod mix deps.compile --include-children needle_uid needle_ulid 
# paper_trail

# compile protocols (attempted fix for 'could not load module Poison.Encoder due to reason :unavailable')
# RUN MIX_ENV=prod mix compile.protocols
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# A Dockerfile for development/testing

version: "3.5"
# version: "3.5"

services:
web:
Expand Down
96 changes: 62 additions & 34 deletions flavours/classic/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ import Bonfire.Me.Fake
import Bonfire.Social.Fake
import Bonfire.Posts.Fake

# num_users = 100
# num_objects = 100000
# num_sub_objects = 50
num_users = 3
num_objects = 10
num_sub_objects = 10

System.put_env("INVITE_ONLY", "false")
System.put_env("SEARCH_INDEXING_DISABLED", "true")

Application.put_env(:bonfire_common, Bonfire.Common.AntiSpam,
service: Bonfire.Common.AntiSpam.Mock
)

# if the user has configured an admin user for the seeds, insert it.
case {System.get_env("ADMIN_USER", "root"), System.get_env("ADMIN_PASSWORD", "")} do
{u, p} when p != "" ->
Expand All @@ -21,61 +32,76 @@ case {System.get_env("ADMIN_USER", "root"), System.get_env("ADMIN_PASSWORD", "")
end

# create some users
users = for _ <- 1..3, do: fake_user!()
users = for _ <- 1..num_users, do: fake_user!()
random_user = fn -> Faker.Util.pick(users) end

# start fake threads
threads =
for _ <- 1..10 do
thread = fake_post!(random_user.())
comment = fake_comment!(random_user.(), thread)
comment = fake_comment!(random_user.(), comment)
for i <- 1..num_objects do
thread =
case Faker.Util.pick(1..3) do
1 ->
fake_post!(random_user.())

2 ->
fake_post!(random_user.(), "public", %{
post_content: %{
summary: "test #{i} with #hashtag"
}
})

3 ->
fake_post!(random_user.(), "public", %{
post_content: %{
summary: "@#{e(random_user.(), :character, :username, nil)} test mention #{i}"
}
})
end

comments = for i <- 1..num_sub_objects, do: fake_comment!(random_user.(), thread)

_sub_comment =
for i <- 1..num_sub_objects, do: fake_comment!(random_user.(), Faker.Util.pick(comments))

thread
end ++
for i <- 1..4 do
fake_post!(random_user.(), "public", %{
post_content: %{
html_body: "test #{i} with #hashtag"
}
})
end ++
for i <- 1..4 do
mention = random_user.()

fake_post!(random_user.(), "public", %{
post_content: %{
html_body: "@#{e(mention, :character, :username, nil)} test mention #{i}"
}
})
end
end

# random_thread = fn -> Faker.Util.pick(threads) end

# define some tags/categories
if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Classify.Simulate)) do
for _ <- 1..2 do
if(
Bonfire.Common.Extend.extension_enabled?(Bonfire.UI.Groups) or
Bonfire.Common.Extend.extension_enabled?(Bonfire.UI.Topics)
) do
for _ <- 1..num_objects do
category = Bonfire.Classify.Simulate.fake_category!(random_user.())
_subcategory = Bonfire.Classify.Simulate.fake_category!(random_user.(), category)

for i <- 1..num_sub_objects do
subcategory = Bonfire.Classify.Simulate.fake_category!(random_user.(), category)

for i <- 1..num_sub_objects do
_subsubcategory = Bonfire.Classify.Simulate.fake_category!(random_user.(), subcategory)
end
end
end
end

# define some geolocations
if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Geolocate.Simulate)) do
for _ <- 1..2,
for _ <- 1..num_objects,
do: Bonfire.Geolocate.Simulate.fake_geolocation!(random_user.())
end

# define some units
if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Quantify.Simulate)) do
for _ <- 1..2 do
_unit1 = Bonfire.Quantify.Simulate.fake_unit!(random_user.())
_unit2 = Bonfire.Quantify.Simulate.fake_unit!(random_user.())
for _ <- 1..num_objects do
Bonfire.Quantify.Simulate.fake_unit!(random_user.())
end
end

# conduct some fake economic activities
if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do
for _ <- 1..2 do
for _ <- 1..num_objects do
user = random_user.()
action_id = ValueFlows.Simulate.action_id()

Expand All @@ -84,7 +110,7 @@ if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do
_proposal = ValueFlows.Simulate.fake_proposal!(user)
end

for _ <- 1..2 do
for _ <- 1..num_objects do
user = random_user.()

_process_spec = ValueFlows.Simulate.fake_process_specification!(user)
Expand All @@ -105,10 +131,12 @@ if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do

# define some geolocations
if(Bonfire.Common.Extend.extension_enabled?(Bonfire.Geolocate.Simulate)) do
places = for _ <- 1..2, do: Bonfire.Geolocate.Simulate.fake_geolocation!(random_user.())
places =
for _ <- 1..num_objects, do: Bonfire.Geolocate.Simulate.fake_geolocation!(random_user.())

random_place = fn -> Faker.Util.pick(places) end

for _ <- 1..2 do
for _ <- 1..num_objects do
# define some intents with geolocation
_intent =
ValueFlows.Simulate.fake_intent!(
Expand Down Expand Up @@ -157,7 +185,7 @@ if(Bonfire.Common.Extend.extension_enabled?(ValueFlows.Simulate)) do
unit1 = Bonfire.Quantify.Simulate.fake_unit!(random_user.())
unit2 = Bonfire.Quantify.Simulate.fake_unit!(random_user.())

for _ <- 1..2 do
for _ <- 1..num_objects do
action_id = ValueFlows.Simulate.action_id()
# define some intents with measurements
intent =
Expand Down
7 changes: 5 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,10 @@ rebuild: init

_db-dump docker_compose compose_args="":
-mv data/db_dump.sql data/db_dump.archive.sql
just docker-compose -f {{docker_compose}} {{compose_args}} exec db /bin/bash -c "PGPASSWORD=$POSTGRES_PASSWORD pg_dump --username $POSTGRES_USER $POSTGRES_DB" > data/db_dump.sql
just _db-shell {{docker_compose}} pg_dump {{compose_args}} " > data/db_dump.sql"

_db-shell docker_compose cmd="psql" compose_args="" extra_args="":
just docker-compose -f {{docker_compose}} {{compose_args}} exec --user $POSTGRES_USER db /bin/bash -c "PGPASSWORD=$POSTGRES_PASSWORD {{cmd}} --username $POSTGRES_USER" {{extra_args}}

# Run a specific command in the container (if used), eg: `just cmd messclt` or `just cmd time` or `just cmd "echo hello"`
@cmd *args='': init docker-stop-web
Expand All @@ -863,7 +866,7 @@ shell:
-docker rm $WEB_CONTAINER

@docker *args='':
export $(./tool-versions-to-env.sh 3 | xargs) && export $(grep -v '^#' .tool-versions.env | xargs) && export ELIXIR_DOCKER_IMAGE="${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION}" && echo $ELIXIR_DOCKER_IMAGE && docker $@
export $(./tool-versions-to-env.sh 3 | xargs) && export $(grep -v '^#' .tool-versions.env | xargs) && export ELIXIR_DOCKER_IMAGE="${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-alpine-${ALPINE_VERSION}" && docker $@

@docker-compose *args='':
just docker compose $@
Expand Down

0 comments on commit e35b181

Please sign in to comment.