Remove stuff I don't need to stay closer to upstream

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-03-12 16:07:29 +01:00
parent 81414cc413
commit bd33a7ac8f
48 changed files with 685 additions and 833 deletions

1
.buildpacks Normal file
View file

@ -0,0 +1 @@
https://github.com/hashnuke/heroku-buildpack-elixir

View file

@ -1,71 +1,130 @@
image: registry.gitlab.com/soapbox-pub/rebased/ci
image: git.pleroma.social:5050/pleroma/pleroma/ci-base
variables: &global_variables
ELIXIR_VER: 1.12.3
POSTGRES_DB: pleroma_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
DB_HOST: postgres
DB_PORT: 5432
MIX_ENV: test
# Needed for Dokku deployment.
# https://github.com/dokku/dokku/issues/2514#issuecomment-616775470
GIT_DEPTH: 0
cache: &cache
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
cache: &global_cache_policy
key:
files:
- mix.lock
paths:
- deps
- _build
policy: pull
stages:
- deps
- check-changelog
- build
- test
- benchmark
- deploy
- release
- docker
- docker-combine
deps:
stage: deps
before_script:
- echo $MIX_ENV
- rm -rf _build/*/lib/pleroma
- mix deps.get
after_script:
- rm -rf _build/*/lib/pleroma
check-changelog:
stage: check-changelog
image: alpine
rules:
- if: $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'pleroma/pleroma' && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == 'weblate-extract'
when: never
- if: $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'pleroma/pleroma' && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME == 'weblate'
when: never
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"
before_script: ''
after_script: ''
cache: {}
script:
- mix deps.get
- mix deps.compile
cache:
<<: *cache
policy: pull-push
only:
changes:
- mix.lock
- apk add git
- sh ./tools/check-changelog
openapi:
.build_changes_policy:
rules:
- changes:
- ".gitlab-ci.yml"
- "**/*.ex"
- "**/*.exs"
- "mix.lock"
.using-ci-base:
tags:
- amd64
build:
extends:
- .build_changes_policy
- .using-ci-base
stage: build
script:
- mix compile --force
spec-build:
extends:
- .using-ci-base
stage: test
only:
changes:
- ".gitlab-ci.yml"
- "lib/pleroma/web/api_spec/**/*.ex"
- "lib/pleroma/web/api_spec.ex"
rules:
- changes:
- ".gitlab-ci.yml"
- "lib/pleroma/web/api_spec/**/*.ex"
- "lib/pleroma/web/api_spec.ex"
artifacts:
paths:
- spec.json
- spec.json
script:
- mix pleroma.openapi_spec spec.json
- mix pleroma.openapi_spec spec.json
test:
stage: test
only:
changes: &elixir-changes
- ".gitlab-ci.yml"
- "**/*.ex"
- "**/*.exs"
- "mix.lock"
services: &db-services
- name: postgres:13-alpine
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
before_script: &db-setup
benchmark:
extends:
- .using-ci-base
stage: benchmark
when: manual
variables:
MIX_ENV: benchmark
services:
- name: postgres:9.6-alpine
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
script:
- mix ecto.create
- mix ecto.migrate
- mix pleroma.load_testing
unit-testing:
extends:
- .build_changes_policy
- .using-ci-base
stage: test
cache: &testing_cache_policy
<<: *global_cache_policy
policy: pull
services:
- name: postgres:13-alpine
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
script:
- mix ecto.create
- mix ecto.migrate
- mix test --cover --preload-modules
coverage: '/^Line total: ([^ ]*%)$/'
artifacts:
@ -74,88 +133,429 @@ test:
coverage_format: cobertura
path: coverage.xml
test-erratic:
unit-testing-erratic:
extends:
- .build_changes_policy
- .using-ci-base
stage: test
retry: 2
allow_failure: true
only:
changes: *elixir-changes
services: *db-services
before_script: *db-setup
cache: &testing_cache_policy
<<: *global_cache_policy
policy: pull
services:
- name: postgres:13-alpine
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
script:
- mix ecto.create
- mix ecto.migrate
- mix test --only=erratic
lint:
# Removed to fix CI issue. In this early state it wasn't adding much value anyway.
# TODO Fix and reinstate federated testing
# federated-testing:
# stage: test
# cache: *testing_cache_policy
# services:
# - name: minibikini/postgres-with-rum:12
# alias: postgres
# command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
# script:
# - mix deps.get
# - mix ecto.create
# - mix ecto.migrate
# - epmd -daemon
# - mix test --trace --only federated
unit-testing-rum:
extends:
- .build_changes_policy
- .using-ci-base
stage: test
only:
changes: *elixir-changes
cache: *testing_cache_policy
services:
- name: minibikini/postgres-with-rum:12
alias: postgres
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
variables:
<<: *global_variables
RUM_ENABLED: "true"
script:
- mix ecto.create
- mix ecto.migrate
- "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
- mix test --preload-modules
lint:
extends: .build_changes_policy
image: &current_elixir elixir:1.12-alpine
stage: test
cache: *testing_cache_policy
before_script: &current_bfr_script
- apk update
- apk add build-base cmake file-dev git openssl
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
script:
- mix format --check-formatted
# analysis:
# stage: test
# only:
# changes: *elixir-changes
# script:
# - mix credo --strict --only=warnings,todo,fixme,consistency,readability
analysis:
extends:
- .build_changes_policy
- .using-ci-base
stage: test
cache: *testing_cache_policy
script:
- mix credo --strict --only=warnings,todo,fixme,consistency,readability
cycles:
extends: .build_changes_policy
image: *current_elixir
stage: test
only:
changes: *elixir-changes
cache: {}
before_script: *current_bfr_script
script:
- mix compile
- mix xref graph --format cycles --label compile | awk '{print $0} END{exit ($0 != "No cycles found")}'
# Deploy with Dokku
# https://github.com/dokku/gitlab-ci
# https://github.com/dokku/ci-docker-image
review:
image: dokku/ci-docker-image
stage: test
docs-deploy:
stage: deploy
cache: *testing_cache_policy
image: alpine:latest
only:
- stable@pleroma/pleroma
- develop@pleroma/pleroma
before_script:
- apk add curl
script:
- curl --fail-with-body -X POST -F"token=$CI_JOB_TOKEN" -F'ref=master' -F"variables[BRANCH]=$CI_COMMIT_REF_NAME" https://git.pleroma.social/api/v4/projects/673/trigger/pipeline
review_app:
image: alpine:3.9
stage: deploy
before_script:
- apk update && apk add openssh-client git
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://rebased-$CI_COMMIT_REF_SLUG.dokku.soapbox.pub
url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
on_stop: stop_review_app
only:
- branches
except:
- main
variables:
GIT_REMOTE_URL: ssh://dokku@$DOKKU_HOST/rebased-$CI_COMMIT_REF_SLUG
GIT_PUSH_FLAGS: --force
script: dokku-deploy
allow_failure: true
release:
stage: deploy
variables:
MIX_ENV: prod
PLEROMA_BUILD_BRANCH: $CI_COMMIT_REF_NAME
- master
- develop
script:
- mix deps.get
- mkdir release
- mix release --path release
- echo "$CI_ENVIRONMENT_SLUG"
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
- (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
- (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
- ssh -t dokku@pleroma.online -- config:set "$CI_ENVIRONMENT_SLUG" APP_NAME="$CI_ENVIRONMENT_SLUG" APP_HOST="$CI_ENVIRONMENT_SLUG.pleroma.online" MIX_ENV=dokku
- (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
- (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
- (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
- git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
spec-deploy:
stage: deploy
artifacts:
name: "rebased-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
paths:
- spec.json
only:
- develop@pleroma/pleroma
image: alpine:latest
before_script:
- apk add curl
script:
- curl --fail-with-body -X POST -F"token=$CI_JOB_TOKEN" -F'ref=master' -F"variables[BRANCH]=$CI_COMMIT_REF_NAME" -F"variables[JOB_REF]=$CI_JOB_ID" https://git.pleroma.social/api/v4/projects/1130/trigger/pipeline
stop_review_app:
image: alpine:3.9
stage: deploy
before_script:
- apk update && apk add openssh-client git
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
script:
- echo "$CI_ENVIRONMENT_SLUG"
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
- ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
- ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
amd64:
stage: release
image: elixir:$ELIXIR_VER
only: &release-only
- stable@pleroma/pleroma
- develop@pleroma/pleroma
- /^maint/.*$/@pleroma/pleroma
- /^release/.*$/@pleroma/pleroma
tags:
- amd64
artifacts: &release-artifacts
name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
paths:
- release/*
cache: {}
only:
refs:
- main
changes: *elixir-changes
# Ideally it would be never for master branch and with the next commit for develop,
# but Gitlab does not support neither `only` for artifacts
# nor setting it to never from .gitlab-ci.yml
# nor expiring with the next commit
expire_in: 42 yrs
docker:
stage: deploy
image: docker:20.10.17
cache: {}
services:
- docker:20.10.17-dind
cache: &release-cache
key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
paths:
- deps
variables: &release-variables
MIX_ENV: prod
before_script: &before-release
- apt-get update && apt-get install -y cmake libmagic-dev
- echo "import Config" > config/prod.secret.exs
- mix local.hex --force
- mix local.rebar --force
script: &release
- mix deps.get --only prod
- mkdir release
- export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
- mix release --path release
amd64-musl:
stage: release
artifacts: *release-artifacts
only: *release-only
image: elixir:$ELIXIR_VER-alpine
tags:
- dind
# https://medium.com/devops-with-valentine/how-to-build-a-docker-image-and-push-it-to-the-gitlab-container-registry-from-a-gitlab-ci-pipeline-acac0d1f26df
script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
- amd64
cache: *release-cache
variables: *release-variables
before_script: &before-release-musl
- apk add git build-base cmake file-dev openssl
- echo "import Config" > config/prod.secret.exs
- mix local.hex --force
- mix local.rebar --force
script: *release
arm:
stage: release
artifacts: *release-artifacts
only: *release-only
tags:
- arm32-specified
image: arm32v7/elixir:$ELIXIR_VER
cache: *release-cache
variables: *release-variables
before_script: *before-release
script: *release
arm-musl:
stage: release
artifacts: *release-artifacts
only: *release-only
tags:
- arm32-specified
image: arm32v7/elixir:$ELIXIR_VER-alpine
cache: *release-cache
variables: *release-variables
before_script: *before-release-musl
script: *release
arm64:
stage: release
artifacts: *release-artifacts
only: *release-only
tags:
- arm
image: arm64v8/elixir:$ELIXIR_VER
cache: *release-cache
variables: *release-variables
before_script: *before-release
script: *release
arm64-musl:
stage: release
artifacts: *release-artifacts
only: *release-only
tags:
- arm
image: arm64v8/elixir:$ELIXIR_VER-alpine
cache: *release-cache
variables: *release-variables
before_script: *before-release-musl
script: *release
.kaniko:
stage: docker
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
cache: {}
dependencies: []
before_script: &before-kaniko
- export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
- export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
- export IMAGE_TAG=$CI_REGISTRY_IMAGE/$BUILD_ARCH_IMG_SUFFIX:$CI_COMMIT_SHORT_SHA
- export IMAGE_TAG_SLUG=$CI_REGISTRY_IMAGE/$BUILD_ARCH_IMG_SUFFIX:$CI_COMMIT_REF_SLUG
- export IMAGE_TAG_LATEST=$CI_REGISTRY_IMAGE/$BUILD_ARCH_IMG_SUFFIX:latest
- export IMAGE_TAG_LATEST_STABLE=$CI_REGISTRY_IMAGE/$BUILD_ARCH_IMG_SUFFIX:latest-stable
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
.kaniko-latest:
extends: .kaniko
only:
refs:
- main
- develop@pleroma/pleroma
script:
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --custom-platform=$BUILD_ARCH --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP --build-arg ELIXIR_IMG=$ELIXIR_IMG --destination $IMAGE_TAG --destination $IMAGE_TAG_SLUG --destination $IMAGE_TAG_LATEST
.kaniko-stable:
extends: .kaniko
only:
- stable@pleroma/pleroma
script:
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --custom-platform=$BUILD_ARCH --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP --build-arg ELIXIR_IMG=$ELIXIR_IMG --destination $IMAGE_TAG --destination $IMAGE_TAG_SLUG --destination $IMAGE_TAG_LATEST_STABLE
.kaniko-release:
extends: .kaniko
only:
- /^release/.*$/@pleroma/pleroma
script:
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --custom-platform=$BUILD_ARCH --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP --build-arg ELIXIR_IMG=$ELIXIR_IMG --destination $IMAGE_TAG --destination $IMAGE_TAG_SLUG
.kaniko-adhoc:
extends: .kaniko
only:
- /^build-docker/.*$/@pleroma/pleroma
script:
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --custom-platform=$BUILD_ARCH --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP --build-arg ELIXIR_IMG=$ELIXIR_IMG --destination $IMAGE_TAG --destination $IMAGE_TAG_SLUG
.kaniko:linux/amd64:
variables:
BUILD_ARCH: linux/amd64
BUILD_ARCH_IMG_SUFFIX: linux-amd64
ELIXIR_IMG: hexpm/elixir
tags:
- amd64
.kaniko:linux/arm64:
variables:
BUILD_ARCH: linux/arm64/v8
BUILD_ARCH_IMG_SUFFIX: linux-arm64-v8
ELIXIR_IMG: hexpm/elixir
tags:
- arm
.kaniko:linux/arm:
variables:
BUILD_ARCH: linux/arm/v7
BUILD_ARCH_IMG_SUFFIX: linux-arm-v7
ELIXIR_IMG: git.pleroma.social:5050/pleroma/ci-image/elixir-linux-arm-v7
tags:
- arm32-specified
kaniko-latest:linux/amd64:
extends:
- .kaniko-latest
- .kaniko:linux/amd64
kaniko-latest:linux/arm64:
extends:
- .kaniko-latest
- .kaniko:linux/arm64
kaniko-latest:linux/arm:
extends:
- .kaniko-latest
- .kaniko:linux/arm
kaniko-stable:linux/amd64:
extends:
- .kaniko-stable
- .kaniko:linux/amd64
kaniko-stable:linux/arm64:
extends:
- .kaniko-stable
- .kaniko:linux/arm64
kaniko-stable:linux/arm:
extends:
- .kaniko-stable
- .kaniko:linux/arm
kaniko-release:linux/amd64:
extends:
- .kaniko-release
- .kaniko:linux/amd64
kaniko-release:linux/arm64:
extends:
- .kaniko-release
- .kaniko:linux/arm64
kaniko-release:linux/arm:
extends:
- .kaniko-release
- .kaniko:linux/arm
.docker-combine:
stage: docker-combine
image: docker:cli
cache: {}
before_script:
- 'BUILD_ARCHES="linux-amd64 linux-arm64-v8 linux-arm-v7"'
- export IMAGE_TAG=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- export IMAGE_TAG_SLUG=$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
- export IMAGE_TAG_LATEST=$CI_REGISTRY_IMAGE:latest
- export IMAGE_TAG_LATEST_STABLE=$CI_REGISTRY_IMAGE:latest-stable
- 'IMAGES=; for arch in $BUILD_ARCHES; do IMAGES="$IMAGES $CI_REGISTRY_IMAGE/$arch:$CI_COMMIT_SHORT_SHA"; done'
- 'IMAGES_SLUG=; for arch in $BUILD_ARCHES; do IMAGES_SLUG="$IMAGES_SLUG $CI_REGISTRY_IMAGE/$arch:$CI_COMMIT_REF_SLUG"; done'
- 'IMAGES_LATEST=; for arch in $BUILD_ARCHES; do IMAGES_LATEST="$IMAGES_LATEST $CI_REGISTRY_IMAGE/$arch:latest"; done'
- 'IMAGES_LATEST_STABLE=; for arch in $BUILD_ARCHES; do IMAGES_LATEST_STABLE="$IMAGES_LATEST_STABLE $CI_REGISTRY_IMAGE/$arch:latest"; done'
- mkdir -p ~/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > ~/.docker/config.json
docker-combine:latest:
extends: .docker-combine
only:
- develop@pleroma/pleroma
script:
- 'docker manifest create $IMAGE_TAG $IMAGES'
- 'docker manifest push $IMAGE_TAG'
- 'docker manifest create $IMAGE_TAG_SLUG $IMAGES_SLUG'
- 'docker manifest push $IMAGE_TAG_SLUG'
- 'docker manifest create $IMAGE_TAG_LATEST $IMAGES_LATEST'
- 'docker manifest push $IMAGE_TAG_LATEST'
docker-combine:stable:
extends: .docker-combine
only:
- stable@pleroma/pleroma
script:
- 'docker manifest create $IMAGE_TAG $IMAGES'
- 'docker manifest push $IMAGE_TAG'
- 'docker manifest create $IMAGE_TAG_SLUG $IMAGES_SLUG'
- 'docker manifest push $IMAGE_TAG_SLUG'
- 'docker manifest create $IMAGE_TAG_LATEST_STABLE $IMAGES_LATEST_STABLE'
- 'docker manifest push $IMAGE_TAG_LATEST_STABLE'
docker-combine:release:
extends: .docker-combine
only:
- /^release/.*$/@pleroma/pleroma
script:
- 'docker manifest create $IMAGE_TAG $IMAGES'
- 'docker manifest push $IMAGE_TAG'
- 'docker manifest create $IMAGE_TAG_SLUG $IMAGES_SLUG'
- 'docker manifest push $IMAGE_TAG_SLUG'

View file

@ -1,2 +0,0 @@
elixir 1.13
erlang 24.3.4.2

View file

@ -1,61 +1,57 @@
FROM ubuntu:22.04 as build
ARG ELIXIR_IMG=hexpm/elixir
ARG ELIXIR_VER=1.12.3
ARG ERLANG_VER=24.2.1
ARG ALPINE_VER=3.17.0
ARG MIX_ENV=prod \
OAUTH_CONSUMER_STRATEGIES="twitter facebook google microsoft slack github keycloak:ueberauth_keycloak_strategy"
FROM ${ELIXIR_IMG}:${ELIXIR_VER}-erlang-${ERLANG_VER}-alpine-${ALPINE_VER} as build
WORKDIR /src
COPY . .
RUN apt-get update &&\
apt-get install -y git elixir erlang-dev erlang-nox build-essential cmake libssl-dev libmagic-dev automake autoconf libncurses5-dev &&\
mix local.hex --force &&\
mix local.rebar --force
ENV MIX_ENV=prod
COPY . /src
RUN apk add git gcc g++ musl-dev make cmake file-dev &&\
echo "import Config" > config/prod.secret.exs &&\
mix local.hex --force &&\
mix local.rebar --force &&\
mix deps.get --only prod &&\
mkdir release &&\
mix release --path release
RUN cd /src &&\
mix deps.get --only prod &&\
mkdir release &&\
mix release --path release
FROM ubuntu:22.04
FROM alpine:${ALPINE_VER}
ARG BUILD_DATE
ARG VCS_REF
ARG DEBIAN_FRONTEND="noninteractive"
ENV TZ="Etc/UTC"
LABEL maintainer="hello@soapbox.pub" \
org.opencontainers.image.title="rebased" \
org.opencontainers.image.description="Rebased" \
org.opencontainers.image.authors="hello@soapbox.pub" \
org.opencontainers.image.vendor="soapbox.pub" \
org.opencontainers.image.documentation="https://gitlab.com/soapbox-pub/rebased" \
LABEL maintainer="ops@pleroma.social" \
org.opencontainers.image.title="pleroma" \
org.opencontainers.image.description="Pleroma for Docker" \
org.opencontainers.image.authors="ops@pleroma.social" \
org.opencontainers.image.vendor="pleroma.social" \
org.opencontainers.image.documentation="https://git.pleroma.social/pleroma/pleroma" \
org.opencontainers.image.licenses="AGPL-3.0" \
org.opencontainers.image.url="https://soapbox.pub" \
org.opencontainers.image.url="https://pleroma.social" \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.created=$BUILD_DATE
ARG HOME=/opt/pleroma
ARG DATA=/var/lib/pleroma
RUN apt-get update &&\
apt-get install -y --no-install-recommends curl ca-certificates imagemagick libmagic-dev ffmpeg libimage-exiftool-perl libncurses5 postgresql-client fasttext &&\
adduser --system --shell /bin/false --home ${HOME} pleroma &&\
mkdir -p ${DATA}/uploads &&\
mkdir -p ${DATA}/static &&\
chown -R pleroma ${DATA} &&\
mkdir -p /etc/pleroma &&\
chown -R pleroma /etc/pleroma &&\
mkdir -p /usr/share/fasttext &&\
curl -L https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz -o /usr/share/fasttext/lid.176.ftz &&\
chmod 0644 /usr/share/fasttext/lid.176.ftz
RUN apk update &&\
apk add exiftool ffmpeg imagemagick libmagic ncurses postgresql-client &&\
adduser --system --shell /bin/false --home ${HOME} pleroma &&\
mkdir -p ${DATA}/uploads &&\
mkdir -p ${DATA}/static &&\
chown -R pleroma ${DATA} &&\
mkdir -p /etc/pleroma &&\
chown -R pleroma /etc/pleroma
USER pleroma
COPY --from=build --chown=pleroma:0 /src/release ${HOME}
COPY --from=build --chown=pleroma:0 /release ${HOME}
COPY --chown=pleroma --chmod=640 ./config/docker.exs /etc/pleroma/config.exs
COPY ./docker-entrypoint.sh ${HOME}
EXPOSE 4000
ENTRYPOINT ["/opt/pleroma/docker-entrypoint.sh"]

View file

@ -1,33 +1,58 @@
# Rebased
<img src="https://git.pleroma.social/pleroma/pleroma/uploads/8cec84f5a084d887339f57deeb8a293e/pleroma-banner-vector-nopad-notext.svg" width="300px" />
![Rebased](rebased.png)
## About
**Rebased** is a Fediverse backend written in Elixir.
It's compatible with the Mastodon API and is the recommended backend for Soapbox.
Pleroma is a microblogging server software that can federate (= exchange messages with) other servers that support ActivityPub. What that means is that you can host a server for yourself or your friends and stay in control of your online identity, but still exchange messages with people on larger servers. Pleroma will federate with all servers that implement ActivityPub, like Friendica, GNU Social, Hubzilla, Mastodon, Misskey, Peertube, and Pixelfed.
## Your social media server
Pleroma is written in Elixir and uses PostgresSQL for data storage. It's efficient enough to be ran on low-power devices like Raspberry Pi (though we wouldn't recommend storing the database on the internal SD card ;) but can scale well when ran on more powerful hardware (albeit only single-node for now).
Rebased empowers people to take control of their social media experience.
Hosting your own server means that *you* get to decide the rules.
For clients it supports the [Mastodon client API](https://docs.joinmastodon.org/api/guidelines/) with Pleroma extensions (see the API section on <https://docs-develop.pleroma.social>).
Rebased connects to over 4,000 other servers on the Fediverse.
It is designed to spread your message far and wide, while being resilient to deplatforming.
- [Client Applications for Pleroma](https://docs-develop.pleroma.social/backend/clients/)
## Installation
See [the installation guide](https://soapbox.pub/install/).
### OTP releases (Recommended)
If you are running Linux (glibc or musl) on x86/arm, the recommended way to install Pleroma is by using OTP releases. OTP releases are as close as you can get to binary releases with Erlang/Elixir. The release is self-contained, and provides everything needed to boot it. The installation instructions are available [here](https://docs-develop.pleroma.social/backend/installation/otp_en/).
## License
### From Source
If your platform is not supported, or you just want to be able to edit the source code easily, you may install Pleroma from source.
Rebased is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
- [Alpine Linux](https://docs-develop.pleroma.social/backend/installation/alpine_linux_en/)
- [Arch Linux](https://docs-develop.pleroma.social/backend/installation/arch_linux_en/)
- [CentOS 7](https://docs-develop.pleroma.social/backend/installation/centos7_en/)
- [Debian-based](https://docs-develop.pleroma.social/backend/installation/debian_based_en/)
- [Debian-based (jp)](https://docs-develop.pleroma.social/backend/installation/debian_based_jp/)
- [FreeBSD](https://docs-develop.pleroma.social/backend/installation/freebsd_en/)
- [Gentoo Linux](https://docs-develop.pleroma.social/backend/installation/gentoo_en/)
- [NetBSD](https://docs-develop.pleroma.social/backend/installation/netbsd_en/)
- [OpenBSD](https://docs-develop.pleroma.social/backend/installation/openbsd_en/)
- [OpenBSD (fi)](https://docs-develop.pleroma.social/backend/installation/openbsd_fi/)
Rebased is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
### OS/Distro packages
Currently Pleroma is packaged for [YunoHost](https://yunohost.org), [NixOS](https://nixos.org), [Gentoo through GURU](https://gentoo.org/) and [Archlinux through AUR](https://aur.archlinux.org/packages/pleroma). You may find more at <https://repology.org/project/pleroma/versions>.
If you want to package Pleroma for any OS/Distros, we can guide you through the process on our [community channels](#community-channels). If you want to change default options in your Pleroma package, please **discuss it with us first**.
You should have received a copy of the GNU Affero General Public License
along with Rebased. If not, see <https://www.gnu.org/licenses/>.
### Docker
While we dont provide docker files, other people have written very good ones. Take a look at <https://github.com/angristan/docker-pleroma> or <https://glitch.sh/sn0w/pleroma-docker>.
### Raspberry Pi
Community maintained Raspberry Pi image that you can flash and run Pleroma on your Raspberry Pi. Available here <https://github.com/guysoft/PleromaPi>.
### Compilation Troubleshooting
If you ever encounter compilation issues during the updating of Pleroma, you can try these commands and see if they fix things:
- `mix deps.clean --all`
- `mix local.rebar`
- `mix local.hex`
- `rm -r _build`
If you are not developing Pleroma, it is better to use the OTP release, which comes with everything precompiled.
## Documentation
- Latest Released revision: <https://docs.pleroma.social>
- Latest Git revision: <https://docs-develop.pleroma.social>
## Community Channels
* IRC: **#pleroma** and **#pleroma-dev** on libera.chat, webchat is available at <https://irc.pleroma.social>
* Matrix: [#pleroma:libera.chat](https://matrix.to/#/#pleroma:libera.chat) and [#pleroma-dev:libera.chat](https://matrix.to/#/#pleroma-dev:libera.chat)

View file

@ -3,6 +3,6 @@ FROM elixir:1.12.3
# Single RUN statement, otherwise intermediate images are created
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
RUN apt-get update &&\
apt-get install -y libmagic-dev cmake libimage-exiftool-perl ffmpeg &&\
mix local.hex --force &&\
mix local.rebar --force
apt-get install -y libmagic-dev cmake libimage-exiftool-perl ffmpeg &&\
mix local.hex --force &&\
mix local.rebar --force

12
ci/README Normal file
View file

@ -0,0 +1,12 @@
## Dependencies
Assuming an AMD64 Alpine system, you're going to need the following packages
- `qemu qemu-openrc qemu-arm qemu-aarch64` for binfmt
- `docker-cli-buildx` for building the images
## Setting up
```
docker login git.pleroma.social:5050
doas rc-service qemu-binfmt start
```

View file

@ -1 +1 @@
docker build -t gitlab.com/soapbox-pub/rebased/ci:latest --push .
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t git.pleroma.social:5050/pleroma/pleroma/ci-base:latest --push .

View file

@ -170,7 +170,7 @@
description: "Pleroma: An efficient and flexible fediverse server",
short_description: "",
background_image: "/images/city.jpg",
instance_thumbnail: "/instance/thumbnail.png",
instance_thumbnail: "/instance/thumbnail.jpeg",
favicon: "/favicon.png",
limit: 5_000,
description_limit: 5_000,
@ -188,7 +188,7 @@
registrations_open: true,
invites_enabled: false,
account_activation_required: false,
account_approval_required: true,
account_approval_required: false,
federating: true,
federation_incoming_replies_max_depth: 100,
federation_reachability_timeout_days: 7,
@ -257,22 +257,7 @@
:emoji_manage_emoji,
:statistics_read
],
moderator_privileges: [
:users_read,
:users_manage_invites,
:users_manage_activation_state,
:users_manage_tags,
:users_manage_credentials,
:users_delete,
:messages_read,
:messages_delete,
:instances_delete,
:reports_manage_reports,
:moderation_log_read,
:announcements_manage_announcements,
:emoji_manage_emoji,
:statistics_read
],
moderator_privileges: [:messages_delete, :reports_manage_reports],
max_endorsed_users: 20,
birthday_required: false,
birthday_min_age: 0,
@ -305,7 +290,9 @@
}
config :pleroma, :markup,
allow_inline_images: false,
# XXX - unfortunately, inline images must be enabled by default right now, because
# of custom emoji. Issue #275 discusses defanging that somehow.
allow_inline_images: true,
allow_headings: false,
allow_tables: false,
allow_fonts: false,
@ -375,8 +362,7 @@
follow_handshake_timeout: 500,
note_replies_output_limit: 5,
sign_object_fetches: true,
authorized_fetch_mode: false,
fetch_actor_origin: nil
authorized_fetch_mode: false
config :pleroma, :streamer,
workers: 3,
@ -924,7 +910,7 @@
{Pleroma.Webhook.Notify, [max_running: 5, max_waiting: 200]}
]
config :pleroma, Pleroma.Web.WebFinger, domain: nil, update_nickname_on_user_fetch: false
config :pleroma, Pleroma.Web.WebFinger, domain: nil, update_nickname_on_user_fetch: true
config :pleroma, Pleroma.Language.Translation, allow_unauthenticated: false, allow_remote: true

View file

@ -58,13 +58,6 @@
# https://dashbit.co/blog/speeding-up-re-compilation-of-elixir-projects
config :phoenix, :plug_init_mode, :runtime
config :pleroma, Pleroma.PromEx,
disabled: false,
manual_metrics_start_delay: :no_delay,
drop_metrics_groups: [],
grafana: :disabled,
metrics_server: :disabled
if File.exists?("./config/dev.secret.exs") do
import_config "dev.secret.exs"
else

View file

@ -2,29 +2,24 @@
config :pleroma, Pleroma.Web.Endpoint,
url: [host: System.get_env("DOMAIN", "localhost"), scheme: "https", port: 443],
http: [ip: {0, 0, 0, 0}, port: System.get_env("PORT", "5000")]
http: [ip: {0, 0, 0, 0}, port: 4000]
config :pleroma, :instance,
name: System.get_env("INSTANCE_NAME", "Soapbox"),
name: System.get_env("INSTANCE_NAME", "Pleroma"),
email: System.get_env("ADMIN_EMAIL"),
notify_email: System.get_env("NOTIFY_EMAIL"),
limit: 5000,
registrations_open: false,
healthcheck: true
# Prefer `DATABASE_URL` if set, otherwise use granular env.
case System.get_env("DATABASE_URL") do
database_url when is_binary(database_url) ->
config :pleroma, Pleroma.Repo, url: database_url
_ ->
config :pleroma, Pleroma.Repo,
username: System.get_env("DB_USER", "postgres"),
password: System.get_env("DB_PASS", "postgres"),
database: System.get_env("DB_NAME", "postgres"),
hostname: System.get_env("DB_HOST", "db"),
port: System.get_env("DB_PORT", "5432")
end
config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("DB_USER", "pleroma"),
password: System.fetch_env!("DB_PASS"),
database: System.get_env("DB_NAME", "pleroma"),
hostname: System.get_env("DB_HOST", "db"),
port: System.get_env("DB_PORT", "5432"),
pool_size: 10
# Configure web push notifications
config :web_push_encryption, :vapid_details, subject: "mailto:#{System.get_env("NOTIFY_EMAIL")}"

View file

@ -23,24 +23,6 @@
config :logger, :console, level: :info
config :logger, :ex_syslogger, level: :info
# PromEx set up
config :pleroma, Pleroma.Web.Plugs.MetricsPredicate,
auth_token: System.get_env("PROMETHEUS_AUTH_TOKEN", "supersecret")
config :pleroma, Pleroma.PromEx,
prometheus_data_source_id:
System.get_env(
"PROMETHEUS_DATASOURCE_ID",
"Prometheus"
),
grafana: [
host: System.get_env("GRAFANA_HOST", "http://localhost:3000"),
auth_token: System.get_env("GRAFANA_AUTH_TOKEN", "LOLNO"),
upload_dashboards_on_start: true,
folder_name: "Pleroma - PromEx",
annotate_app_lifecycle: true
]
# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
@ -81,16 +63,11 @@
# Finally import the config/prod.secret.exs
# which should be versioned separately.
cond do
File.exists?("./config/prod.secret.exs") ->
import_config "prod.secret.exs"
System.get_env("CI") == "true" ->
nil
true ->
"`config/prod.secret.exs` not found. You may want to create one by running `mix pleroma.instance gen`"
|> IO.warn([])
if File.exists?("./config/prod.secret.exs") do
import_config "prod.secret.exs"
else
"`config/prod.secret.exs` not found. You may want to create one by running `mix pleroma.instance gen`"
|> IO.warn([])
end
if File.exists?("./config/prod.exported_from_db.secret.exs"),

View file

@ -49,10 +49,30 @@
config :pleroma, :instance,
name: "Soapbox",
description: "Social media owned by you",
instance_thumbnail: "/instance/thumbnail.png"
instance_thumbnail: "/instance/thumbnail.png",
account_approval_required: true,
moderator_privileges: [
:users_read,
:users_manage_invites,
:users_manage_activation_state,
:users_manage_tags,
:users_manage_credentials,
:users_delete,
:messages_read,
:messages_delete,
:instances_delete,
:reports_manage_reports,
:moderation_log_read,
:announcements_manage_announcements,
:emoji_manage_emoji,
:statistics_read
]
# Background migration performance
config :pleroma, :delete_context_objects, sleep_interval_ms: 3_000
config :pleroma, :markup,
allow_inline_images: false
# Pretend to be WhatsApp because some sites don't return link previews otherwise
config :pleroma, :rich_media, user_agent: "WhatsApp/2"

View file

@ -1,11 +1,9 @@
#!/bin/bash
#!/bin/ash
set -e
DATABASE_URL=${DATABASE_URL:-"postgres://${DB_USER:-postgres}:${DB_PASS:-postgres}@${DB_HOST:-db}:5432/${DB_NAME:-postgres}"}
echo "-- Waiting for database..."
while ! pg_isready -d $DATABASE_URL -t 1; do
while ! pg_isready -U ${DB_USER:-pleroma} -d postgres://${DB_HOST:-db}:${DB_PORT:-5432}/${DB_NAME:-pleroma} -t 1; do
sleep 1s
done

View file

@ -1,4 +0,0 @@
# Rebased
**Rebased** is a Fediverse backend written in Elixir.
It's compatible with the Mastodon API and is the recommended backend for Soapbox.

View file

@ -18,8 +18,7 @@ Environment="HOME=/var/lib/pleroma"
; Path to the folder containing the Pleroma installation.
WorkingDirectory=/opt/pleroma
; Path to the Mix binary.
Environment="PATH=/var/lib/pleroma/.asdf/shims:/var/lib/pleroma/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/var/lib/pleroma/.asdf/shims/mix phx.server
ExecStart=/usr/bin/mix phx.server
; Some security directives.
; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops.

View file

@ -60,7 +60,7 @@ def run(["gen" | rest]) do
get_option(
options,
:domain,
"What domain will your instance use? (e.g mysite.com)"
"What domain will your instance use? (e.g pleroma.soykaf.com)"
),
":"
) ++ [443]
@ -69,7 +69,7 @@ def run(["gen" | rest]) do
get_option(
options,
:instance_name,
"What is the name of your instance? (e.g. Our Wonderful Community)",
"What is the name of your instance? (e.g. The Corndog Emporium)",
domain
)

View file

@ -94,7 +94,6 @@ def start(_type, _args) do
# Define workers and child supervisors to be supervised
children =
[
Pleroma.PromEx,
Pleroma.Repo,
Config.TransferTask,
Pleroma.Emoji,

View file

@ -278,6 +278,10 @@ def update_and_set_cache(changeset) do
end
end
defp poll_is_multiple?(%Object{data: %{"anyOf" => [_ | _]}}), do: true
defp poll_is_multiple?(_), do: false
def increase_replies_count(ap_id) do
Object
|> where([o], fragment("?->>'id' = ?::text", o.data, ^to_string(ap_id)))
@ -370,10 +374,6 @@ def decrease_quotes_count(ap_id) do
end
end
defp poll_is_multiple?(%Object{data: %{"anyOf" => [_ | _]}}), do: true
defp poll_is_multiple?(_), do: false
def increase_vote_count(ap_id, name, actor) do
with %Object{} = object <- Object.normalize(ap_id, fetch: false),
"Question" <- object.data["type"] do

View file

@ -1,90 +0,0 @@
defmodule Pleroma.PromEx do
@moduledoc """
Be sure to add the following to finish setting up PromEx:
1. Update your configuration (config.exs, dev.exs, prod.exs, releases.exs, etc) to
configure the necessary bit of PromEx. Be sure to check out `PromEx.Config` for
more details regarding configuring PromEx:
```
config :pleroma, Pleroma.PromEx,
disabled: false,
manual_metrics_start_delay: :no_delay,
drop_metrics_groups: [],
grafana: :disabled,
metrics_server: :disabled
```
2. Add this module to your application supervision tree. It should be one of the first
things that is started so that no Telemetry events are missed. For example, if PromEx
is started after your Repo module, you will miss Ecto's init events and the dashboards
will be missing some data points:
```
def start(_type, _args) do
children = [
Pleroma.PromEx,
...
]
...
end
```
3. Update your `endpoint.ex` file to expose your metrics (or configure a standalone
server using the `:metrics_server` config options). Be sure to put this plug before
your `Plug.Telemetry` entry so that you can avoid having calls to your `/metrics`
endpoint create their own metrics and logs which can pollute your logs/metrics given
that Prometheus will scrape at a regular interval and that can get noisy:
```
defmodule PleromaWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :pleroma
...
plug PromEx.Plug, prom_ex_module: Pleroma.PromEx
...
end
```
4. Update the list of plugins in the `plugins/0` function return list to reflect your
application's dependencies. Also update the list of dashboards that are to be uploaded
to Grafana in the `dashboards/0` function.
"""
use PromEx, otp_app: :pleroma
alias PromEx.Plugins
@impl true
def plugins do
[
# PromEx built in plugins
Plugins.Application,
Plugins.Beam,
{Plugins.Phoenix, router: Pleroma.Web.Router, endpoint: Pleroma.Web.Endpoint},
Plugins.Ecto,
Plugins.Oban
]
end
@impl true
def dashboard_assigns do
[
datasource_id: "Prometheus",
default_selected_interval: "1m"
]
end
@impl true
def dashboards do
[
# PromEx built in Grafana dashboards
{:prom_ex, "application.json"},
{:prom_ex, "beam.json"},
{:prom_ex, "phoenix.json"},
{:prom_ex, "ecto.json"},
{:prom_ex, "oban.json"}
]
end
end

View file

@ -152,7 +152,6 @@ defmodule Pleroma.User do
field(:accepts_chat_messages, :boolean, default: nil)
field(:last_active_at, :naive_datetime)
field(:disclose_client, :boolean, default: true)
field(:accepts_email_list, :boolean, default: false)
field(:pinned_objects, :map, default: %{})
field(:is_suggested, :boolean, default: false)
field(:last_status_at, :naive_datetime)
@ -579,7 +578,6 @@ def update_changeset(struct, params \\ %{}) do
:actor_type,
:accepts_chat_messages,
:disclose_client,
:accepts_email_list,
:birthday,
:show_birthday,
:location
@ -767,8 +765,7 @@ def register_changeset_ldap(struct, params = %{password: password})
:name,
:nickname,
:email,
:accepts_chat_messages,
:accepts_email_list
:accepts_chat_messages
])
|> validate_required([:name, :nickname])
|> unique_constraint(:nickname)
@ -814,7 +811,6 @@ def register_changeset(struct, params \\ %{}, opts \\ []) do
:emoji,
:accepts_chat_messages,
:registration_reason,
:accepts_email_list,
:birthday,
:language
])
@ -1973,8 +1969,7 @@ def purge_user_changeset(user) do
fields: [],
raw_fields: [],
is_discoverable: false,
also_known_as: [],
accepts_email_list: false
also_known_as: []
# id: preserved
# ap_id: preserved
# nickname: preserved

View file

@ -1,70 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.EmailList do
@moduledoc """
Functions for generating email lists from local users.
"""
import Ecto.Query
alias Pleroma.Repo
alias Pleroma.User
@header_row ["Email Address", "Nickname", "Subscribe?"]
defp query(:subscribers) do
User.Query.build(%{
local: true,
active: true,
accepts_email_list: true
})
|> where([u], not is_nil(u.email))
end
defp query(:unsubscribers) do
User.Query.build(%{
local: true,
accepts_email_list: false
})
|> where([u], not is_nil(u.email))
end
defp query(:combined) do
User.Query.build(%{
local: true
})
|> where([u], not is_nil(u.email))
end
def generate_csv(audience) when is_atom(audience) do
audience
|> query()
|> generate_csv()
end
def generate_csv(%Ecto.Query{} = query) do
query
|> Repo.all()
|> Enum.map(&build_row/1)
|> build_csv()
end
defp subscribe?(%User{} = user) do
user.accepts_email_list && user.is_active && user.is_approved && user.is_confirmed
end
defp build_row(%User{} = user) do
[
user.email,
user.nickname,
subscribe?(user)
]
end
defp build_csv(lines) do
[@header_row | lines]
|> CSV.encode()
|> Enum.join()
end
end

View file

@ -131,10 +131,6 @@ defp compose_query({:is_moderator, bool}, query) do
where(query, [u], u.is_moderator == ^bool)
end
defp compose_query({:accepts_email_list, bool}, query) do
where(query, [u], u.accepts_email_list == ^bool)
end
defp compose_query({:super_users, _}, query) do
where(
query,

View file

@ -334,16 +334,8 @@ def relay(conn, _params) do
|> represent_service_actor(conn)
end
def internal_fetch(%Plug.Conn{host: host} = conn, _params) do
with fetch_actor_origin when is_binary(fetch_actor_origin) <-
Pleroma.Config.get([:activitypub, :fetch_actor_origin]),
%URI{host: fetch_actor_host} <- URI.parse(fetch_actor_origin),
true <- host == fetch_actor_host do
fetch_actor_origin
else
_ -> Pleroma.Web.Endpoint.url()
end
|> InternalFetchActor.get_actor()
def internal_fetch(conn, _params) do
InternalFetchActor.get_actor()
|> represent_service_actor(conn)
end

View file

@ -11,24 +11,10 @@ def init do
# Wait for everything to settle.
Process.sleep(1000 * 5)
get_actor()
get_actor(Pleroma.Web.Endpoint.url())
end
def get_actor(origin) do
%URI{host: host} = URI.parse(origin)
nickname =
cond do
host == Pleroma.Web.Endpoint.host() -> "internal.fetch"
true -> "internal.fetch@#{host}"
end
"#{origin}/internal/fetch"
|> User.get_or_create_service_actor_by_ap_id(nickname)
end
def get_actor() do
(Pleroma.Config.get([:activitypub, :fetch_actor_origin]) || Pleroma.Web.Endpoint.url())
|> get_actor()
def get_actor do
"#{Pleroma.Web.Endpoint.url()}/internal/fetch"
|> User.get_or_create_service_actor_by_ap_id("internal.fetch")
end
end

View file

@ -1,35 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.EmailListController do
use Pleroma.Web, :controller
alias Pleroma.User.EmailList
alias Pleroma.Web.Plugs.OAuthScopesPlug
require Logger
plug(OAuthScopesPlug, %{scopes: ["admin:read:accounts"]})
def subscribers(conn, _params) do
render_csv(conn, :subscribers)
end
def unsubscribers(conn, _params) do
render_csv(conn, :unsubscribers)
end
def combined(conn, _params) do
render_csv(conn, :combined)
end
defp render_csv(conn, audience) when is_atom(audience) do
csv = EmailList.generate_csv(audience)
conn
|> put_resp_content_type("text/csv")
|> resp(200, csv)
|> send_resp()
end
end

View file

@ -616,11 +616,6 @@ defp create_request do
nullable: true,
description: "Invite token required when the registrations aren't public"
},
accepts_email_list: %Schema{
allOf: [BooleanLike],
description:
"Whether the user opts-in to receiving news and marketing updates from site admins."
},
birthday: %Schema{
nullable: true,
description: "User's birthday",
@ -817,11 +812,6 @@ defp update_credentials_request do
"Discovery (listing, indexing) of this account by external services (search bots etc.) is allowed."
},
actor_type: ActorType,
accepts_email_list: %Schema{
allOf: [BooleanLike],
description:
"Whether the user opts-in to receiving news and marketing updates from site admins."
},
birthday: %Schema{
nullable: true,
description: "User's birthday",

View file

@ -11,11 +11,6 @@ defmodule Pleroma.Web.Endpoint do
socket("/live", Phoenix.LiveView.Socket)
plug(Unplug,
if: Pleroma.Web.Plugs.MetricsPredicate,
do: {PromEx.Plug, path: "/api/metrics", prom_ex_module: Pleroma.PromEx}
)
plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
plug(Pleroma.Web.Plugs.SetLocalePlug)

View file

@ -194,7 +194,6 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
:allow_following_move,
:also_known_as,
:accepts_chat_messages,
:accepts_email_list,
:show_birthday
]
|> Enum.reduce(%{}, fn key, acc ->

View file

@ -330,7 +330,6 @@ defp do_render("show.json", %{user: user} = opts) do
|> maybe_put_allow_following_move(user, opts[:for])
|> maybe_put_unread_conversation_count(user, opts[:for])
|> maybe_put_unread_notification_count(user, opts[:for])
|> maybe_put_accepts_email_list(user, opts[:for])
|> maybe_put_email_address(user, opts[:for])
|> maybe_put_mute_expires_at(user, opts[:for], opts)
|> maybe_show_birthday(user, opts[:for])
@ -449,16 +448,6 @@ defp maybe_put_unread_notification_count(data, %User{id: user_id}, %User{id: use
defp maybe_put_unread_notification_count(data, _, _), do: data
defp maybe_put_accepts_email_list(data, %User{id: user_id}, %User{id: user_id} = user) do
Kernel.put_in(
data,
[:pleroma, :accepts_email_list],
user.accepts_email_list
)
end
defp maybe_put_accepts_email_list(data, _, _), do: data
defp maybe_put_email_address(data, %User{id: user_id}, %User{id: user_id} = user) do
Kernel.put_in(
data,

View file

@ -153,8 +153,8 @@ def features do
"shareable_emoji_packs",
"multifetch",
"pleroma:api/v1/notifications:include_types_filter",
"quote_posting",
"editing",
"quote_posting",
if Config.get([:activitypub, :blockers_visible]) do
"blockers_visible"
end,
@ -173,7 +173,6 @@ def features do
"pleroma_emoji_reactions",
"pleroma_custom_emoji_reactions",
"pleroma_chat_messages",
"email_list",
if Config.get([:instance, :show_reactions]) do
"exposable_reactions"
end,

View file

@ -304,6 +304,16 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
reply_to = get_reply_to(activity, opts)
reply_to_user = reply_to && CommonAPI.get_user(reply_to.data["actor"])
history_len =
1 +
(Object.Updater.history_for(object.data)
|> Map.get("orderedItems")
|> length())
# See render("history.json", ...) for more details
# Here the implicit index of the current content is 0
chrono_order = history_len - 1
quote_activity = get_quote(activity, opts)
quote_id =
@ -320,16 +330,6 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
nil
end
history_len =
1 +
(Object.Updater.history_for(object.data)
|> Map.get("orderedItems")
|> length())
# See render("history.json", ...) for more details
# Here the implicit index of the current content is 0
chrono_order = history_len - 1
content =
object
|> render_content()

View file

@ -1,29 +0,0 @@
defmodule Pleroma.Web.Plugs.MetricsPredicate do
@moduledoc """
This Unplug predicate is used to authorize requests to the PromEx metrics
"""
@behaviour Unplug.Predicate
@impl true
def call(conn, _) do
conn
|> Plug.Conn.get_req_header("authorization")
|> case do
["Bearer " <> token] ->
token == get_configured_auth_token()
[] ->
get_configured_auth_token() == :disabled
_ ->
false
end
end
defp get_configured_auth_token do
:pleroma
|> Application.get_env(__MODULE__, auth_token: "super_secret")
|> Keyword.get(:auth_token)
end
end

View file

@ -293,10 +293,6 @@ defmodule Pleroma.Web.Router do
post("/backups", AdminAPIController, :create_backup)
get("/email_list/subscribers.csv", EmailListController, :subscribers)
get("/email_list/unsubscribers.csv", EmailListController, :unsubscribers)
get("/email_list/combined.csv", EmailListController, :combined)
get("/rules", RuleController, :index)
post("/rules", RuleController, :create)
patch("/rules/:id", RuleController, :update)
@ -705,10 +701,6 @@ defmodule Pleroma.Web.Router do
scope [] do
pipe_through([:admin_api, :require_admin])
get("/email_list/subscribers.csv", EmailListController, :subscribers)
get("/email_list/unsubscribers.csv", EmailListController, :unsubscribers)
get("/email_list/combined.csv", EmailListController, :combined)
get("/rules", RuleController, :index)
post("/rules", RuleController, :create)
patch("/rules/:id", RuleController, :update)

View file

@ -16,7 +16,7 @@ def register_user(params, opts \\ []) do
params =
params
|> Map.take([:email, :token, :password, :accepts_email_list])
|> Map.take([:email, :token, :password])
|> Map.put(:bio, params |> Map.get(:bio, "") |> User.parse_bio())
|> Map.put(:nickname, params[:username])
|> Map.put(:name, Map.get(params, :fullname, params[:username]))

18
mix.exs
View file

@ -19,11 +19,11 @@ def project do
deps: deps(),
test_coverage: [tool: :covertool, summary: true],
# Docs
homepage_url: "https://soapbox.pub/",
source_url: "https://gitlab.com/soapbox-pub/rebased",
homepage_url: "https://github.com/mkljczk/pleroma",
source_url: "https://github.com/mkljczk/pleroma",
docs: [
source_url_pattern:
"https://gitlab.com/soapbox-pub/rebased/blob/develop/%{path}#L%{line}",
"https://github.com/mkljczk/pleroma/blob/develop/%{path}#L%{line}",
logo: "priv/static/images/logo.png",
extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"),
groups_for_extras: [
@ -117,12 +117,10 @@ defp oauth_deps do
defp deps do
[
{:phoenix, "~> 1.7.3"},
{:tzdata, "~> 1.0.3"},
{:plug_cowboy, "~> 2.6.1"},
{:phoenix_pubsub, "~> 2.0"},
{:phoenix_ecto, "~> 4.4.0"},
{:ecto_enum, "~> 1.4"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.10"},
{:phoenix_pubsub, "~> 2.0"},
{:ecto_enum, "~> 1.4"},
{:postgrex, ">= 0.15.5"},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_reload, "~> 1.3.3", only: :dev},
@ -130,6 +128,8 @@ defp deps do
{:phoenix_live_dashboard, "~> 0.8.0"},
{:telemetry_metrics, "~> 0.6"},
{:telemetry_poller, "~> 1.0"},
{:tzdata, "~> 1.0.3"},
{:plug_cowboy, "~> 2.6.1"},
# oban 2.14 requires Elixir 1.12+
{:oban, "~> 2.13.4"},
{:gettext, "~> 0.20"},
@ -203,8 +203,6 @@ defp deps do
{:ecto_psql_extras, "~> 0.6"},
{:icalendar, "~> 1.1"},
{:geospatial, "~> 0.2.0"},
{:prom_ex, "~> 1.8.0"},
{:unplug, "~> 1.0"},
## dev & test
{:ex_doc, "~> 0.22", only: :dev, runtime: false},

View file

@ -1,9 +0,0 @@
defmodule Pleroma.Repo.Migrations.AddEmailListFieldToUsers do
use Ecto.Migration
def change do
alter table(:users) do
add(:accepts_email_list, :boolean, default: false)
end
end
end

View file

@ -40,9 +40,9 @@
"@type": "@id"
},
"vcard": "http://www.w3.org/2006/vcard/ns#",
"formerRepresentations": "litepub:formerRepresentations",
"sm": "http://smithereen.software/ns#",
"nonAnonymous": "sm:nonAnonymous",
"formerRepresentations": "litepub:formerRepresentations",
"votersCount": "toot:votersCount",
"mz": "https://joinmobilizon.org/ns#",
"joinMode": {

View file

@ -1,66 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User.EmailListTest do
alias Pleroma.User.EmailList
use Pleroma.DataCase
import Pleroma.Factory
@tag :erratic
test "generate_csv/1 with :subscribers" do
user1 = insert(:user, accepts_email_list: true)
user2 = insert(:user, accepts_email_list: true)
user3 = insert(:user, accepts_email_list: true)
insert(:user, accepts_email_list: false)
expected = """
Email Address,Nickname,Subscribe?\r
#{user1.email},#{user1.nickname},true\r
#{user2.email},#{user2.nickname},true\r
#{user3.email},#{user3.nickname},true\r
"""
assert EmailList.generate_csv(:subscribers) == expected
end
@tag :erratic
test "generate_csv/1 with :unsubscribers" do
user1 = insert(:user, accepts_email_list: false)
user2 = insert(:user, accepts_email_list: false)
insert(:user, accepts_email_list: true)
insert(:user, accepts_email_list: true)
expected = """
Email Address,Nickname,Subscribe?\r
#{user1.email},#{user1.nickname},false\r
#{user2.email},#{user2.nickname},false\r
"""
assert EmailList.generate_csv(:unsubscribers) == expected
end
@tag :erratic
test "generate_csv/1 with :combined" do
user1 = insert(:user, accepts_email_list: true, is_active: false)
user2 = insert(:user, accepts_email_list: true)
user3 = insert(:user, accepts_email_list: true, is_approved: false)
user4 = insert(:user, accepts_email_list: true, is_confirmed: false)
user5 = insert(:user, accepts_email_list: true)
user6 = insert(:user, accepts_email_list: false)
expected = """
Email Address,Nickname,Subscribe?\r
#{user1.email},#{user1.nickname},false\r
#{user2.email},#{user2.nickname},true\r
#{user3.email},#{user3.nickname},false\r
#{user4.email},#{user4.nickname},false\r
#{user5.email},#{user5.nickname},true\r
#{user6.email},#{user6.nickname},false\r
"""
assert EmailList.generate_csv(:combined) == expected
end
end

View file

@ -722,16 +722,6 @@ test "it creates a confirmed user" do
assert user.is_confirmed
end
test "it sets 'accepts_email_list'" do
params = Map.put_new(@full_user_data, :accepts_email_list, true)
changeset = User.register_changeset(%User{}, params)
assert changeset.valid?
{:ok, user} = Repo.insert(changeset)
assert user.accepts_email_list
end
test_with_mock "triggers webhooks", Notify, trigger_webhooks: fn _, _ -> nil end do
cng = User.register_changeset(%User{}, @full_user_data)
@ -813,17 +803,6 @@ test "it restricts length of registration reason" do
end
end
describe "update_changeset/2" do
test "it sets :accepts_email_list" do
changeset =
%User{accepts_email_list: false}
|> User.update_changeset(%{accepts_email_list: true})
assert changeset.valid?
assert %User{accepts_email_list: true} = Ecto.Changeset.apply_changes(changeset)
end
end
describe "user registration, with :birthday_required and :birthday_min_age" do
@full_user_data %{
bio: "A guy",

View file

@ -75,7 +75,7 @@ test "it returns the internal fetch user", %{conn: conn} do
|> get(activity_pub_path(conn, :internal_fetch))
|> json_response(200)
assert res["id"] =~ "http://localhost:4001/internal/fetch"
assert res["id"] =~ "/fetch"
end
test "on non-federating instance, it returns 404", %{conn: conn} do

View file

@ -1,102 +0,0 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.EmailListControllerTest do
use Pleroma.Web.ConnCase, async: true
import Pleroma.Factory
defp admin_setup do
admin = insert(:user, is_admin: true)
token = insert(:oauth_admin_token, user: admin)
conn =
build_conn()
|> assign(:user, admin)
|> assign(:token, token)
{:ok, %{admin: admin, token: token, conn: conn}}
end
defp user_setup do
user = insert(:user)
token = insert(:oauth_token, user: user)
conn =
build_conn()
|> assign(:user, user)
|> assign(:token, token)
{:ok, %{user: user, token: token, conn: conn}}
end
describe "GET /api/v1/pleroma/admin/email_list/subscribers.csv" do
setup do: admin_setup()
test "returns a CSV", %{conn: conn} do
result =
conn
|> get("/api/v1/pleroma/admin/email_list/subscribers.csv")
|> response(200)
assert result
end
end
describe "GET /api/v1/pleroma/admin/email_list/subscribers.csv unauthorized" do
setup do: user_setup()
test "returns 403", %{conn: conn} do
conn
|> get("/api/v1/pleroma/admin/email_list/subscribers.csv")
|> response(403)
end
end
describe "GET /api/v1/pleroma/admin/email_list/unsubscribers.csv" do
setup do: admin_setup()
test "returns a CSV", %{conn: conn} do
result =
conn
|> get("/api/v1/pleroma/admin/email_list/unsubscribers.csv")
|> response(200)
assert result
end
end
describe "GET /api/v1/pleroma/admin/email_list/unsubscribers.csv unauthorized" do
setup do: user_setup()
test "returns 403", %{conn: conn} do
conn
|> get("/api/v1/pleroma/admin/email_list/unsubscribers.csv")
|> response(403)
end
end
describe "GET /api/v1/pleroma/admin/email_list/combined.csv" do
setup do: admin_setup()
test "returns a CSV", %{conn: conn} do
result =
conn
|> get("/api/v1/pleroma/admin/email_list/combined.csv")
|> response(200)
assert result
end
end
describe "GET /api/v1/pleroma/admin/email_list/combined.csv unauthorized" do
setup do: user_setup()
test "returns 403", %{conn: conn} do
conn
|> get("/api/v1/pleroma/admin/email_list/combined.csv")
|> response(403)
end
end
end

View file

@ -1235,7 +1235,7 @@ test "registers and logs in without :account_activation_required / :account_appr
assert user
assert user.is_confirmed
assert user.is_approved
refute user.accepts_email_list
refute user.accepts_
end
test "registers but does not log in with :account_activation_required", %{conn: conn} do
@ -1467,20 +1467,6 @@ test "allow registration with an empty email", %{conn: conn, valid_params: valid
assert json_response_and_validate_schema(res, 200)
end
test "registration with accepts_email_list", %{conn: conn, valid_params: valid_params} do
app_token = insert(:oauth_token, user: nil)
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
res =
conn
|> put_req_header("content-type", "application/json")
|> Map.put(:remote_ip, {127, 0, 0, 9})
|> post("/api/v1/accounts", Map.put(valid_params, :accepts_email_list, true))
assert json_response_and_validate_schema(res, 200)
assert %User{accepts_email_list: true} = Repo.get_by(User, email: "lain@example.org")
end
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
res =
conn

View file

@ -147,13 +147,6 @@ test "updates the user's chat acceptance status", %{conn: conn} do
assert user_data["pleroma"]["accepts_chat_messages"] == false
end
test "updates the user's newsletter preference", %{user: user, conn: conn} do
conn = patch(conn, "/api/v1/accounts/update_credentials", %{accepts_email_list: "true"})
assert json_response_and_validate_schema(conn, 200)
assert %User{accepts_email_list: true} = User.get_by_id(user.id)
end
test "updates the user's allow_following_move", %{user: user, conn: conn} do
assert user.allow_following_move == true

View file

@ -603,23 +603,6 @@ test "shows email only to the account owner" do
end
end
test "shows accepts_email_list only to the account owner" do
user = insert(:user)
other_user = insert(:user)
user = User.get_cached_by_ap_id(user.ap_id)
assert AccountView.render(
"show.json",
%{user: user, for: other_user}
)[:pleroma][:accepts_email_list] == nil
assert AccountView.render(
"show.json",
%{user: user, for: user}
)[:pleroma][:accepts_email_list] == user.accepts_email_list
end
describe "hiding birthday" do
test "doesn't show birthday if hidden" do
user =

View file

@ -339,8 +339,8 @@ test "a note activity" do
emoji_reactions: [],
parent_visible: false,
pinned_at: nil,
content_type: nil,
quotes_count: 0,
content_type: nil,
event: nil
}
}

View file

@ -144,20 +144,6 @@ test "it registers a new user and parses mentions in the bio" do
assert user2.bio == expected_text
end
test "it registers a new user with accepts_email_list." do
data = %{
:username => "lain",
:email => "lain@wired.jp",
:fullname => "lain iwakura",
:password => "bear",
:confirm => "bear",
:accepts_email_list => true
}
{:ok, user} = TwitterAPI.register_user(data)
assert user.accepts_email_list
end
describe "register with one time token" do
setup do: clear_config([:instance, :registrations_open], false)

View file

@ -1371,6 +1371,15 @@ def get("https://patch.cx/objects/a399c28e-c821-4820-bc3e-4afeb044c16f", _, _, _
}}
end
def get("https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json"),
headers: activitypub_object_headers()
}}
end
def get("https://misskey.io/users/83ssedkv53", _, _, _) do
{:ok,
%Tesla.Env{
@ -1401,15 +1410,6 @@ def get("https://mitra.social/objects/01830912-1357-d4c5-e4a2-76eab347e749", _,
}}
end
def get("https://gleasonator.com/objects/102eb097-a18b-4cd5-abfc-f952efcb70bb", _, _, _) do
{:ok,
%Tesla.Env{
status: 200,
body: File.read!("test/fixtures/tesla_mock/gleasonator-AG3RzWfwEKKrY63qj2.json"),
headers: activitypub_object_headers()
}}
end
def get("https://gleasonator.com/users/macgirvin", _, _, _) do
{:ok,
%Tesla.Env{