Skip to content

Commit

Permalink
Require datbase mode to be explicitly defined and recommend mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Dec 21, 2022
1 parent b4f5ed2 commit 100cb13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 35 deletions.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,37 @@ This is the preferred and currently only tested way to run the app.

You must provide a tmdb api key (get one [here](https://www.themoviedb.org/settings/api)).

Example default (using sqlite):
Example using MySQL (recommended):

```shell
$ docker volume create movary-storage
$ docker run --rm -d \
--name movary \
-p 80:80 \
-e TMDB_API_KEY="<tmdb_key>" \
-e DATABASE_MODE="mysql" \
-e DATABASE_MYSQL_HOST="<host>" \
-e DATABASE_MYSQL_NAME="<db_name>" \
-e DATABASE_MYSQL_USER="<db_user>" \
-e DATABASE_MYSQL_PASSWORD="<db_password>" \
-v movary-storage:/app/storage \
leepeuker/movary:latest
```

Example using SQLite:

```shell
$ docker volume create movary-storage
$ docker run --rm -d \
--name movary \
-p 80:80 \
-e DATABASE_MODE="sqlite" \
-e TMDB_API_KEY="<tmdb_key>" \
-v movary-storage:/app/storage
-e DATABASE_MODE="sqlite" \
-v movary-storage:/app/storage \
leepeuker/movary:latest
```

Example docker-compose.yml with a mysql server
Example docker-compose.yml with a MySQL server

```yml
version: "3.5"
Expand All @@ -88,7 +104,7 @@ services:
ports:
- "80:80"
environment:
TMDB_API_KEY: "XXX"
TMDB_API_KEY: "<tmdb_key>"
DATABASE_MODE: "mysql"
DATABASE_MYSQL_HOST: "mysql"
DATABASE_MYSQL_NAME: "movary"
Expand All @@ -103,7 +119,7 @@ services:
MYSQL_DATABASE: "movary"
MYSQL_USER: "movary_user"
MYSQL_PASSWORD: "movary_password"
MYSQL_ROOT_PASSWORD: "XXX"
MYSQL_ROOT_PASSWORD: "<mysql_root_password>"
volumes:
- movary-db:/var/lib/mysql

Expand All @@ -116,7 +132,7 @@ volumes:
You can run movary commands in docker via e.g. `docker exec movary php bin/console.php`

1. Execute all missing database migrations, e.g. like this: `php bin/console.php database:migration:migrate` (on initial installation and after every update)
1. Execute missing database migrations: `php bin/console.php database:migration:migrate` (on initial installation and ideally after every update)
2. Create initial user
- via web UI by visiting the movary lading page for the first time
- via cli `php bin/console.php user:create [email protected] password username`
Expand All @@ -134,7 +150,7 @@ MIN_RUNTIME_IN_SECONDS_FOR_JOB_PROCESSING=15

### Database
# Supported modes: sqlite or mysql
DATABASE_MODE=sqlite
DATABASE_MODE=
DATABASE_SQLITE=storage/movary.sqlite
DATABASE_MYSQL_HOST=
DATABASE_MYSQL_PORT=
Expand All @@ -150,7 +166,7 @@ TMDB_API_KEY=
TMDB_ENABLE_IMAGE_CACHING=0

### Logging
LOG_LEVEL=
LOG_LEVEL=warning
LOG_ENABLE_STACKTRACE=0
LOG_ENABLE_FILE_LOGGING=0
```
Expand Down
51 changes: 26 additions & 25 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
use Psr\Container\ContainerInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Twig;

class Factory
{
private const DEFAULT_LOG_LEVEL = LogLevel::WARNING;

private const DEFAULT_APPLICATION_VERSION = null;

private const DEFAULT_TMDB_IMAGE_CACHING = false;
Expand All @@ -47,8 +50,6 @@ class Factory

private const DEFAULT_ENABLE_FILE_LOGGING = false;

private const DEFAULT_DATABASE_MODE = 'sqlite';

public static function createConfig() : Config
{
$dotenv = Dotenv::createMutable(__DIR__ . '/..');
Expand Down Expand Up @@ -129,15 +130,9 @@ public static function createImageCacheService(ContainerInterface $container) :

public static function createJobQueueScheduler(ContainerInterface $container, Config $config) : JobQueueScheduler
{
try {
$enableImageCaching = $config->getAsBool('TMDB_ENABLE_IMAGE_CACHING');
} catch (OutOfBoundsException) {
$enableImageCaching = self::DEFAULT_TMDB_IMAGE_CACHING;
}

return new JobQueueScheduler(
$container->get(JobQueueApi::class),
$enableImageCaching
self::getTmdbEnabledImageCaching($config)
);
}

Expand Down Expand Up @@ -251,35 +246,23 @@ public static function createTwigFilesystemLoader() : Twig\Loader\FilesystemLoad

public static function createUrlGenerator(ContainerInterface $container, Config $config) : UrlGenerator
{
try {
$enableImageCaching = $config->getAsBool('TMDB_ENABLE_IMAGE_CACHING');
} catch (OutOfBoundsException) {
$enableImageCaching = false;
}

return new UrlGenerator(
$container->get(TmdbUrlGenerator::class),
$container->get(ImageCacheService::class),
$enableImageCaching
self::getTmdbEnabledImageCaching($config)
);
}

public static function getDatabaseMode(Config $config) : string
{
try {
$databaseMode = $config->getAsString('DATABASE_MODE');
} catch (OutOfBoundsException) {
$databaseMode = self::DEFAULT_DATABASE_MODE;
}

return $databaseMode;
return $config->getAsString('DATABASE_MODE');
}

private static function createLoggerStreamHandlerFile(ContainerInterface $container, Config $config) : StreamHandler
{
$streamHandler = new StreamHandler(
__DIR__ . '/../tmp/app.log',
$config->getAsString('LOG_LEVEL')
self::getLogLevel($config)
);
$streamHandler->setFormatter($container->get(LineFormatter::class));

Expand All @@ -288,12 +271,30 @@ private static function createLoggerStreamHandlerFile(ContainerInterface $contai

private static function createLoggerStreamHandlerStdout(ContainerInterface $container, Config $config) : StreamHandler
{
$streamHandler = new StreamHandler('php://stdout', $config->getAsString('LOG_LEVEL'));
$streamHandler = new StreamHandler('php://stdout', self::getLogLevel($config));
$streamHandler->setFormatter($container->get(LineFormatter::class));

return $streamHandler;
}

private static function getLogLevel(Config $config) : string
{
try {
return $config->getAsString('LOG_LEVEL');
} catch (OutOfBoundsException) {
return self::DEFAULT_LOG_LEVEL;
}
}

private static function getTmdbEnabledImageCaching(Config $config) : bool
{
try {
return $config->getAsBool('TMDB_ENABLE_IMAGE_CACHING');
} catch (OutOfBoundsException) {
return self::DEFAULT_TMDB_IMAGE_CACHING;
}
}

public function createProcessJobCommand(ContainerInterface $container, Config $config) : Command\ProcessJobs
{
try {
Expand Down
4 changes: 3 additions & 1 deletion src/JobQueue/JobQueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public function updateJobStatus(int $id, JobStatus $status) : void
'job_status' => (string)$status,
'updated_at' => (string)DateTime::create(),
],
['id' => $id],
[
'id' => $id
],
);
}
}

0 comments on commit 100cb13

Please sign in to comment.