Commit 95db9c72 authored by Tobias Munk's avatar Tobias Munk

initial commit

parents
Pipeline #9863 failed with stages
.git
.vagrant
.env
data
vendor
runtime
web/assets
config/local.php
\ No newline at end of file
# Environment settings for docker-compose
COMPOSE_PROJECT_NAME=yii2-app
COMPOSE_FILE=./docker-compose.yml:./docker-compose.dev.yml
GITHUB_API_TOKEN=0000000000000000000000000000000000000000
STACK_PHP_IMAGE=registry-v2.hrzg.de/dmstr/yii2-app
\ No newline at end of file
.idea
vendor
.env
runtime
web/assets
docker-compose.override.yml
app.env
_artifacts
stages:
- build
- test
- deploy
- cleanup
before_script:
- export ISOLATION=buildref${CI_BUILD_REF}$(echo ${CI_BUILD_REF_NAME} | tr -dc '[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]')
- export COMPOSE_PROJECT_NAME=${ISOLATION}
- export APP_VERSION=$(git describe --always --dirty)
- export STACK_PHP_IMAGE=registry-v2.hrzg.de/dmstr/yii2-app:${APP_VERSION}
build:
stage: build
script:
- cp .env-dist .env
- docker-compose build --pull
test:
stage: test
script:
- cd tests
- cp .env-dist .env
- docker-compose run -e YII_ENV=test php codecept run
release:
stage: deploy
script:
- docker push ${STACK_PHP_IMAGE}
only:
- release
cleanup:
stage: cleanup
when: always
script:
- docker-compose kill
- docker-compose rm -fv --all
- docker-compose down --remove-orphans --rmi local
FROM dmstr/php
WORKDIR /app
ARG GITHUB_API_TOKEN
ADD composer.lock composer.json /app/
RUN composer install --prefer-dist --optimize-autoloader
ADD yii /app/
ADD ./web /app/web/
ADD ./src /app/src/
RUN cp src/app.env-dist src/app.env
RUN mkdir -p runtime web/assets && \
chmod -R 775 runtime web/assets && \
chown -R 1000:33 runtime web/assets
yii2-app
========
## Introduction
This is a minimal dockerized application template for Yii 2.0 Framework.
## Requirements
- [Docker Toolbox](https://www.docker.com/products/docker-toolbox)
- Docker `>=1.10`
- docker-compose `>=1.7.0`
## Setup
cp .env-dist .env
mkdir web/assets
Start stack
docker-compose up -d
Show containers
docker-compose ps
Create bash
docker-compose run --rm php bash
Run setup in container
$ composer install
## Develop
$ yii help
## Test
$ codecept run
### CLI
docker run dmstr/yii2-app yii
## Resources
- [Yii 2.0 Framework guide](http://www.yiiframework.com/doc-2.0/guide-index.html)
- [Docker documentation](https://docs.docker.com)
---
#### ![dmstr logo](http://t.phundament.com/dmstr-16-cropped.png) Built by [dmstr](http://diemeisterei.de)
\ No newline at end of file
actor: Tester
paths:
tests: tests/codeception
log: tests/codeception/_output
data: tests/codeception/_data
support: tests/codeception/_support
envs: tests/codeception/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/codeception/_data/dump.sql
{
"name": "dmstr/yii2-app",
"minimum-stability": "stable",
"require": {
"vlucas/phpdotenv": "2.*",
"yiisoft/yii2": "^2.0.8",
"yiisoft/yii2-bootstrap": "2.*"
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
This diff is collapsed.
version: '2'
services:
web:
volumes:
- ./web:/app/web
php:
build:
dockerfile: Dockerfile
context: .
args:
- GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
environment:
- PHP_USER_ID=1000
volumes:
- ./composer.json:/app/composer.json
- ./composer.lock:/app/composer.lock
- ./vendor:/app/vendor
- ./src:/app/src
- ./web:/app/web
- ./tests:/app/tests
- ./codeception.yml:/app/codeception.yml
\ No newline at end of file
version: '2'
services:
web:
image: phundament/nginx-one:1.9-5.0.2
environment:
- FASTCGI_PASS_HOST=php
depends_on:
- php
volumes_from:
- php
ports:
- 80
php:
image: ${STACK_PHP_IMAGE}
environment:
- GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
volumes:
- /app/web
\ No newline at end of file
YII_ENV=prod
YII_DEBUG=0
YII_TRACE_LEVEL=0
APP_NAME=yii2-app
APP_TITLE="Docker Yii 2.0 Application"
APP_ADMIN_EMAIL=${APP_NAME}@example.com
APP_COOKIE_VALIDATION_KEY=<insert-a-random-string-here>
APP_PRETTY_URLS=1
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Basic configuration, used in web and console applications
return [
'id' => 'app',
'language' => 'en',
'basePath' => dirname(__DIR__),
'vendorPath' => '@app/../vendor',
'runtimePath' => '@app/../runtime',
// Bootstrapped modules are loaded in every request
'bootstrap' => [
'log',
],
];
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'controllerNamespace' => 'app\commands',
];
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Version check
$version = is_file(__DIR__.'/../version') ? file_get_contents(__DIR__.'/../version') : 'dev';
defined('APP_VERSION') or define('APP_VERSION', $version);
// Load default settings via dotenv from file
$dotenv = new Dotenv\Dotenv(__DIR__.'/..', 'app.env');
$dotenv->load();
// Checks & validation
$dotenv->required('YII_DEBUG', ['', '0', '1', 'true', true]);
$dotenv->required('YII_ENV', ['dev', 'prod', 'test']);
$dotenv->required([
'YII_TRACE_LEVEL',
'APP_NAME',
'APP_COOKIE_VALIDATION_KEY',
]);
// Additional Validations
if (!preg_match('/^[a-z0-9_-]{3,16}$/', getenv('APP_NAME'))) {
throw new \Dotenv\Exception\ValidationException(
'APP_NAME must only be lowercase, dash or underscore and 3-16 characters long.'
);
}
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Define application aliases
Yii::setAlias('@app', dirname(__DIR__).'/..');
Yii::setAlias('@root', '@app/..');
Yii::setAlias('@runtime', dirname(__DIR__).'/../../runtime');
Yii::setAlias('@web', dirname(__DIR__).'/../web');
Yii::setAlias('@webroot', dirname(__DIR__).'/web');
// Load $merge configuration files
$applicationType = php_sapi_name() == 'cli' ? 'console' : 'web';
$env = YII_ENV;
$configDir = __DIR__;
return \yii\helpers\ArrayHelper::merge(
require("{$configDir}/common.php"),
require("{$configDir}/{$applicationType}.php"),
(file_exists("{$configDir}/common-{$env}.php")) ? require("{$configDir}/common-{$env}.php") : [],
(file_exists("{$configDir}/{$applicationType}-{$env}.php")) ? require("{$configDir}/{$applicationType}-{$env}.php") : [],
(file_exists(getenv('APP_CONFIG_FILE'))) ? getenv('APP_CONFIG_FILE') : []
);
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
// Settings for web-application only
return [
'components' => [
'errorHandler' => [
'errorAction' => 'site/error',
],
'request' => [
'cookieValidationKey' => getenv('APP_COOKIE_VALIDATION_KEY'),
],
'urlManager' => [
'enablePrettyUrl' => getenv('APP_PRETTY_URLS')
]
],
];
<?php
namespace app\controllers;
/*
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Yii;
use yii\web\Controller;
/**
* Site controller.
*/
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
/**
* Renders the start page.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}
<?php
/*
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use yii\helpers\Html;
/* @var $this \yii\web\View */
/* @var $content string */
$this->title = $this->title;
// Register asset bundle
\yii\bootstrap\BootstrapAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?= $content ?>
</div>
<footer class="footer">
<div class="container">
<hr/>
<p class="pull-left">
<span class="label label-primary">dmstr</span>
</p>
<p class="pull-right">
<span class="label label-default"><?= getenv('HOSTNAME') ?></span>
<span class="label label-default"><?= getenv('APP_NAME') ?></span>
<span class="label label-default"></span>
<span class="label label-warning <?= YII_ENV_PROD ? 'label-success' : 'label-danger' ?>"><?= YII_ENV ?></span>
<span class="label label-warning <?= YII_DEBUG ? '' : 'hidden' ?>">debug</span>
</p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php
/**
* @link http://www.diemeisterei.de/
*
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */
$this->title = $name;
?>
<div class="site-error container">
<h1 class="text-danger"><?= Html::encode($this->title) ?></h1>
<div class="well">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
<p>
<?= Html::a('Home Page', Yii::$app->homeUrl) ?>
</p>
</div>
<?php
/*
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/* @var $this yii\web\View */
$this->title .= 'Home';
?>
<div class="site-index">
<div class="jumbotron">
<div class="container">
<h1><?= getenv('APP_TITLE') ?></h1>
<p>
<?= \yii\helpers\Html::a(
'GitHub Project',
'https://github.com/dmstr/docker-yii2-app',
[
'target' => '_blank',
'class' => 'btn btn-primary'
]) ?>
</p>
</div>
</div>
<div class="container">
<h2>Start development bash</h2>
<p class="well">
<code>
docker-compose run php bash
</code>
</p>
<h2>Install packages</h2>
<p class="well">
<code>
$ composer require "dmstr/yii2-cms-metapackage"
</code>
</p>
</div>
</div>
COMPOSE_PROJECT_NAME=test-yii2-app
COMPOSE_FILE=../docker-compose.yml:./docker-compose.test.yml
\ No newline at end of file
<?php
// This is global bootstrap for autoloading
$rootPath = __DIR__.'/../..';
require($rootPath.'/vendor/autoload.php');
require($rootPath.'/src/config/env.php');
if (getenv('YII_ENV') !== 'test') {
echo "Error: YII_ENV must be set to 'test'\n";
exit;
}
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));
defined('YII_TEST_ENTRY_FILE') or define('YII_TEST_ENTRY_FILE', dirname(dirname(__DIR__)).'/web/index.php');
require_once($rootPath.'/vendor/yiisoft/yii2/Yii.php');
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
$_SERVER['SERVER_NAME'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
$_SERVER['SERVER_PORT'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
Yii::setAlias('@tests', dirname(__DIR__));
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
This diff is collapsed.
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
\ No newline at end of file
<?php
class ControllerTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
}
protected function tearDown()
{
}
// tests
public function testMe()
{
Yii::$app;
}
}
<?php
// Here you can initialize variables that will be available to your tests
version: '2'
services:
php:
volumes:
- ./tests:/app/tests
- ./codeception.yml:/app/codeception.yml
<?php
$rootPath = __DIR__.'/..';
require($rootPath.'/vendor/autoload.php');
require($rootPath.'/src/config/env.php');
defined('YII_DEBUG') or define('YII_DEBUG', (boolean)getenv('YII_DEBUG'));
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV'));
require($rootPath.'/vendor/yiisoft/yii2/Yii.php');
$config = require($rootPath.'/src/config/main.php');
$application = new yii\web\Application($config);
$application->run();
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
ini_set('memory_limit', '512M');
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/src/config/env.php');
defined('YII_DEBUG') or define('YII_DEBUG', (boolean)getenv('YII_DEBUG'));
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV'));
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/src/config/main.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
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