Skip to content

Commit

Permalink
Jekyll Service
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph3nol committed Oct 18, 2017
1 parent e6275fe commit 65ca024
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/jekyll-project/.docker-arch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Docker Arch - Jekyll Project
services:
# Jekyll App
- type: jekyll
path: ../app
host: localhost
2 changes: 2 additions & 0 deletions examples/jekyll-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app/*
!app/.gitkeep
Empty file.
64 changes: 64 additions & 0 deletions src/Application/DockerContainer/JekyllDockerContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Ph3\DockerArch\Application\DockerContainer;

use Ph3\DockerArch\Domain\DockerContainer\Model\DockerContainer;
use Ph3\DockerArch\Domain\DockerContainer\Model\DockerContainerInterface;
use Ph3\DockerArch\Domain\TemplatedFile\Model\TemplatedFile;

/**
* @author Cédric Dugat <cedric@dugat.me>
*/
class JekyllDockerContainer extends DockerContainer
{
/**
* {@inheritdoc}
*/
public function getPackageManager(): string
{
return DockerContainerInterface::PACKAGE_MANAGER_TYPE_APK;
}

/**
* {@inheritdoc}
*/
public function execute(): void
{
$service = $this->getService();

$this->setFrom('jekyll/jekyll:latest');

$this->setWorkingDir($this->getMainPath());

// EntryPoint.
$service
->addTemplatedFile(new TemplatedFile(
'entrypoint.sh',
'Service/Jekyll/entrypoint.sh.twig'
));
$this
->addCopyEntry([
'local' => 'entrypoint.sh',
'remote' => '/root/entrypoint.sh',
])
->addCommand('chmod +x /root/entrypoint.sh')
->setEntryPoint(['/root/entrypoint.sh']);

// Ports.
$this->addEnvPort('JEKYLL', ['from' => '4004', 'to' => '4000']);
}

/**
* {@inheritdoc}
*/
public function postExecute(): void
{
// UI.
$port = reset($this->getService()->getDockerContainer()->getPorts());
$this->getService()->addUIAccess([
'url' => 'localhost',
'port' => $port['from'],
'label' => 'Website (from Watching)',
]);
}
}
12 changes: 12 additions & 0 deletions src/Application/Resources/views/Service/Jekyll/entrypoint.sh.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% set mainPath = service.dockerContainer.mainPath %}
#!/bin/sh
set -e

chown jekyll:jekyll {{ mainPath }}

if [ ! -f "{{ mainPath }}/_config.yml" ]; then
echo "--> No Jekyll project - Let's creating it..."
jekyll new .
fi

jekyll serve
23 changes: 23 additions & 0 deletions src/Application/Service/JekyllService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Ph3\DockerArch\Application\Service;

use Ph3\DockerArch\Domain\Service\Model\AbstractService;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Cédric Dugat <cedric@dugat.me>
*/
class JekyllService extends AbstractService implements WebInterface, CliInterface
{
const NAME = 'jekyll';

/**
* {@inheritdoc}
*/
public function getOptionsResolver(): Options
{
return new OptionsResolver();
}
}
1 change: 1 addition & 0 deletions src/UI/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private function getAvailableServicesFqcns(): array
'php' => '\\Ph3\\DockerArch\\Application\\Service\\PHPService',
'rabbitmq' => '\\Ph3\\DockerArch\\Application\\Service\\RabbitMQService',
'redis' => '\\Ph3\\DockerArch\\Application\\Service\\RedisService',
'jekyll' => '\\Ph3\\DockerArch\\Application\\Service\\JekyllService',
];
}
}

0 comments on commit 65ca024

Please sign in to comment.