Skip to content

Commit

Permalink
Merge pull request #88 from repco-org/apex
Browse files Browse the repository at this point in the history
feat: activitypub server
Still having some issues: #94 #95 and docs need to be improved.
  • Loading branch information
flipsimon authored Dec 4, 2023
2 parents bc8f0a4 + d46a87f commit 3ce44bf
Show file tree
Hide file tree
Showing 52 changed files with 16,837 additions and 143 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package-lock.json
.env
SANDBOX
data
yarn.lock
*.0x
packages/repco-frontend/app/styles
packages/*/coverage
1 change: 1 addition & 0 deletions dev/peertube/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-volume
50 changes: 50 additions & 0 deletions dev/peertube/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.3"

services:

peertube:
# If you don't want to use the official image and build one from sources:
# build:
# context: .
# dockerfile: ./support/docker/production/Dockerfile.bullseye
image: chocobozzz/peertube:production-bullseye
env_file:
- .env

ports:
# - "1935:1935" # Comment if you don't want to use the live feature
- "9000:9000" # Uncomment if you use another webserver/proxy or test PeerTube in local, otherwise not suitable for production
volumes:
# - ./docker-volume/assets:/app/client/dist
- ./docker-volume/data:/data
- ./docker-volume/config:/config
depends_on:
- postgres
- redis
# - postfix
restart: "always"
extra_hosts:
- "host.docker.internal:host-gateway"

postgres:
image: postgres:13-alpine
env_file:
- .env
volumes:
- ./docker-volume/db:/var/lib/postgresql/data
restart: "always"

redis:
image: redis:6-alpine
volumes:
- ./docker-volume/redis:/data
restart: "always"

# postfix:
# image: mwader/postfix-relay
# env_file:
# - .env
# volumes:
# - ./docker-volume/opendkim/keys:/etc/opendkim/keys
# restart: "always"

55 changes: 55 additions & 0 deletions dev/peertube/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Database / Postgres service configuration
POSTGRES_USER=peertube
POSTGRES_PASSWORD=peertube
# Postgres database name "peertube"
POSTGRES_DB=peertube
# The database name used by PeerTube will be PEERTUBE_DB_NAME (only if set) *OR* 'peertube'+PEERTUBE_DB_SUFFIX
#PEERTUBE_DB_NAME=<MY POSTGRES DB NAME>
#PEERTUBE_DB_SUFFIX=_prod
# Database username and password used by PeerTube must match Postgres', so they are copied:
PEERTUBE_DB_USERNAME=peertube
PEERTUBE_DB_PASSWORD=peertube
PEERTUBE_DB_SSL=false
# Default to Postgres service name "postgres" in docker-compose.yml
PEERTUBE_DB_HOSTNAME=postgres

# PeerTube server configuration
# If you test PeerTube in local: use "peertube.localhost" and add this domain to your host file resolving on 127.0.0.1
PEERTUBE_WEBSERVER_HOSTNAME=host.docker.internal
# If you just want to test PeerTube on local
PEERTUBE_WEBSERVER_PORT=9000
PEERTUBE_WEBSERVER_HTTPS=false
# If you need more than one IP as trust_proxy
# pass them as a comma separated array:
PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback", "172.18.0.0/16"]

PEERTUBE_LOG_LEVEL="debug"

# Generate one using `openssl rand -hex 32`
PEERTUBE_SECRET=66abdc69a969d9632be098c9bd8814972ca87c93a1bffae00580f228dfc57cd8
PT_INITIAL_ROOT_PASSWORD=peertube
# E-mail configuration
# If you use a Custom SMTP server
#PEERTUBE_SMTP_USERNAME=
#PEERTUBE_SMTP_PASSWORD=
# Default to Postfix service name "postfix" in docker-compose.yml
# May be the hostname of your Custom SMTP server
PEERTUBE_SMTP_HOSTNAME=postfix
PEERTUBE_SMTP_PORT=25
PEERTUBE_SMTP_FROM=noreply@<MY DOMAIN>
PEERTUBE_SMTP_TLS=false
PEERTUBE_SMTP_DISABLE_STARTTLS=false
PEERTUBE_ADMIN_EMAIL=[email protected]

# Postfix service configuration
#POSTFIX_myhostname=localhost
# If you need to generate a list of sub/DOMAIN keys
# pass them as a whitespace separated string <DOMAIN>=<selector>
#OPENDKIM_DOMAINS=<MY DOMAIN>=peertube
# see https://github.com/wader/postfix-relay/pull/18
#OPENDKIM_RequireSafeKeys=no

# /!\ Prefer to use the PeerTube admin interface to set the following configurations /!\
#PEERTUBE_SIGNUP_ENABLED=true
#PEERTUBE_TRANSCODING_ENABLED=true
#PEERTUBE_CONTACT_FORM_ENABLED=true
4 changes: 4 additions & 0 deletions dev/peertube/start-peertube-without-dnscache-for-local-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
docker compose up -d
docker compose exec peertube sed -i "s/dnsCache: true,/dnsCache: false,/g" /app/dist/server/helpers/requests.js
docker compose restart peertube
1 change: 1 addition & 0 deletions dev/peertube2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-volume
50 changes: 50 additions & 0 deletions dev/peertube2/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.3"

services:

peertube:
# If you don't want to use the official image and build one from sources:
# build:
# context: .
# dockerfile: ./support/docker/production/Dockerfile.bullseye
image: chocobozzz/peertube:production-bullseye
env_file:
- .env

ports:
# - "1935:1935" # Comment if you don't want to use the live feature
- "9001:9000" # Uncomment if you use another webserver/proxy or test PeerTube in local, otherwise not suitable for production
volumes:
# - ./docker-volume/assets:/app/client/dist
- ./docker-volume/data:/data
- ./docker-volume/config:/config
depends_on:
- postgres
- redis
# - postfix
restart: "always"
extra_hosts:
- "host.docker.internal:host-gateway"

postgres:
image: postgres:13-alpine
env_file:
- .env
volumes:
- ./docker-volume/db:/var/lib/postgresql/data
restart: "always"

redis:
image: redis:6-alpine
volumes:
- ./docker-volume/redis:/data
restart: "always"

# postfix:
# image: mwader/postfix-relay
# env_file:
# - .env
# volumes:
# - ./docker-volume/opendkim/keys:/etc/opendkim/keys
# restart: "always"

54 changes: 54 additions & 0 deletions dev/peertube2/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Database / Postgres service configuration
POSTGRES_USER=peertube
POSTGRES_PASSWORD=peertube
# Postgres database name "peertube"
POSTGRES_DB=peertube
# The database name used by PeerTube will be PEERTUBE_DB_NAME (only if set) *OR* 'peertube'+PEERTUBE_DB_SUFFIX
#PEERTUBE_DB_NAME=<MY POSTGRES DB NAME>
#PEERTUBE_DB_SUFFIX=_prod
# Database username and password used by PeerTube must match Postgres', so they are copied:
PEERTUBE_DB_USERNAME=peertube
PEERTUBE_DB_PASSWORD=peertube
PEERTUBE_DB_SSL=false
# Default to Postgres service name "postgres" in docker-compose.yml
PEERTUBE_DB_HOSTNAME=postgres

# PeerTube server configuration
# If you test PeerTube in local: use "peertube.localhost" and add this domain to your host file resolving on 127.0.0.1
PEERTUBE_WEBSERVER_HOSTNAME=host.docker.internal
# If you just want to test PeerTube on local
PEERTUBE_WEBSERVER_PORT=9001
PEERTUBE_WEBSERVER_HTTPS=false
# If you need more than one IP as trust_proxy
# pass them as a comma separated array:
PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback", "172.18.0.0/16"]
PEERTUBE_LOG_LEVEL="debug"

# Generate one using `openssl rand -hex 32`
PEERTUBE_SECRET=66abdc69a969d9632be098c9bd8814972ca87c93a1bffae00580f228dfc57cd8
PT_INITIAL_ROOT_PASSWORD=peertube
# E-mail configuration
# If you use a Custom SMTP server
#PEERTUBE_SMTP_USERNAME=
#PEERTUBE_SMTP_PASSWORD=
# Default to Postfix service name "postfix" in docker-compose.yml
# May be the hostname of your Custom SMTP server
PEERTUBE_SMTP_HOSTNAME=postfix
PEERTUBE_SMTP_PORT=25
PEERTUBE_SMTP_FROM=noreply@<MY DOMAIN>
PEERTUBE_SMTP_TLS=false
PEERTUBE_SMTP_DISABLE_STARTTLS=false
PEERTUBE_ADMIN_EMAIL=[email protected]

# Postfix service configuration
#POSTFIX_myhostname=localhost
# If you need to generate a list of sub/DOMAIN keys
# pass them as a whitespace separated string <DOMAIN>=<selector>
#OPENDKIM_DOMAINS=<MY DOMAIN>=peertube
# see https://github.com/wader/postfix-relay/pull/18
#OPENDKIM_RequireSafeKeys=no

# /!\ Prefer to use the PeerTube admin interface to set the following configurations /!\
#PEERTUBE_SIGNUP_ENABLED=true
#PEERTUBE_TRANSCODING_ENABLED=true
#PEERTUBE_CONTACT_FORM_ENABLED=true
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine as base

RUN apk add --update nodejs yarn
RUN apk add --update nodejs yarn git curl wget
WORKDIR /app

FROM base as builder
Expand Down
26 changes: 26 additions & 0 deletions docs/Development/activitypub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ActivityPub development

Repco includes a tiny ActivityPub server to ingest content from ActivityPub actors.

To locally develop and test the federation, you can start a local peertube instance. A docker compose file is included in the repo.

To launch a local PeerTube instance:

```
cd dev/peertube
docker compose up -d
```
To make federation work, add this line to `/etc/hosts`:
```
127.0.0.1 host.docker.internal
```

Afterwards open http://host.docker.internal:9000 in a browser and login with username `root` and password `peertube`


And make sure that you have these two variables set in repco's `.env` file.

```
AP_BASE_URL=http://host.docker.internal:8765/ap
```

1 change: 1 addition & 0 deletions docs/User Guides/Deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Deploying repco
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
},
"type": "module",
"scripts": {
"build": "run-s build:prisma-generate build:prisma build:frontend build:tsc build:cli build:webcomponent",
"build": "run-s build:prisma-generate build:prisma build:ap build:frontend build:tsc build:cli build:webcomponent",
"build:docker": "run-s build build:docs",
"build:tsc": "tsc --build",
"build:prisma-generate": "yarn --cwd packages/repco-prisma-generate build",
"build:prisma": "yarn --cwd packages/repco-prisma build",
"build:ap": "yarn --cwd packages/repco-activitypub build",
"build:cli": "yarn --cwd packages/repco-cli build",
"build:frontend": "yarn --cwd packages/repco-frontend build",
"build:docs": "run-s build:docs-core build:docs-website",
Expand Down Expand Up @@ -58,4 +59,3 @@
"typescript": "^4.8"
}
}

3 changes: 3 additions & 0 deletions packages/repco-activitypub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.peertube-repl-history
/generated
/dist
5 changes: 5 additions & 0 deletions packages/repco-activitypub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# repco-activitypub

a minimal implementation of an activitypub server

only used to follow other actors, no publishing happens
34 changes: 34 additions & 0 deletions packages/repco-activitypub/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'source-map-support/register.js'
import Dotenv from 'dotenv'
import express from 'express'
import { PrismaClient } from 'repco-prisma'
import { ActivityPub, mountActivityPub } from './src/server.js'

Dotenv.config()
Dotenv.config({ path: '../../.env' })

const app = express()

const baseUrl = process.env.AP_BASE_URL
if (!baseUrl) {
throw new Error('Missing AP_BASE_URL environment variable')
}

const db = new PrismaClient()
const ap = new ActivityPub(db, baseUrl)

mountActivityPub(app, ap, {
prefix: '/ap',
api: {
prefix: '/api/ap',
auth: async (_req) => {
// todo: authentication
return true
},
},
})

const port = process.env.PORT || 8765
app.listen(port, () => {
console.log('listening on http://localhost:' + port)
})
31 changes: 31 additions & 0 deletions packages/repco-activitypub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "repco-activitypub",
"version": "0.1.0",
"license": "MIT OR Apache-2.0",
"maintainers": [
"repco contributors"
],
"main": "./dist/src/server.js",
"type": "module",
"scripts": {
"build": "tsc --build",
"watch": "tsc --build -w",
"dev": "run-p watch start:watch",
"docs": "typedoc src/server.ts --out ./docs",
"start": "node dist/bin.js",
"test": "brittle dist/test/*.js"
},
"dependencies": {
"@digitalbazaar/http-digest-header": "^2.0.0",
"body-parser": "^1.18.3",
"express": "^4.18.1",
"express-async-errors": "^3.1.1",
"pino-http": "^8.3.3",
"repco-common": "*",
"repco-prisma": "*",
"source-map-support": "^0.5.21",
"undici": "^5.10.0",
"zod": "^3.19",
"zod-error": "^1.5.0"
}
}
Loading

0 comments on commit 3ce44bf

Please sign in to comment.