Skip to content
Snippets Groups Projects
Commit c974616e authored by jurgenhaas's avatar jurgenhaas
Browse files

Initial code

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #
# Drupal editor configuration normalization
# @see http://editorconfig.org/
# This is the top-most .editorconfig file; do not search in parent directories.
root = true
# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{composer.json,composer.lock}]
indent_size = 4
vendor
composer.lock
stages:
- test
- deploy
Test:
stage: test
except:
- tags
script:
- composer install
- ./vendor/bin/phpunit
Deploy:
stage: deploy
script:
- curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=${PACKAGIST_USERNAME}&apiToken=${PACKAGIST_API_TOKEN}" -d'{"repository":{"url":"'${CI_PROJECT_URL}'"}}'
# Docker Traefik
to be done.
{
"name": "lakedrops/docker-traefik",
"description": "Library to prepare local Traefik Docker container which is used by e.g. Docker4Drupal.",
"type": "library",
"keywords": ["Drupal", "Development", "Docker"],
"homepage": "https://gitlab.lakedrops.com/lakedrops/docker-traefik",
"license": "GPL-2.0+",
"authors": [
{
"name": "Jürgen Haas",
"email": "juergen@paragon-es.de",
"homepage": "https://www.paragon-es.de",
"role": "Drupal Expert"
},
{
"name": "Richard Papp",
"email": "richard.papp@boromino.com",
"homepage": "http://www.boromino.com",
"role": "Drupal Expert"
}
],
"support": {
"issues": "https://gitlab.lakedrops.com/lakedrops/docker-traefik/issues",
"source": "https://gitlab.lakedrops.com/lakedrops/docker-traefik/tree/master"
},
"require": {
"php": ">=5.4.5",
"symfony/filesystem": "^3.3",
"symfony/yaml": "^3.3"
},
"autoload": {
"psr-4": {
"LakeDrops\\DockerTraefik\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^4.4.0"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
verbose="true"
>
<testsuites>
<testsuite name="docker-traefik">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
<?php
namespace LakeDrops\DockerTraefik;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;
class Traefik {
/** @var string */
protected $name;
/** @var Filesystem */
protected $fs;
/**
* Traefik constructor.
*
* @param string $name
* Name of the network to be created which needs to match the container
* prefix of your project you would like to handle with Traefik.
*/
public function __construct($name) {
$this->name = $name;
$this->fs = new Filesystem();
}
/**
* Update the Traefik container.
*/
public function update() {
// Update host wider traefik container
$traefikPath = $_SERVER['HOME'] . '/.traefik';
$traefikFile = $traefikPath . '/docker-compose.yml';
if ($this->fs->exists($traefikFile)) {
$traefik = Yaml::parse(file_get_contents($traefikFile));
}
else {
$this->fs->mkdir($traefikPath);
$traefik = [
'version' => '2',
'services' => [
'traefik' => [
'image' => 'traefik',
'restart' => 'unless-stopped',
'command' => '-c /dev/null --web --docker --logLevel=DEBUG',
'networks' => [],
'ports' => [
'8000:80',
'8080:8080',
],
'volumes' => [
'/var/run/docker.sock:/var/run/docker.sock',
],
],
],
'networks' => [],
];
}
if (!in_array($this->name, $traefik['services']['traefik']['networks'])) {
$traefik['services']['traefik']['networks'][] = $this->name;
$traefik['networks'][$this->name] = [
'external' => [
'name' => $this->name . '_default',
],
];
file_put_contents($traefikFile, Yaml::dump($traefik, 9, 2));
exec('docker network create ' . $this->name . '_default');
exec('docker-compose -f ' . $traefikFile . ' --project-name traefik stop');
exec('docker-compose -f ' . $traefikFile . ' --project-name traefik up -d');
}
}
}
<?php
/**
* @file
* Contains \LakeDrops\DockerTraefik\Tests\TraefikTest.
*/
namespace LakeDrops\DockerTraefik\Tests;
use LakeDrops\DockerTraefik\Traefik;
use PHPUnit\Framework\TestCase;
/**
* Tests composer library functionality.
*/
class TraefikTest extends TestCase {
static $name = 'docker-traefik';
/**
* Test if we can initialize the main class.
*/
public function testComposerInstallAndUpdate() {
$traefik = new Traefik('test');
$this->assertInstanceOf('LakeDrops\DockerTraefik\Traefik', $traefik);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment