Integrate ctop and docker-compose into the package

parent 466de1d9
......@@ -5,7 +5,7 @@ Section: utils
Maintainer: Marius David Wieschollek <epm@mdns.eu>
Homepage: https://git.mdns.eu/epm/docker
Priority: optional
Architecture: all
Architecture: amd64
Depends: epm (>=0.7.0), docker-engine (>=17.03.0~ce), sudo (>=1.8.9), php-yaml (>=2.0.0)
Enhances: epm (>=0.7.0)
Description: (EPM) Docker Module
......
......@@ -16,7 +16,7 @@ prepare-fresh:
- VERSION=$(sed -n 's/.*version"\s*:\s*"\(.*\)".*/\1/p' ./Configuration/module.json)"+build.${CI_BUILD_ID}";
- MODULE=$(sed -n 's/.*name"\s*:\s*"\(.*\)".*/\1/p' ./Configuration/module.json);
- PACKAGE="epm-${MODULE}";
- DEBPKG="${PACKAGE}-${VERSION}-all.deb";
- DEBPKG="${PACKAGE}-${VERSION}-amd64.deb";
- echo "export VERSION=\"${VERSION}\"" > variables.${CI_BUILD_REF}
- echo "export PACKAGE=\"${PACKAGE}\"" >> variables.${CI_BUILD_REF}
- echo "export EPM_API=\"${EPM_API}\"" >> variables.${CI_BUILD_REF}
......
......@@ -69,10 +69,6 @@ class Install extends AbstractJob {
$output->print('docker.install.reboot');
}
if(!$this->systemUtility->commandExists('docker-compose') || !$this->dockerUtility->isComposeVersionSufficient()) {
$output->print('docker.install.installing', 'Docker Compose');
$this->installDockerCompose();
}
$this->executeHooks('docker.jobs.install.after');
}
......@@ -95,22 +91,4 @@ class Install extends AbstractJob {
$this->shellFactory->getRootShell()->addCommand($installDocker)->addCommand($addUser)->execute();
}
/**
*
*/
public function installDockerCompose(): void {
global $cfg;
$url = 'https://github.com/docker/compose/releases/download/'.$cfg['modules'][ DOCKER_MODULE_NAME ]['docker-compose'].'/docker-compose-'.PHP_OS.'-'.php_uname('m');
$curl = $this->commandUtility->makeCommand('curl')
->addShortOption('L', $url)
->addShortOption('o', '/usr/local/bin/docker-compose');
$chmod = $this->commandUtility->makeCommand('chmod')
->addArgument('+x', false)
->addArgument('/usr/local/bin/docker-compose', false);
$this->shellFactory->getRootShell()->addCommand($curl)->addCommand($chmod)->execute();
}
}
\ No newline at end of file
......@@ -30,17 +30,24 @@ class Logs extends AbstractJob {
* @param array $options
*/
public function run(array $options = []) {
global $init;
$frontendShell = $this->shellFactory->getByName('frontend');
$docker = $this->dockerUtility->makeDockerComposeCommand(false)
->addArgument('logs')
->addShortOption('f')
->addShortOption('t')
->addLongOption('tail', 'all');
$init->flushStatus();
$init->removeLockFile();
$frontendShell->addCommand($docker)->execute();
$this->logs();
}
public function logs() {
global $init;
$this->executeHooks('docker.jobs.logs.before');
$frontendShell = $this->shellFactory->getByName('frontend');
$docker = $this->dockerUtility->makeDockerComposeCommand(false)
->addArgument('logs')
->addShortOption('f')
->addShortOption('t')
->addLongOption('tail', 'all');
$init->flushStatus();
$init->removeLockFile();
$frontendShell->addCommand($docker)->execute();
$this->executeHooks('docker.jobs.logs.after');
}
}
\ No newline at end of file
......@@ -67,6 +67,8 @@ class Shell extends AbstractJob {
*/
public function shell(string $container, string $user = 'root', string $command = 'bash'): bool {
global $init;
$this->executeHooks('docker.jobs.shell.before', $container, $user, $command);
$userShell = $this->shellFactory->getByName('user');
$userShell->addCommand(
$this->commandUtility->makeCommand('docker')
......@@ -81,6 +83,7 @@ class Shell extends AbstractJob {
$init->flushStatus();
$init->removeLockFile();
$userShell->execute();
$this->executeHooks('docker.jobs.shell.after', $container, $user, $command);
return true;
} catch (\Throwable $e) {
......
<?php
/**
* Created by PhpStorm.
* User: marius
* Date: 07.04.17
* Time: 11:19
*/
namespace Docker\Jobs;
use EPM\Jobs\AbstractJob;
class Top extends AbstractJob {
/**
* @var \EPM\Utility\ResourceUtility
* @inject
*/
protected $resourceUtility;
/**
* @var \EPM\Factories\ShellFactory
* @inject
*/
protected $shellFactory;
/**
* @var \EPM\Factories\CommandFactory
* @inject
*/
protected $commandFactory;
/**
* Execute this job
*
* @param array $options
*
* @return string
*/
public function run(array $options = []): string {
global $output;
$this->top($options['options']['active']);
$output->print('docker.top.info', ucfirst(EPM_PROJECT_MODULE));
return 'jobs.done';
}
/**
* @param bool $active
*/
public function top(bool $active = false) {
global $init;
$this->executeHooks('docker.jobs.top.before');
$ctopPath = $this->resourceUtility->resolvePath('Docker:Programs/ctop');
$ctop = $this->commandFactory->getCommand($ctopPath)->addShortOption('f', EPM_PROJECT_MODULE);
if($active) {
$ctop->addShortOption('a');
}
$init->flushStatus();
$init->removeLockFile();
$this->shellFactory->getByName('user')->addCommand($ctop)->execute();
$this->executeHooks('docker.jobs.top.after');
}
}
\ No newline at end of file
......@@ -43,6 +43,12 @@ class DockerUtility {
*/
protected $systemUtility;
/**
* @var \EPM\Utility\ResourceUtility
* @inject
*/
protected $resourceUtility;
/**
* @var \Docker\Utility\ContainerUtility
* @inject
......@@ -142,32 +148,12 @@ class DockerUtility {
$this->hookManager->executeHook('docker.down.after', $volumes);
}
/**
* @return bool
*/
public function isComposeVersionSufficient(): bool {
global $cfg;
$version = $this->getDockerComposeVersion();
if($version === null) {
return false;
}
$version = intval(preg_replace("/[^0-9]/", "", $version));
$rv = intval(preg_replace("/[^0-9]/", "", $cfg['modules'][ DOCKER_MODULE_NAME ]['docker-compose']));
return $version >= $rv;
}
/**
* @return null|string
*/
public function getDockerComposeVersion(): ?string {
if(!$this->systemUtility->commandExists('docker-compose')) {
return null;
}
$docker = $this->commandUtility->makeCommand('docker-compose')->addShortOption('v');
$cmdPath = $this->resourceUtility->resolvePath('Docker:Programs/docker-compose');
$docker = $this->commandUtility->makeCommand($cmdPath)->addShortOption('v');
$result = $this->shellFactory->getLocalShell()->addCommand($docker)->execute(true);
preg_match("/version ([^,]+)/", $result, $matches);
......@@ -195,13 +181,9 @@ class DockerUtility {
* @throws UserException
*/
public function requireDockerInstalled(): void {
global $cfg;
if(!$this->systemUtility->commandExists('docker')) {
throw new UserException('docker.docker.required');
}
if(!$this->systemUtility->commandExists('docker-compose') || !$this->isComposeVersionSufficient()) {
throw new UserException(['docker.compose.upgrade', $cfg['modules'][ DOCKER_MODULE_NAME ]['docker-compose']]);
}
}
/**
......@@ -266,7 +248,8 @@ class DockerUtility {
global $cfg;
$configs = $this->getComposeConfigPaths();
$docker = $this->commandUtility->makeCommand('docker-compose');
$cmdPath = $this->resourceUtility->resolvePath('Docker:Programs/docker-compose');
$docker = $this->commandUtility->makeCommand($cmdPath);
foreach ($configs as $config) {
$docker->addShortOption('f', $config);
......
......@@ -23,6 +23,13 @@ $cfg['modules'][ DOCKER_MODULE_NAME ]['overrides'] = [
\Repositories\Model\Repository\DatabaseRepository::class => \Docker\Overrides\Model\Repository\DatabaseRepository::class
];
if(PHP_OS == 'Darwin') {
$cfg['modules'][ DOCKER_MODULE_NAME ]['overrides'] = [
'Docker:Programs/ctop' => 'Docker:Programs/Darwin/ctop',
'Docker:Programs/docker-compose' => 'Docker:Programs/Darwin/docker-compose'
];
}
$cfg['docker'] = [
'ports' => [],
'domains' => [],
......@@ -49,6 +56,10 @@ $cfg['jobs']['docker.shell'] = [
'c' => 'command'
]
];
$cfg['jobs']['docker.top'] = [
'options' => [ 'active' => false, ],
'mappings' => [ 'a' => 'active' ]
];
$cfg['jobs']['docker.project.create'] = ['template' => null];
$cfg['jobs']['epm.up']['options']['force-recreate'] = false;
......
{
"name" : "docker",
"version" : "0.7.0",
"docker-compose": "1.11.2",
"author" : "Marius David Wieschollek",
"relations" : {
"enhances": [ "repositories" ]
......
......@@ -4,7 +4,7 @@ This module integrates Docker into EPM.
## Installation
The following installation guide shows you how to install Docker, Docker-compose and the Docker Module on Ubuntu 16.04.
The following installation guide shows you how to install Docker and the Docker Module on Ubuntu 16.04.
Please note that the PPA only supports Ubuntu.
You can download the .deb packages at the [Builds page](https://git.mdns.eu/epm/docker/pipelines) or you can [clone the repository](https://git.mdns.eu/epm/docker.git).
......@@ -20,9 +20,6 @@ docker run hello-world
# Install the docker module
wget -O - https://ppa.mdns.eu/epm/add-ppa.sh | sh -
sudo apt install epm-docker
# Install missing dependencies
epm docker:install
```
## Documentation
......
......@@ -55,18 +55,20 @@
}
}
},
"top" : {
"description": "Zeigt aktuelle Container-Statistiken mit ctop an (http://ctop.sh/)",
"options" : {
"active" : {
"description": "Nur aktive Container anzeigen"
}
}
},
"logs" : {
"description": "Zeigt die aktuellen Container Logs an"
},
"install" : {
"description": "Installiere Docker und Docker Compose auf diesem Gerät"
}
},
"docs" : {
"preconditions": {
"title": "Voraussetzungen",
"text" : "Das Docker modul setzt voraus, dass `docker-compose` auf dem System installiert ist. Sollte pip auf dem System vorhanden sein, kann docker-compose mit dem folgenden Befehl installiert werden:\n\n pip install docker-compose\n\nAndernfalls folgen Sie der Anleitung unter https://docs.docker.com/compose/install/."
}
}
},
"epm" : {
......
......@@ -61,18 +61,21 @@
}
}
},
"top" : {
"description": "Monitor current container statistics with ctop (http://ctop.sh/)",
"options" : {
"active" : {
"short" : "a",
"description": "Show only active containers"
}
}
},
"logs" : {
"description": "Show the current container logs"
},
"install" : {
"description": "Install Docker and Docker Compose on this machine"
}
},
"docs" : {
"preconditions": {
"title": "Preconditions",
"text" : "The Docker Module requires `Docker-compose` to be installed on the system. If you have pip installed on your system you can get Docker-compose by using this command:\n\n pip install Docker-compose\n\nOtherwise you can install it by following the manual on https://docs.Docker.com/compose/install/."
}
}
},
"epm" : {
......
......@@ -24,6 +24,7 @@
"docker.hosts.root" : "Füge Host-Einträge für Projekt in /etc/hosts ein. Administrative Rechte sind notwendig.",
"docker.shell.choose" : "Wählen Sie einen Container",
"docker.shell.connected" : "Verbunden mit %1$s",
"docker.top.info" : "Zeige Container-Statistik für %1$s an",
"docker.status.components" : "Docker Komponenten",
"docker.status.compose" : "Docker Compose Konfiguration",
"docker.status.containers" : "Container Status",
......@@ -42,7 +43,6 @@
"e.docker.upgrade.yml" : "Konfigurationsdatei kann nicht gefunden werden",
"e.docker.os.unsupported" : "Das verwendete Betriebssystem wird nicht unterstützt",
"e.docker.docker.required" : "Diese Anwendung benötigt mindestens Version 1.12.5 von docker. Probieren Sie `epm docker:install`",
"e.docker.compose.upgrade" : "Diese Anwendung benötigt mindestens Version %1$s von docker-compose. Probieren Sie `epm docker:install`",
"e.docker.up.failed" : "Docker konnte nicht gestartet werden. Die Details wurden in %1$s abgelegt",
"e.docker.stop.failed" : "Docker konnte nicht beendet werden. Die Details wurden in %1$s abgelegt",
"e.docker.down.failed" : "Das Docker Projekt konnte nicht bereinigt werden. Die Details wurden in %1$s abgelegt"
......
......@@ -26,6 +26,7 @@
"docker.hosts.block" : "\n### %1$s %2$s",
"docker.shell.choose" : "Choose the target container",
"docker.shell.connected" : "Connected to %1$s",
"docker.top.info" : "Display docker container statistics for %1$s",
"docker.status.components" : "Docker Components",
"docker.status.components.docker" : "Docker Engine %1$s",
"docker.status.components.compose" : "Docker Compose %1$s",
......@@ -48,7 +49,6 @@
"e.docker.upgrade.yml" : "Could not find docker-compose.yml",
"e.docker.os.unsupported" : "Your operating system is not supported",
"e.docker.docker.required" : "This application requires docker version 1.12.5. Try `epm docker:install`",
"e.docker.compose.upgrade" : "This application requires docker-compose version %1$s. Try `epm docker:install`",
"e.docker.up.failed" : "Starting docker failed. See %1$s for details",
"e.docker.stop.failed" : "Stopping docker failed. See %1$s for details",
"e.docker.down.failed" : "Cleaning docker project failed. See %1$s for details"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment