From 19e6ba689c773116f35fa1d3048a646f3e359025 Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Thu, 12 Mar 2020 19:24:41 +0100 Subject: [PATCH] add install-plugin script, add project name env --- .env | 5 ++++ Dockerfile | 16 ++++++++++ README.md | 22 ++++++++++++++ docker-compose.override.yml | 5 ++++ docker-compose.yml | 11 +++++++ docker/phraseanet/install-plugins | 50 +++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100755 docker/phraseanet/install-plugins diff --git a/.env b/.env index 2fb773529c..e89eeec0aa 100644 --- a/.env +++ b/.env @@ -1,3 +1,4 @@ +PHRASEANET_PROJECT_NAME=Phraseanet # Registry from where you pull Docker images PHRASEANET_DOCKER_REGISTRY=local # Tag of the Docker images @@ -70,3 +71,7 @@ PHRASEANET_DB_DIR=./volumes/db PHRASEANET_ELASTICSEARCH_DIR=./volumes/elasticsearch PHRASEANET_THUMBNAILS_DIR=./www/thumbnails PHRASEANET_TMP_DIR=./tmp + +# Plugin support +PHRASEANET_PLUGINS= +PHRASEANET_SSH_PRIVATE_KEY= diff --git a/Dockerfile b/Dockerfile index cbb260a711..4b2614a357 100644 --- a/Dockerfile +++ b/Dockerfile @@ -86,6 +86,7 @@ RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \ vim \ iputils-ping \ zsh \ + ssh \ telnet \ autoconf \ libtool \ @@ -112,6 +113,21 @@ RUN make install ADD ./docker/builder/root / +# SSH Private repo +ARG SSH_PRIVATE_KEY +ARG PHRASEANET_PLUGINS + +RUN ( \ + test ! -z "${SSH_PRIVATE_KEY}" \ + && mkdir -p ~/.ssh \ + && echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa \ + # make sure github domain.com is accepted + && ssh-keyscan -H github.com >> ~/.ssh/known_hosts \ + && chmod 600 ~/.ssh/id_rsa \ + ) || echo "Skip SSH key" + +RUN ./docker/phraseanet/install-plugins + ENTRYPOINT ["/bootstrap/entrypoint.sh"] CMD [] diff --git a/README.md b/README.md index e5865b0c6b..a277761d1d 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,28 @@ XDEBUG_REMOTE_HOST=host.docker.internal > Don't forget to recreate your container (`docker-compose up -d phraseanet`) +### Build images with plugins + +Plugins can be installed during build if you set the `PHRASEANET_PLUGINS` env var as follows: + +```bash +PHRASEANET_PLUGINS="git@github.com:alchemy-fr/Phraseanet-plugin-webgallery.git" + +# You can optionally precise the branch to install +# If not precised, the main branch will be pulled +PHRASEANET_PLUGINS="git@github.com:alchemy-fr/Phraseanet-plugin-webgallery.git(custom-branch)" + +# Plugins are separated by spaces +PHRASEANET_PLUGINS="git@github.com:foo/bar.git(branch-1) git@github.com:baz/42.git" +``` + +If you install private plugins, make sure you export your SSH private key content in order to allow docker build to access the GIT repository: +```bash +export PHRASEANET_SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa) +# or if your private key is protected by a passphrase: +export PHRASEANET_SSH_PRIVATE_KEY=$(openssl rsa -in ~/.ssh/id_rsa -out /tmp/id_rsa_raw && cat /tmp/id_rsa_raw && rm /tmp/id_rsa_raw) +``` + # With Vagrant (deprecated) ## Development : diff --git a/docker-compose.override.yml b/docker-compose.override.yml index d926216316..7e2b3dd2b8 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -21,6 +21,9 @@ services: build: context: . target: builder + args: + - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY} + - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS} stdin_open: true tty: true volumes: @@ -33,6 +36,8 @@ services: - ${SSH_AUTH_SOCK}:/ssh-auth-sock - ${HOME}/.ssh:/home/app/.ssh - dev_vol:/home/app + environment: + - PHRASEANET_PROJECT_NAME phraseanet: environment: diff --git a/docker-compose.yml b/docker-compose.yml index 4c6f435ee7..e0bd547fbb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,9 @@ services: build: context: . target: phraseanet-nginx + args: + - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY} + - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS} image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-nginx:$PHRASEANET_DOCKER_TAG restart: on-failure volumes: @@ -21,6 +24,9 @@ services: build: context: . target: phraseanet-fpm + args: + - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY} + - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS} image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-fpm:$PHRASEANET_DOCKER_TAG restart: on-failure depends_on: @@ -29,6 +35,7 @@ services: - rabbitmq - elasticsearch environment: + - PHRASEANET_PROJECT_NAME - MAX_BODY_SIZE - MAX_INPUT_VARS - OPCACHE_ENABLED @@ -57,6 +64,9 @@ services: build: context: . target: phraseanet-worker + args: + - SSH_PRIVATE_KEY=${PHRASEANET_SSH_PRIVATE_KEY} + - PHRASEANET_PLUGINS=${PHRASEANET_PLUGINS} image: $PHRASEANET_DOCKER_REGISTRY/phraseanet-worker:$PHRASEANET_DOCKER_TAG restart: on-failure depends_on: @@ -65,6 +75,7 @@ services: - rabbitmq - elasticsearch environment: + - PHRASEANET_PROJECT_NAME - MAX_BODY_SIZE - MAX_INPUT_VARS - OPCACHE_ENABLED diff --git a/docker/phraseanet/install-plugins b/docker/phraseanet/install-plugins new file mode 100755 index 0000000000..d4a5cb01c8 --- /dev/null +++ b/docker/phraseanet/install-plugins @@ -0,0 +1,50 @@ +#!/usr/bin/env php + $plugin) { + $plugin = trim($plugin); + $repo = $plugin; + $branch = 'master'; + if (1 === preg_match('#^(.+)\(([^)]+)\)$#', $plugin, $matches)) { + $repo = $matches[1]; + $branch = $matches[2]; + } + + $pluginTmpName = 'plugin' . $key; + $pluginPath = './plugin' . $key; + if (is_dir($pluginPath)) { + echo shell_exec(sprintf('rm -rf %s', $pluginPath)); + } + + echo sprintf("Installing %s (branch: %s)\n", $repo, $branch); + runCommand(sprintf('git clone --single-branch --branch %s %s %s', $branch, $repo, $pluginPath)); + + runCommand(sprintf('bin/setup plugins:add %s', $pluginPath)); + + echo shell_exec(sprintf('rm -rf %s', $pluginPath)); +}