add install-plugin script,

add project name env
This commit is contained in:
Arthur de Moulins
2020-03-12 19:24:41 +01:00
parent c13232a001
commit 19e6ba689c
6 changed files with 109 additions and 0 deletions

5
.env
View File

@@ -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=

View File

@@ -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 []

View File

@@ -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 :

View File

@@ -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:

View File

@@ -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

View File

@@ -0,0 +1,50 @@
#!/usr/bin/env php
<?php
function setupStreaming() {
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Disable Apache output buffering/compression
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
}
}
function runCommand($cmd){
echo "+ $cmd\n";
system($cmd, $return);
if (0 !== $return) {
throw new \Exception(sprintf('Error %d: %s', $return, $cmd));
}
}
setupStreaming();
$plugins = trim(getenv('PHRASEANET_PLUGINS'));
if (empty($plugins)) {
echo "No plugin to install... SKIP\n";
exit(0);
}
foreach (explode(' ', $plugins) as $key => $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));
}