Skip to content

Commit

Permalink
✨ Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
allouis committed Jul 4, 2024
0 parents commit f95538f
Show file tree
Hide file tree
Showing 28 changed files with 3,937 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.hbs]
insert_final_newline = false

[*.json]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[Makefile]
indent_style = tab
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
layout node
use flake ./.nix/flakes/nodejs
74 changes: 74 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Test, Build and Push to Artifact Registry

on:
push:

env:
IMAGE_NAME: europe-west4-docker.pkg.dev/ghost-activitypub/main/test-image

jobs:
build-push-artifact:
environment: build
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
europe-west4-docker.pkg.dev/ghost-activitypub/main/test-image
tags: |
type=edge,branch=main
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,priority=1100
- name: "Build docker image"
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}"
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: "Create ci docker compose file"
run: |
echo "
services:
activitypub:
image: $IMAGE_NAME:$DOCKER_METADATA_OUTPUT_VERSION" > docker-compose.ci.yml
- name: "Run tests"
run: |
docker compose -f docker-compose.testing.yml -f docker-compose.ci.yml up --abort-on-container-exit --exit-code-from activitypub
- name: Login to GAR
uses: docker/login-action@v3
with:
registry: europe-west4-docker.pkg.dev
username: _json_key
password: ${{ secrets.SERVICE_ACCOUNT_KEY }}

- name: "Push docker image"
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: "Auth with gcloud"
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}

- name: "Deploy to Cloud Run"
uses: 'google-github-actions/deploy-cloudrun@v2'
with:
image: europe-west4-docker.pkg.dev/ghost-activitypub/main/test-image:edge
region: europe-west4
service: activitypub
72 changes: 72 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Node template

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# IDE
.idea/*
*.iml
*.sublime-*
.vscode/*

# OSX
.DS_Store

# Activitypub V 3 Final Custom
.direnv
43 changes: 43 additions & 0 deletions .nix/flakes/nodejs/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions .nix/flakes/nodejs/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};

outputs = {
systems,
nixpkgs,
...
} @ inputs: let
yarn_overlay = final: prev: {
yarn = prev.yarn.overrideAttrs(finalAttrs: prevAttrs: {
# This is to make sure that yarn runs the correct node version
# https://github.com/NixOS/nixpkgs/issues/145634#issuecomment-1627476963
installPhase = prevAttrs.installPhase + ''
ln -fs $out/libexec/yarn/bin/yarn $out/bin/yarn
ln -fs $out/libexec/yarn/bin/yarn.js $out/bin/yarn.js
ln -fs $out/libexec/yarn/bin/yarn $out/bin/yarnpkg
'';
});
};

# This gives us a central place to set the node version
node_overlay = final: prev: {
nodejs = prev.nodejs;
};

eachSystem = f:
nixpkgs.lib.genAttrs (import systems) (
system:
f ((nixpkgs.legacyPackages.${system}.extend yarn_overlay).extend node_overlay)
);
in {

devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
yarn
];

shellHook = ''
echo "node `${pkgs.nodejs}/bin/node --version`"
'';
};
});
};
}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:lts-alpine

WORKDIR /opt/activitypub

COPY package.json .
COPY yarn.lock .

RUN yarn

COPY tsconfig.json .

COPY src ./src

EXPOSE 8080

CMD ["node", "--import", "tsx", "src/app.ts"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2013-2024 Ghost Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ActivityPub V3 Final

A multitenant ActivityPub service built using the [Fedify](https://fedify.dev/) framework, designed to integrate seamlessly with [Ghost](https://ghost.org/). This service provides ActivityPub functionality for following other users and publishing to the fediverse. Ghost communicates with this service to manage all ActivityPub features.

**Note:** ⚠️ This project is in its early phases and not yet ready for production

## How It Works

All requests to `/.ghost/activitypub/*` and `/.well-known/webfinger` are proxied to this ActivityPub service using NGINX. All other requests are forwarded to Ghost.

### Current Features

- [x] Follow
- [ ] Unfollow
- [x] Auto Accept Follows
- [ ] Manually Accept/Reject Follows
- [x] Publish Articles to Followers
- [x] Receive Articles in Inbox
- [x] Receive Notes in Inbox

## Running Locally / Development

You need `docker` installed - this has only been tested on MacOS using Docker for Mac and OrbStack.

### Setup Steps

1. **Set up a Ghost development environment**
- Ensure Ghost is running locally at `localhost:2368`.
2. **Proxy your local environment**
- Use `tailscale funnel 80` or `ngrok http 80` to expose your local port 80.
3. **Configure Ghost**
- Set the URL in your Ghost config to the URL output by the above command.
4. **Start the ActivityPub Service**
- Run `yarn dev` in the root directory of this project.
5. **Visit the Exposed URL**
- Access your Ghost instance via the URL provided by Tailscale or Ngrok.
6. **Configure Webhook**
- Set up a webhook for the `post.published` event pointing to `https://<your-url>/.ghost/activitypub/webhooks/post/published`.
7. **Enable ActivityPub Alpha**
- Switch on the ActivityPub Alpha flag in Labs

### Running Tests

- Run `yarn test` to execute tests within a Docker Compose stack.

## Related Projects and Resources

- [Fedify](https://github.com/dahlia/fedify/)
- [Ghost](https://github.com/TryGhost/Ghost/)

# Copyright & License

Copyright (c) 2013-2024 Ghost Foundation - Released under the [MIT license](LICENSE).
31 changes: 31 additions & 0 deletions docker-compose.testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
activitypub:
build: .
environment:
- MYSQL_USER=ghost
- MYSQL_PASSWORD=password
- MYSQL_HOST=mysql-testing
- MYSQL_PORT=3306
- MYSQL_DATABASE=activitypub
- NODE_ENV=testing
command: yarn test:all
depends_on:
mysql-testing:
condition: service_healthy

mysql-testing:
image: mysql:lts
volumes:
- mysql-test-volume:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=ghost
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=activitypub
healthcheck:
test: "mysql -ughost -ppassword activitypub -e 'select 1'"
interval: 1s
retries: 120

volumes:
mysql-test-volume:
Loading

0 comments on commit f95538f

Please sign in to comment.