Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runnable via docker (no dependencies needed) #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ bin
.idea
db.sqlite
node_modules
src/Lw/Infrastructure/Ui/Web/Silex/Public/components
src/Lw/Infrastructure/Ui/Web/Silex/Public/components
src/Lw/Infrastructure/Ui/Web/cache
src/Lw/Infrastructure/Ui/Web/Silex/var
28 changes: 28 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "2"

services:
app_php:
ports:
- "4010:80"
rabbitmq:
ports:
- "5672:5672"
- "15672:15672"
elastic:
ports:
- "9200:9200"
- "9300:9300"
kibana:
ports:
- "5601:5601"
redis:
ports:
- "6379:6379"
development_php:
build: "docker/development"
working_dir: "/data/app"
entrypoint: ""
user: "deploy"
volumes:
- "$PWD:/data/app"
command: "/prepare-app.sh"
58 changes: 39 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
---
version: '2'

services:
queues:
container_name: lw_rabbit
app_php:
build: docker/php
restart: "always"
networks:
- "default"
volumes:
- "$PWD:/data/app"
working_dir: "/data/app"
command: "php -S 0.0.0.0:80 -t src/Lw/Infrastructure/Ui/Web/Silex/Public"
app_domain_events:
build: docker/php
restart: "always"
networks:
- "default"
volumes:
- "$PWD:/data/app"
working_dir: "/data/app"
command: "php bin/console domain:events:spread"
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"
container_name: lw_rabbit
networks:
- "default"
elastic:
container_name: lw_elastic
image: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
container_name: lw_elastic
networks:
- "default"
kibana:
container_name: lw_kibana
image: kibana
ports:
- "5601:5601"
links:
- elastic
container_name: lw_kibana
depends_on:
- elastic
environment:
- ELASTICSEARCH_URL=http://elastic:9200
- ELASTICSEARCH_URL=http://elastic:9200
networks:
- "default"
redis:
container_name: lw_redis
image: redis
ports:
- "6379:6379"
container_name: lw_redis
networks:
- "default"

networks:
default:
driver: bridge
19 changes: 19 additions & 0 deletions docker/development/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:6.7.0

ADD prepare-app.sh /prepare-app.sh

RUN apt-get update \
&& apt-get install php5 php5-sqlite -y \
&& php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& mv composer.phar /bin/composer \
&& chmod +x /prepare-app.sh /bin/composer \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd -g 1000 deploy \
&& useradd -m -g 1000 -u 1000 deploy

RUN mkdir /.npm /.config /.cache /.local \
&& chown 1000:1000 -R /.npm /.config /.cache /.local
5 changes: 5 additions & 0 deletions docker/development/prepare-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e

composer install --ignore-platform-reqs
php bin/doctrine orm:schema-tool:create
4 changes: 4 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM php:5.6-fpm

RUN touch /usr/local/etc/php/conf.d/php.ini \
&& echo 'date.timezone = "UTC"' >> /usr/local/etc/php/conf.d/php.ini
9 changes: 9 additions & 0 deletions src/Lw/Application/Service/Wish/AddWishRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

class AddWishRequest
{
/**
* @var string
*/
private $userId;
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $content;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Lw/Application/Service/Wish/AddWishService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class AddWishService extends WishService
public function execute($request = null)
{
$userId = $request->userId();
$address = $request->address();
$address = $request->email();
$content = $request->content();

$user = $this->findUserOrFail($userId);

$wish = $user->makeWish(
$wish = $user->makeWishNoAggregateVersion(
$this->wishRepository->nextIdentity(),
$address,
$content
Expand Down
6 changes: 6 additions & 0 deletions src/Lw/Application/Service/Wish/WishService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public function __construct(UserRepository $userRepository, WishRepository $wish
$this->wishRepository = $wishRepository;
}

/**
* @param $userId
*
* @return \Lw\Domain\Model\User\User
* @throws UserDoesNotExistException
*/
protected function findUserOrFail($userId)
{
$user = $this->userRepository->ofId(new UserId($userId));
Expand Down
2 changes: 1 addition & 1 deletion src/Lw/Domain/Model/User/LogInAttempted.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function email()
*/
public function occurredOn()
{
return $this->occurredOn;
return new \DateTime($this->occurredOn->format('Y-m-d H:i:s'));
}
}
5 changes: 4 additions & 1 deletion src/Lw/Domain/Model/User/UserRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class UserRegistered implements DomainEvent, PublishableDomainEvent
* @var UserId
*/
private $userId;
/**
* @var \DateTimeImmutable
*/
private $occurredOn;

public function __construct(UserId $userId)
Expand All @@ -29,6 +32,6 @@ public function userId()
*/
public function occurredOn()
{
return $this->occurredOn;
return new \DateTime($this->occurredOn->format('Y-m-d H:i:s'));
}
}
2 changes: 1 addition & 1 deletion src/Lw/Domain/Model/Wish/WishGranted.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function wishId()
*/
public function occurredOn()
{
return $this->occurredOn;
return new \DateTime($this->occurredOn->format('Y-m-d H:i:s'));
}
}
2 changes: 1 addition & 1 deletion src/Lw/Domain/Model/Wish/WishWasMade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public function content()
*/
public function occurredOn()
{
return $this->occurredOn;
return new \DateTime($this->occurredOn->format('Y-m-d H:i:s'));
}
}
2 changes: 1 addition & 1 deletion src/Lw/Infrastructure/Domain/Model/Wish/WishEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WishEmail extends Wish

public function __construct(WishId $wishId, UserId $userId, $email, $content)
{
parent::__construct($wishId, $userId, $content);
parent::__construct($wishId, $userId, $email, $content);

$this->setEmail($email);
$this->setContent($content);
Expand Down
3 changes: 2 additions & 1 deletion src/Lw/Infrastructure/Ui/Web/Silex/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Lw\Infrastructure\Persistence\Doctrine\EntityManagerFactory;
use Lw\Infrastructure\Service\HttpUserAdapter;
use Lw\Infrastructure\Service\TranslatingUserService;
use PhpAmqpLib\Connection\AMQPConnection;
use Silex\Provider\DoctrineServiceProvider;
use Silex\Provider\MonologServiceProvider;
use Silex\Provider;
Expand Down Expand Up @@ -72,7 +73,7 @@ public static function bootstrap()

$app['message_producer'] = $app->share(function () {
return new RabbitMqMessageProducer(
new AMQPStreamConnection('localhost', 5672, 'guest', 'guest')
new AMQPConnection('rabbitmq', 5672, 'guest', 'guest')
);
});

Expand Down