From f8225b3e2afe959872a302ebd44eb2eba1515806 Mon Sep 17 00:00:00 2001 From: JannikStreek Date: Fri, 23 Aug 2024 15:20:28 +0200 Subject: [PATCH] fix github plugin installation (#6584) --- Dockerfile | 19 +++++++++++++------ bin/plugins.ts | 23 ++++++++++++----------- docker-compose.dev.yml | 1 + src/static/js/pluginfw/LinkInstaller.ts | 6 ++++++ 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index f392f1e7d08..4feb79909de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,14 @@ ARG ETHERPAD_PLUGINS= # ETHERPAD_LOCAL_PLUGINS="../ep_my_plugin ../ep_another_plugin" ARG ETHERPAD_LOCAL_PLUGINS= +# github plugins to install while building the container. By default no plugins are +# installed. +# If given a value, it has to be a space-separated, quoted list of plugin names. +# +# EXAMPLE: +# ETHERPAD_GITHUB_PLUGINS="ether/ep_plugin" +ARG ETHERPAD_GITHUB_PLUGINS= + # Control whether abiword will be installed, enabling exports to DOC/PDF/ODT formats. # By default, it is not installed. # If given any value, abiword will be installed. @@ -114,13 +122,13 @@ COPY --chown=etherpad:etherpad ./pnpm-workspace.yaml ./package.json ./ FROM build AS development -COPY --chown=etherpad:etherpad ./src/package.json .npmrc ./src/ +COPY --chown=etherpad:etherpad ./src/ ./src/ COPY --chown=etherpad:etherpad --from=adminbuild /opt/etherpad-lite/src/ templates/admin./src/templates/admin COPY --chown=etherpad:etherpad --from=adminbuild /opt/etherpad-lite/src/static/oidc ./src/static/oidc RUN bin/installDeps.sh && \ - if [ ! -z "${ETHERPAD_PLUGINS}" ] || [ ! -z "${ETHERPAD_LOCAL_PLUGINS}" ]; then \ - pnpm run plugins i ${ETHERPAD_PLUGINS} ${ETHERPAD_LOCAL_PLUGINS:+--path ${ETHERPAD_LOCAL_PLUGINS}}; \ + if [ ! -z "${ETHERPAD_PLUGINS}" ] || [ ! -z "${ETHERPAD_LOCAL_PLUGINS}" ] || [ ! -z "${ETHERPAD_GITHUB_PLUGINS}" ]; then \ + pnpm run plugins i ${ETHERPAD_PLUGINS} ${ETHERPAD_LOCAL_PLUGINS:+--path ${ETHERPAD_LOCAL_PLUGINS}} ${ETHERPAD_GITHUB_PLUGINS:+--github ${ETHERPAD_GITHUB_PLUGINS}}; \ fi @@ -134,11 +142,10 @@ COPY --chown=etherpad:etherpad --from=adminbuild /opt/etherpad-lite/src/template COPY --chown=etherpad:etherpad --from=adminbuild /opt/etherpad-lite/src/static/oidc ./src/static/oidc RUN bin/installDeps.sh && rm -rf ~/.npm && rm -rf ~/.local && rm -rf ~/.cache && \ - if [ ! -z "${ETHERPAD_PLUGINS}" ] || [ ! -z "${ETHERPAD_LOCAL_PLUGINS}" ]; then \ - pnpm run plugins i ${ETHERPAD_PLUGINS} ${ETHERPAD_LOCAL_PLUGINS:+--path ${ETHERPAD_LOCAL_PLUGINS}}; \ + if [ ! -z "${ETHERPAD_PLUGINS}" ] || [ ! -z "${ETHERPAD_LOCAL_PLUGINS}" ] || [ ! -z "${ETHERPAD_GITHUB_PLUGINS}" ]; then \ + pnpm run plugins i ${ETHERPAD_PLUGINS} ${ETHERPAD_LOCAL_PLUGINS:+--path ${ETHERPAD_LOCAL_PLUGINS}} ${ETHERPAD_GITHUB_PLUGINS:+--github ${ETHERPAD_GITHUB_PLUGINS}}; \ fi - # Copy the configuration file. COPY --chown=etherpad:etherpad ${SETTINGS} "${EP_DIR}"/settings.json diff --git a/bin/plugins.ts b/bin/plugins.ts index 856e59f3971..17c756f601f 100644 --- a/bin/plugins.ts +++ b/bin/plugins.ts @@ -23,17 +23,13 @@ const possibleActions = [ ] const install = ()=> { - - let registryPlugins: string[] = []; - let localPlugins: string[] = []; - - if (args.indexOf('--path') !== -1) { - const indexToSplit = args.indexOf('--path'); - registryPlugins = args.slice(1, indexToSplit); - localPlugins = args.slice(indexToSplit + 1); - } else { - registryPlugins = args; - } + const argsAsString: string = args.join(" "); + const regexRegistryPlugins = /(?<=i\s)(.*?)(?=--github|--path|$)/; + const regexLocalPlugins = /(?<=--path\s)(.*?)(?=--github|$)/; + const regexGithubPlugins = /(?<=--github\s)(.*?)(?=--path|$)/; + const registryPlugins = argsAsString.match(regexRegistryPlugins)?.[0]?.split(" ")?.filter(s => s) || []; + const localPlugins = argsAsString.match(regexLocalPlugins)?.[0]?.split(" ")?.filter(s => s) || []; + const githubPlugins = argsAsString.match(regexGithubPlugins)?.[0]?.split(" ")?.filter(s => s) || []; async function run() { for (const plugin of registryPlugins) { @@ -53,6 +49,11 @@ const install = ()=> { console.log(`Installing plugin from path: ${plugin}`); await linkInstaller.installFromPath(plugin); } + + for (const plugin of githubPlugins) { + console.log(`Installing plugin from github: ${plugin}`); + await linkInstaller.installFromGitHub(plugin); + } } (async () => { diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 4efb74da4bf..62b9bc56366 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -9,6 +9,7 @@ services: build: context: . args: + # Attention: installed plugins in the node_modules folder get overwritten during volume mount in dev ETHERPAD_PLUGINS: # change from development to production if needed target: development diff --git a/src/static/js/pluginfw/LinkInstaller.ts b/src/static/js/pluginfw/LinkInstaller.ts index f4f782de524..e5eaf0b5c89 100644 --- a/src/static/js/pluginfw/LinkInstaller.ts +++ b/src/static/js/pluginfw/LinkInstaller.ts @@ -44,6 +44,12 @@ export class LinkInstaller { await this.checkLinkedDependencies(installedPlugin) } + public async installFromGitHub(repository: string) { + const installedPlugin = await this.livePluginManager.installFromGithub(repository) + this.linkDependency(installedPlugin.name) + await this.checkLinkedDependencies(installedPlugin) + } + public async installPlugin(pluginName: string, version?: string) { if (version) { const installedPlugin = await this.livePluginManager.install(pluginName, version);