Skip to content

Commit

Permalink
feat: add etherpad service (#295)
Browse files Browse the repository at this point in the history
* build: add etherpad devcontainer

* feat: register etherpad plugin

* fix: use docker etherpad URL

* chore: bump sdk

* fix: use public etherpad URL

* chore: add etherpad database connection to sqltools extension

* ci: add test container env vars for etherpad

* chore: bump graasp-plugin-etherpad

* feat: register public etherpad plugin

* chore: bump dependencies

* chore: bump graasp-plugin-etherpad

* ci: add env vars

* chore: bump graasp-plugin-etherpad

* fix: add cookie domain

* ci: add etherpad cookie domain env var

* chore: bump @graasp/translations

* ci: replace etherpad URL secret by env var

(cherry picked from commit 2ff2ffb)
  • Loading branch information
Alexandre Chau authored and codeofmochi committed Jan 11, 2023
1 parent 1bfb8b3 commit f8b3b0d
Show file tree
Hide file tree
Showing 15 changed files with 559 additions and 15 deletions.
1 change: 1 addition & 0 deletions .devcontainer/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FROM postgres:13
COPY db-schema.sql /docker-entrypoint-initdb.d/
COPY db-schema-etherpad.sh /docker-entrypoint-initdb.d/
14 changes: 12 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@
"terminal.integrated.shell.linux": "/bin/bash",
"sqltools.connections": [
{
"name": "Container database",
"name": "Graasp database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "localhost",
"server": "db",
"port": 5432,
"database": "docker",
"username": "docker",
"password": "docker"
},
{
"name": "Etherpad database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "db",
"port": 5432,
"database": "etherpad",
"username": "etherpad",
"password": "etherpad"
}
]
},
Expand Down
30 changes: 30 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ services:
POSTGRES_DB: docker
POSTGRES_USER: docker
POSTGRES_PASSWORD: docker
POSTGRES_ETHERPAD_DB: etherpad
POSTGRES_ETHERPAD_USER: etherpad
POSTGRES_ETHERPAD_PASSWORD: etherpad
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward MongoDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

Expand All @@ -58,6 +61,33 @@ services:
ports:
- 6379:6379

etherpad:
container_name: graasp-etherpad
image: etherpad/etherpad
# start the server with dev API key
# https://hub.docker.com/r/etherpad/etherpad/dockerfile
# https://github.com/ether/etherpad-lite/issues/3849
volumes:
# bind copy the dev API key
- ./etherpad/devApiKey.txt:/opt/etherpad-lite/APIKEY.txt
ports:
- 9001:9001
environment:
- DB_TYPE=postgres
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=etherpad
- DB_USER=etherpad
- DB_PASS=etherpad
# allow only group pads
# - REQUIRE_SESSION=true
# only API can create pads
- EDIT_ONLY=true
# restart the container until db has created tables
restart: unless-stopped
depends_on:
- db

# Localstack is used to test aws services locally
localstack:
container_name: graasp-localstack
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/etherpad/devApiKey.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
3 changes: 3 additions & 0 deletions .github/workflows/cdelivery-ecs-backend-caller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
chatbox-plugin: true
database-logs: false
embedded-link-item-plugin: true
etherpad-cookie-domain: ${{ vars.ETHERPAD_COOKIE_DOMAIN_STAGE }}
etherpad-url: ${{ vars.ETHERPAD_URL_STAGE }}
hidden-items-plugin: true
node-env: production
node-env-iframely: production
Expand Down Expand Up @@ -56,6 +58,7 @@ jobs:
cors-origin-regex: ${{ secrets.CORS_ORIGIN_REGEX_STAGE }}
email-links-host: ${{ secrets.EMAIL_LINKS_HOST_STAGE }}
embedded-link-item-iframely-href-origin: ${{ secrets.EMBEDDED_LINK_ITEM_IFRAMELY_HREF_ORIGIN }}
etherpad-api-key: ${{ secrets.ETHERPAD_API_KEY_STAGE }}
explorer-client-host: ${{ secrets.EXPLORER_CLIENT_HOST_STAGE }}
file-storage-root-path: ${{ secrets.FILE_STORAGE_ROOT_PATH }}
files-path-prefix: ${{ secrets.FILES_PATH_PREFIX }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cdeployment-ecs-backend-caller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
chatbox-plugin: true
database-logs: false
embedded-link-item-plugin: true
etherpad-cookie-domain: ${{ vars.ETHERPAD_COOKIE_DOMAIN_PROD }}
etherpad-url: ${{ vars.ETHERPAD_URL_PROD }}
hidden-items-plugin: true
node-env: production
node-env-iframely: production
Expand Down Expand Up @@ -57,6 +59,7 @@ jobs:
cors-origin-regex: ${{ secrets.CORS_ORIGIN_REGEX_PROD }}
email-links-host: ${{ secrets.EMAIL_LINKS_HOST_PROD }}
embedded-link-item-iframely-href-origin: ${{ secrets.EMBEDDED_LINK_ITEM_IFRAMELY_HREF_ORIGIN }}
etherpad-api-key: ${{ secrets.ETHERPAD_API_KEY_PROD }}
explorer-client-host: ${{ secrets.EXPLORER_CLIENT_HOST_PROD }}
file-storage-root-path: ${{ secrets.FILE_STORAGE_ROOT_PATH }}
files-path-prefix: ${{ secrets.FILES_PATH_PREFIX }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cintegration-ecs-backend-caller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
chatbox-plugin: true
database-logs: false
embedded-link-item-plugin: true
etherpad-cookie-domain: ${{ vars.ETHERPAD_COOKIE_DOMAIN_DEV }}
etherpad-url: ${{ vars.ETHERPAD_URL_DEV }}
hidden-items-plugin: true
node-env: production
node-env-iframely: production
Expand Down Expand Up @@ -61,6 +63,7 @@ jobs:
cors-origin-regex: ${{ secrets.CORS_ORIGIN_REGEX_DEV }}
email-links-host: ${{ secrets.EMAIL_LINKS_HOST_DEV }}
embedded-link-item-iframely-href-origin: ${{ secrets.EMBEDDED_LINK_ITEM_IFRAMELY_HREF_ORIGIN }}
etherpad-api-key: ${{ secrets.ETHERPAD_API_KEY_DEV }}
explorer-client-host: ${{ secrets.EXPLORER_CLIENT_HOST_DEV }}
file-storage-root-path: ${{ secrets.FILE_STORAGE_ROOT_PATH }}
files-path-prefix: ${{ secrets.FILES_PATH_PREFIX }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ jobs:
BUILDER_CLIENT_HOST: 'http://localhost:3111'
PLAYER_CLIENT_HOST: 'http://localhost:3112'
EXPLORER_CLIENT_HOST: 'http://localhost:3113'
ETHERPAD_URL: http://etherpad:9001
ETHERPAD_API_KEY: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ H5P_CONTENT_ACCESS_KEY_ID=graasp-user
H5P_CONTENT_SECRET_ACCESS_KEY=graasp-pwd
H5P_PATH_PREFIX=h5p-content/

# Graasp Etherpad
ETHERPAD_URL=http://etherpad:9001
# Optional, if the etherpad server server has a different public URL than what the back-end uses to communicate with the service (e.g. private network)
ETHERPAD_PUBLIC_URL=http://localhost:9001
# Optional, if the etherpad cookie domain is different from the domain of the public URL
ETHERPAD_COOKIE_DOMAIN=localhost:9001
ETHERPAD_API_KEY=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

# Graasp embedded link item
EMBEDDED_LINK_ITEM_PLUGIN=false
# EMBEDDED_LINK_ITEM_IFRAMELY_HREF_ORIGIN=<protocol>://<hostname>:<port>
Expand Down
5 changes: 5 additions & 0 deletions db-schema-etherpad.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE DATABASE $POSTGRES_ETHERPAD_DB;
CREATE USER $POSTGRES_ETHERPAD_USER WITH PASSWORD '$POSTGRES_ETHERPAD_PASSWORD';
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_ETHERPAD_DB to $POSTGRES_ETHERPAD_USER;
EOSQL
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@fastify/cors": "7.0.0",
"@fastify/helmet": "8.0.0",
"@fastify/secure-session": "4.0.0",
"@graasp/sdk": "github:graasp/graasp-sdk",
"@graasp/translations": "github:graasp/graasp-translations",
"@graasp/sdk": "0.2.0",
"@graasp/translations": "1.2.1",
"@sentry/node": "6.19.7",
"@sentry/tracing": "6.19.7",
"aws-sdk": "2.1124.0",
Expand All @@ -68,6 +68,7 @@
"graasp-plugin-actions": "github:graasp/graasp-plugin-actions",
"graasp-plugin-categories": "github:graasp/graasp-plugin-categories",
"graasp-plugin-chatbox": "github:graasp/graasp-plugin-chatbox",
"graasp-plugin-etherpad": "github:graasp/graasp-plugin-etherpad",
"graasp-plugin-file": "github:graasp/graasp-plugin-file",
"graasp-plugin-file-item": "github:graasp/graasp-plugin-file-item",
"graasp-plugin-h5p": "github:graasp/graasp-plugin-h5p",
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { publicPlugin as publicAppsPlugin } from 'graasp-apps';
import { ItemTagService } from 'graasp-item-tags';
import { publicPlugin as publicCategoriesPlugin } from 'graasp-plugin-categories';
import { publicPlugin as publicChatboxPlugin } from 'graasp-plugin-chatbox';
import { publicPlugin as publicEtherpadPlugin } from 'graasp-plugin-etherpad';
import { publicPlugin as publicFileItemPlugin } from 'graasp-plugin-file-item';
import { publicPlugin as publicH5PPlugin } from 'graasp-plugin-h5p';
import { publicPlugin as publicZipPlugin } from 'graasp-plugin-item-zip';
Expand All @@ -16,6 +17,9 @@ import {
APPS_JWT_SECRET,
APP_ITEMS_PREFIX,
AVATARS_PATH_PREFIX,
ETHERPAD_API_KEY,
ETHERPAD_PUBLIC_URL,
ETHERPAD_URL,
FILES_PATH_PREFIX,
FILE_ITEM_PLUGIN_OPTIONS,
FILE_ITEM_TYPE,
Expand Down Expand Up @@ -113,6 +117,13 @@ const plugin: FastifyPluginAsync<PublicPluginOptions> = async (instance) => {
// chatbox
await instance.register(publicChatboxPlugin);

// etherpad
await instance.register(publicEtherpadPlugin, {
url: ETHERPAD_URL,
apiKey: ETHERPAD_API_KEY,
publicUrl: ETHERPAD_PUBLIC_URL,
});

// download zip
await instance.register(publicZipPlugin, {
pathPrefix: FILES_PATH_PREFIX,
Expand Down
12 changes: 12 additions & 0 deletions src/services/items/service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from 'graasp-plugin-actions';
import graaspCategoryPlugin from 'graasp-plugin-categories';
import graaspChatbox from 'graasp-plugin-chatbox';
import graaspItemEtherpad from 'graasp-plugin-etherpad';
import fileItemPlugin from 'graasp-plugin-file-item';
import graaspItemH5P from 'graasp-plugin-h5p';
import graaspHidden from 'graasp-plugin-hidden-items';
Expand All @@ -48,6 +49,10 @@ import {
CLIENT_HOSTS,
EMBEDDED_LINK_ITEM_IFRAMELY_HREF_ORIGIN,
EMBEDDED_LINK_ITEM_PLUGIN,
ETHERPAD_API_KEY,
ETHERPAD_COOKIE_DOMAIN,
ETHERPAD_PUBLIC_URL,
ETHERPAD_URL,
FILES_PATH_PREFIX,
FILE_ITEM_PLUGIN_OPTIONS,
FILE_ITEM_TYPE,
Expand Down Expand Up @@ -158,6 +163,13 @@ const plugin: FastifyPluginAsync = async (fastify) => {
},
});

fastify.register(graaspItemEtherpad, {
url: ETHERPAD_URL,
apiKey: ETHERPAD_API_KEY,
publicUrl: ETHERPAD_PUBLIC_URL,
cookieDomain: ETHERPAD_COOKIE_DOMAIN,
});

fastify.register(graaspItemZip, {
pathPrefix: FILES_PATH_PREFIX,
fileItemType: FILE_ITEM_TYPE,
Expand Down
5 changes: 5 additions & 0 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export const H5P_CONTENT_BUCKET = process.env.H5P_CONTENT_BUCKET;
export const H5P_CONTENT_ACCESS_KEY_ID = process.env.H5P_CONTENT_ACCESS_KEY_ID;
export const H5P_CONTENT_SECRET_ACCESS_KEY = process.env.H5P_CONTENT_SECRET_ACCESS_KEY;

export const ETHERPAD_URL = process.env.ETHERPAD_URL;
export const ETHERPAD_PUBLIC_URL = process.env.ETHERPAD_PUBLIC_URL;
export const ETHERPAD_API_KEY = process.env.ETHERPAD_API_KEY;
export const ETHERPAD_COOKIE_DOMAIN = process.env.ETHERPAD_COOKIE_DOMAIN;

let S3_INSTANCE: S3;

// Enable localstack, only create the instance in test or dev environments
Expand Down
Loading

0 comments on commit f8b3b0d

Please sign in to comment.