diff --git a/.s2i/environment b/.s2i/environment new file mode 100644 index 00000000..5355e870 --- /dev/null +++ b/.s2i/environment @@ -0,0 +1,3 @@ +DOCUMENTROOT=/public +SHORT_OPEN_TAG=ON +APP_LOG=errorlog \ No newline at end of file diff --git a/config/app.php b/config/app.php index 4fc7a63f..307f6691 100644 --- a/config/app.php +++ b/config/app.php @@ -13,7 +13,7 @@ | */ - 'env' => env('APP_ENV', 'production'), + 'env' => env('APP_ENV', 'development'), /* |-------------------------------------------------------------------------- @@ -26,7 +26,7 @@ | */ - 'debug' => env('APP_DEBUG', false), + 'debug' => env('APP_DEBUG', true), /* |-------------------------------------------------------------------------- @@ -39,7 +39,7 @@ | */ - 'url' => env('APP_URL', 'http://localhost'), + 'url' => env('OPENSHIFT_BUILD_NAME') ? ( 'http://'.preg_replace('/^(.*)-[\d]+$/','${1}',env('OPENSHIFT_BUILD_NAME', 'laravel-mysql-example-1')).'-'.env('OPENSHIFT_BUILD_NAMESPACE').'.'.env('ROUTER_SHARD', '44fs').'.'.env('CLUSTER_NAME', 'preview').'.openshiftapps.com' ) : env('APP_URL', 'http://localhost'), /* |-------------------------------------------------------------------------- @@ -91,7 +91,7 @@ | */ - 'key' => env('APP_KEY'), + 'key' => env('APP_KEY', 'base64:WvqIZriSQBJAlFyHQ3zrMUQbzLB9a42v/vQRACDAdqA='), 'cipher' => 'AES-256-CBC', diff --git a/config/database.php b/config/database.php index 8451a62f..dc38bfcf 100644 --- a/config/database.php +++ b/config/database.php @@ -26,7 +26,7 @@ | */ - 'default' => env('DB_CONNECTION', 'mysql'), + 'default' => env('DB_CONNECTION', 'sqlite'), /* |-------------------------------------------------------------------------- @@ -54,8 +54,8 @@ 'mysql' => [ 'driver' => 'mysql', - 'host' => env('DB_HOST', 'localhost'), - 'port' => env('DB_PORT', '3306'), + 'host' => env(strtoupper(env('DB_SERVICE_NAME', 'MYSQL')).'_SERVICE_HOST', env('DB_HOST', 'localhost')), + 'port' => env(strtoupper(env('DB_SERVICE_NAME', 'MYSQL')).'_SERVICE_PORT', env('DB_PORT', '3306')), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), @@ -68,8 +68,8 @@ 'pgsql' => [ 'driver' => 'pgsql', - 'host' => env('DB_HOST', 'localhost'), - 'port' => env('DB_PORT', '5432'), + 'host' => env(strtoupper(env('DB_SERVICE_NAME', 'PGSQL')).'_SERVICE_HOST', env('DB_HOST', 'localhost')), + 'port' => env(strtoupper(env('DB_SERVICE_NAME', 'PGSQL')).'_SERVICE_PORT', env('DB_PORT', '5432')), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), diff --git a/config/session.php b/config/session.php index b501055b..f3631e56 100644 --- a/config/session.php +++ b/config/session.php @@ -16,7 +16,7 @@ | */ - 'driver' => env('SESSION_DRIVER', 'file'), + 'driver' => env('SESSION_DRIVER', 'cookie'), /* |-------------------------------------------------------------------------- diff --git a/database/.gitignore b/database/.gitignore deleted file mode 100644 index 9b1dffd9..00000000 --- a/database/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.sqlite diff --git a/database/database.sqlite b/database/database.sqlite new file mode 100644 index 00000000..e69de29b diff --git a/migrate-database.sh b/migrate-database.sh new file mode 100755 index 00000000..c7ec8d68 --- /dev/null +++ b/migrate-database.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +echo "Migrating database 'php artisan migrate --force'..." +php artisan migrate --force diff --git a/openshift/templates/laravel-mysql.json b/openshift/templates/laravel-mysql.json new file mode 100644 index 00000000..a2713ff6 --- /dev/null +++ b/openshift/templates/laravel-mysql.json @@ -0,0 +1,448 @@ +{ + "kind": "Template", + "apiVersion": "v1", + "metadata": { + "name": "laravel-mysql-example", + "annotations": { + "description": "An example Laravel application with a MySQL database", + "tags": "quickstart,php,laravel,mysql", + "iconClass": "icon-laravel" + } + }, + "labels": { + "template": "laravel-mysql-example" + }, + "objects": [{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "laravel-mysql-example", + "annotations": { + "description": "Exposes and load balances the application pods" + } + }, + "spec": { + "ports": [{ + "name": "web", + "port": 8080, + "targetPort": 8080 + }], + "selector": { + "name": "laravel-mysql-example" + } + } + }, { + "kind": "Route", + "apiVersion": "v1", + "metadata": { + "name": "laravel-mysql-example" + }, + "spec": { + "host": "${APPLICATION_DOMAIN}", + "to": { + "kind": "Service", + "name": "laravel-mysql-example" + } + } + }, { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "laravel-mysql-example", + "annotations": { + "description": "Keeps track of changes in the application image" + } + } + }, { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "laravel-mysql-example", + "annotations": { + "description": "Defines how to build the application" + } + }, + "spec": { + "source": { + "type": "Git", + "git": { + "uri": "${SOURCE_REPOSITORY_URL}", + "ref": "${SOURCE_REPOSITORY_REF}" + }, + "contextDir": "${CONTEXT_DIR}" + }, + "strategy": { + "type": "Source", + "sourceStrategy": { + "from": { + "kind": "ImageStreamTag", + "namespace": "openshift", + "name": "php:5.6" + } + } + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "laravel-mysql-example:latest" + } + }, + "triggers": [{ + "type": "ImageChange" + }, { + "type": "ConfigChange" + }, { + "type": "GitHub", + "github": { + "secret": "${GITHUB_WEBHOOK_SECRET}" + } + }] + } + }, { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "${VOLUME_CAPACITY}" + } + } + } + }, { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "laravel-mysql-example", + "annotations": { + "description": "Defines how to deploy the application server" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "recreateParams": { + "pre": { + "failurePolicy": "Retry", + "execNewPod": { + "command": [ + "./migrate-database.sh" + ], + "containerName": "laravel-mysql-example" + } + } + } + }, + "triggers": [{ + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "laravel-mysql-example" + ], + "from": { + "kind": "ImageStreamTag", + "name": "laravel-mysql-example:latest" + } + } + }, { + "type": "ConfigChange" + }], + "replicas": 1, + "selector": { + "name": "laravel-mysql-example" + }, + "template": { + "metadata": { + "name": "laravel-mysql-example", + "labels": { + "name": "laravel-mysql-example" + } + }, + "spec": { + "containers": [{ + "name": "laravel-mysql-example", + "image": "laravel-mysql-example", + "ports": [{ + "containerPort": 8080 + }], + "readinessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 3, + "httpGet": { + "path": "/health.php", + "port": 8080 + } + }, + "livenessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 30, + "httpGet": { + "path": "/", + "port": 8080 + } + }, + "env": [{ + "name": "CLUSTER_NAME", + "value": "${CLUSTER_NAME}" + }, { + "name": "ROUTER_SHARD", + "value": "${ROUTER_SHARD}" + }, { + "name": "DB_SERVICE_NAME", + "value": "${DATABASE_SERVICE_NAME}" + }, { + "name": "DB_CONNECTION", + "value": "${DATABASE_ENGINE}" + }, { + "name": "DB_DATABASE", + "value": "${DATABASE_NAME}" + }, { + "name": "DB_USERNAME", + "value": "${DATABASE_USER}" + }, { + "name": "DB_PASSWORD", + "value": "${DATABASE_PASSWORD}" + }, { + "name": "APP_KEY", + "value": "${LARAVEL_APP_KEY}" + }, { + "name": "APP_ENV", + "value": "${LARAVEL_APP_ENV}" + }, { + "name": "APP_DEBUG", + "value": "${LARAVEL_APP_DEBUG}" + }, { + "name": "OPCACHE_REVALIDATE_FREQ", + "value": "${OPCACHE_REVALIDATE_FREQ}" + }], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + } + }] + } + } + } + }, { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "description": "Exposes the database server" + } + }, + "spec": { + "ports": [{ + "name": "mysql", + "port": 3306, + "targetPort": 3306 + }], + "selector": { + "name": "${DATABASE_SERVICE_NAME}" + } + } + }, { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "description": "Defines how to deploy the database" + } + }, + "spec": { + "strategy": { + "type": "Recreate" + }, + "triggers": [{ + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "mysql" + ], + "from": { + "kind": "ImageStreamTag", + "namespace": "openshift", + "name": "mysql:5.6" + } + } + }, { + "type": "ConfigChange" + }], + "replicas": 1, + "selector": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "template": { + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "labels": { + "name": "${DATABASE_SERVICE_NAME}" + } + }, + "spec": { + "containers": [{ + "name": "mysql", + "image": "mysql", + "ports": [{ + "containerPort": 3306 + }], + "readinessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 5, + "exec": { + "command": ["/bin/sh", "-i", "-c", "MYSQL_PWD='${DATABASE_PASSWORD}' mysql -h 127.0.0.1 -u ${DATABASE_USER} -D ${DATABASE_NAME} -e 'SELECT 1'"] + } + }, + "livenessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 30, + "tcpSocket": { + "port": 3306 + } + }, + "env": [{ + "name": "MYSQL_USER", + "value": "${DATABASE_USER}" + }, { + "name": "MYSQL_PASSWORD", + "value": "${DATABASE_PASSWORD}" + }, { + "name": "MYSQL_DATABASE", + "value": "${DATABASE_NAME}" + }], + "resources": { + "limits": { + "memory": "${MEMORY_MYSQL_LIMIT}" + } + }, + "volumeMounts": [{ + "name": "${DATABASE_SERVICE_NAME}-data", + "mountPath": "/var/lib/mysql/data" + }] + }], + "volumes": [{ + "name": "${DATABASE_SERVICE_NAME}-data", + "persistentVolumeClaim": { + "claimName": "${DATABASE_SERVICE_NAME}" + } + }] + } + } + } + }], + "parameters": [{ + "name": "SOURCE_REPOSITORY_URL", + "displayName": "Git Repository URL", + "description": "The URL of the repository with your application source code.", + "value": "https://github.com/luciddreamz/laravel-ex.git", + "required": true + }, { + "name": "SOURCE_REPOSITORY_REF", + "displayName": "Git Reference", + "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." + }, { + "name": "LARAVEL_APP_ENV", + "displayName": "Laravel Application Environment", + "description": "Determines the 'environment' your application is currently.", + "value": "development", + "required": true + }, { + "name": "LARAVEL_APP_DEBUG", + "displayName": "Laravel Application Debug Mode", + "description": "Enable or disable detailed error messages.", + "value": "true", + "required": true + }, { + "name": "OPCACHE_REVALIDATE_FREQ", + "displayName": "OPcache Revalidation Frequency", + "description": "How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.", + "value": "0" + }, { + "displayName": "Cluster Name", + "name": "CLUSTER_NAME", + "description": "The name of your current OpenShift cluster (console.CLUSTER_NAME.openshift.com).", + "value": "preview", + "required": true + }, { + "displayName": "Router Shard", + "name": "ROUTER_SHARD", + "description": "The router shard used by routes in your current OpenShift cluster (http://PROJECT_NAME-APPLICATION_NAME.ROUTER_SHARD.CLUSTER_NAME.openshiftapps.com/).", + "value": "44fs", + "required": true + }, { + "name": "MEMORY_LIMIT", + "displayName": "Memory Limit", + "description": "Maximum amount of memory the Laravel container can use.", + "value": "512Mi", + "required": true + }, { + "name": "MEMORY_MYSQL_LIMIT", + "displayName": "Memory Limit (MySQL)", + "description": "Maximum amount of memory the MySQL container can use.", + "value": "512Mi", + "required": true + }, { + "name": "VOLUME_CAPACITY", + "displayName": "Volume Capacity", + "description": "Volume space available for data, e.g. 512Mi, 2Gi", + "value": "1Gi", + "required": true + }, { + "name": "CONTEXT_DIR", + "displayName": "Context Directory", + "description": "Set this to the relative path to your project if it is not in the root of your repository." + }, { + "name": "APPLICATION_DOMAIN", + "displayName": "Application Hostname", + "description": "The exposed hostname that will route to the Laravel service, if left blank a value will be defaulted.", + "value": "" + }, { + "name": "GITHUB_WEBHOOK_SECRET", + "displayName": "GitHub Webhook Secret", + "description": "A secret string used to configure the GitHub webhook.", + "generate": "expression", + "from": "[a-zA-Z0-9]{40}" + }, { + "name": "DATABASE_SERVICE_NAME", + "displayName": "Database Service Name", + "value": "mysql", + "required": true + }, { + "name": "DATABASE_ENGINE", + "displayName": "Database Engine", + "description": "Database engine: mysql (default), pgsql, or sqlite.", + "value": "mysql", + "required": true + }, { + "name": "DATABASE_NAME", + "displayName": "Database Name", + "value": "default", + "required": true + }, { + "name": "DATABASE_USER", + "displayName": "Database User", + "value": "laravel", + "required": true + }, { + "name": "DATABASE_PASSWORD", + "displayName": "Database Password", + "generate": "expression", + "from": "[a-zA-Z0-9]{16}" + }, { + "name": "LARAVEL_APP_KEY", + "displayName": "Laravel Encryption Key", + "description": "Set this to a 32 character random string.", + "generate": "expression", + "from": "[\\w]{32}" + }] +} \ No newline at end of file diff --git a/openshift/templates/laravel-postgresql.json b/openshift/templates/laravel-postgresql.json new file mode 100644 index 00000000..bd19e5d6 --- /dev/null +++ b/openshift/templates/laravel-postgresql.json @@ -0,0 +1,448 @@ +{ + "kind": "Template", + "apiVersion": "v1", + "metadata": { + "name": "laravel-pgsql-example", + "annotations": { + "description": "An example Laravel application with a PostgreSQL database", + "tags": "quickstart,php,laravel,postgresql", + "iconClass": "icon-laravel" + } + }, + "labels": { + "template": "laravel-pgsql-example" + }, + "objects": [{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "laravel-pgsql-example", + "annotations": { + "description": "Exposes and load balances the application pods" + } + }, + "spec": { + "ports": [{ + "name": "web", + "port": 8080, + "targetPort": 8080 + }], + "selector": { + "name": "laravel-pgsql-example" + } + } + }, { + "kind": "Route", + "apiVersion": "v1", + "metadata": { + "name": "laravel-pgsql-example" + }, + "spec": { + "host": "${APPLICATION_DOMAIN}", + "to": { + "kind": "Service", + "name": "laravel-pgsql-example" + } + } + }, { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "laravel-pgsql-example", + "annotations": { + "description": "Keeps track of changes in the application image" + } + } + }, { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "laravel-pgsql-example", + "annotations": { + "description": "Defines how to build the application" + } + }, + "spec": { + "source": { + "type": "Git", + "git": { + "uri": "${SOURCE_REPOSITORY_URL}", + "ref": "${SOURCE_REPOSITORY_REF}" + }, + "contextDir": "${CONTEXT_DIR}" + }, + "strategy": { + "type": "Source", + "sourceStrategy": { + "from": { + "kind": "ImageStreamTag", + "namespace": "openshift", + "name": "php:5.6" + } + } + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "laravel-pgsql-example:latest" + } + }, + "triggers": [{ + "type": "ImageChange" + }, { + "type": "ConfigChange" + }, { + "type": "GitHub", + "github": { + "secret": "${GITHUB_WEBHOOK_SECRET}" + } + }] + } + }, { + "kind": "PersistentVolumeClaim", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "spec": { + "accessModes": [ + "ReadWriteOnce" + ], + "resources": { + "requests": { + "storage": "${VOLUME_CAPACITY}" + } + } + } + }, { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "laravel-pgsql-example", + "annotations": { + "description": "Defines how to deploy the application server" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "recreateParams": { + "pre": { + "failurePolicy": "Retry", + "execNewPod": { + "command": [ + "./migrate-database.sh" + ], + "containerName": "laravel-pgsql-example" + } + } + } + }, + "triggers": [{ + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "laravel-pgsql-example" + ], + "from": { + "kind": "ImageStreamTag", + "name": "laravel-pgsql-example:latest" + } + } + }, { + "type": "ConfigChange" + }], + "replicas": 1, + "selector": { + "name": "laravel-pgsql-example" + }, + "template": { + "metadata": { + "name": "laravel-pgsql-example", + "labels": { + "name": "laravel-pgsql-example" + } + }, + "spec": { + "containers": [{ + "name": "laravel-pgsql-example", + "image": "laravel-pgsql-example", + "ports": [{ + "containerPort": 8080 + }], + "readinessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 3, + "httpGet": { + "path": "/health.php", + "port": 8080 + } + }, + "livenessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 30, + "httpGet": { + "path": "/", + "port": 8080 + } + }, + "env": [{ + "name": "CLUSTER_NAME", + "value": "${CLUSTER_NAME}" + }, { + "name": "ROUTER_SHARD", + "value": "${ROUTER_SHARD}" + }, { + "name": "DB_SERVICE_NAME", + "value": "${DATABASE_SERVICE_NAME}" + }, { + "name": "DB_CONNECTION", + "value": "${DATABASE_ENGINE}" + }, { + "name": "DB_DATABASE", + "value": "${DATABASE_NAME}" + }, { + "name": "DB_USERNAME", + "value": "${DATABASE_USER}" + }, { + "name": "DB_PASSWORD", + "value": "${DATABASE_PASSWORD}" + }, { + "name": "APP_KEY", + "value": "${LARAVEL_APP_KEY}" + }, { + "name": "APP_ENV", + "value": "${LARAVEL_APP_ENV}" + }, { + "name": "APP_DEBUG", + "value": "${LARAVEL_APP_DEBUG}" + }, { + "name": "OPCACHE_REVALIDATE_FREQ", + "value": "${OPCACHE_REVALIDATE_FREQ}" + }], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + } + }] + } + } + } + }, { + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "description": "Exposes the database server" + } + }, + "spec": { + "ports": [{ + "name": "postgresql", + "port": 5432, + "targetPort": 5432 + }], + "selector": { + "name": "${DATABASE_SERVICE_NAME}" + } + } + }, { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "annotations": { + "description": "Defines how to deploy the database" + } + }, + "spec": { + "strategy": { + "type": "Recreate" + }, + "triggers": [{ + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "postgresql" + ], + "from": { + "kind": "ImageStreamTag", + "namespace": "openshift", + "name": "postgresql:9.5" + } + } + }, { + "type": "ConfigChange" + }], + "replicas": 1, + "selector": { + "name": "${DATABASE_SERVICE_NAME}" + }, + "template": { + "metadata": { + "name": "${DATABASE_SERVICE_NAME}", + "labels": { + "name": "${DATABASE_SERVICE_NAME}" + } + }, + "spec": { + "containers": [{ + "name": "postgresql", + "image": "postgresql", + "ports": [{ + "containerPort": 5432 + }], + "readinessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 5, + "exec": { + "command": [ "/bin/sh", "-i", "-c", "psql -h 127.0.0.1 -U ${DATABASE_USER} -q -d ${DATABASE_NAME} -c 'SELECT 1'"] + } + }, + "livenessProbe": { + "timeoutSeconds": 1, + "initialDelaySeconds": 30, + "tcpSocket": { + "port": 5432 + } + }, + "env": [{ + "name": "POSTGRESQL_USER", + "value": "${DATABASE_USER}" + }, { + "name": "POSTGRESQL_PASSWORD", + "value": "${DATABASE_PASSWORD}" + }, { + "name": "POSTGRESQL_DATABASE", + "value": "${DATABASE_NAME}" + }], + "resources": { + "limits": { + "memory": "${MEMORY_POSTGRESQL_LIMIT}" + } + }, + "volumeMounts": [{ + "name": "${DATABASE_SERVICE_NAME}-data", + "mountPath": "/var/lib/pgsql/data" + }] + }], + "volumes": [{ + "name": "${DATABASE_SERVICE_NAME}-data", + "persistentVolumeClaim": { + "claimName": "${DATABASE_SERVICE_NAME}" + } + }] + } + } + } + }], + "parameters": [{ + "name": "SOURCE_REPOSITORY_URL", + "displayName": "Git Repository URL", + "description": "The URL of the repository with your application source code.", + "value": "https://github.com/luciddreamz/laravel-ex.git", + "required": true + }, { + "name": "SOURCE_REPOSITORY_REF", + "displayName": "Git Reference", + "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." + }, { + "name": "LARAVEL_APP_ENV", + "displayName": "Laravel Application Environment", + "description": "Determines the 'environment' your application is currently.", + "value": "development", + "required": true + }, { + "name": "LARAVEL_APP_DEBUG", + "displayName": "Laravel Application Debug Mode", + "description": "Enable or disable detailed error messages.", + "value": "true", + "required": true + }, { + "name": "OPCACHE_REVALIDATE_FREQ", + "displayName": "OPcache Revalidation Frequency", + "description": "How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.", + "value": "0" + }, { + "displayName": "Cluster Name", + "name": "CLUSTER_NAME", + "description": "The name of your current OpenShift cluster (console.CLUSTER_NAME.openshift.com).", + "value": "preview", + "required": true + }, { + "displayName": "Router Shard", + "name": "ROUTER_SHARD", + "description": "The router shard used by routes in your current OpenShift cluster (http://PROJECT_NAME-APPLICATION_NAME.ROUTER_SHARD.CLUSTER_NAME.openshiftapps.com/).", + "value": "44fs", + "required": true + }, { + "name": "MEMORY_LIMIT", + "displayName": "Memory Limit", + "description": "Maximum amount of memory the Laravel container can use.", + "value": "512Mi", + "required": true + }, { + "name": "MEMORY_POSTGRESQL_LIMIT", + "displayName": "Memory Limit (PostgreSQL)", + "description": "Maximum amount of memory the PostgreSQL container can use.", + "value": "512Mi", + "required": true + }, { + "name": "VOLUME_CAPACITY", + "displayName": "Volume Capacity", + "description": "Volume space available for data, e.g. 512Mi, 2Gi", + "value": "1Gi", + "required": true + }, { + "name": "CONTEXT_DIR", + "displayName": "Context Directory", + "description": "Set this to the relative path to your project if it is not in the root of your repository." + }, { + "name": "APPLICATION_DOMAIN", + "displayName": "Application Hostname", + "description": "The exposed hostname that will route to the Laravel service, if left blank a value will be defaulted.", + "value": "" + }, { + "name": "GITHUB_WEBHOOK_SECRET", + "displayName": "GitHub Webhook Secret", + "description": "A secret string used to configure the GitHub webhook.", + "generate": "expression", + "from": "[a-zA-Z0-9]{40}" + }, { + "name": "DATABASE_SERVICE_NAME", + "displayName": "Database Service Name", + "value": "postgresql", + "required": true + }, { + "name": "DATABASE_ENGINE", + "displayName": "Database Engine", + "description": "Database engine: mysql, pgsql (default), or sqlite.", + "value": "pgsql", + "required": true + }, { + "name": "DATABASE_NAME", + "displayName": "Database Name", + "value": "default", + "required": true + }, { + "name": "DATABASE_USER", + "displayName": "Database User", + "value": "laravel", + "required": true + }, { + "name": "DATABASE_PASSWORD", + "displayName": "Database Password", + "generate": "expression", + "from": "[a-zA-Z0-9]{16}" + }, { + "name": "LARAVEL_APP_KEY", + "displayName": "Laravel Encryption Key", + "description": "Set this to a 32 character random string.", + "generate": "expression", + "from": "[\\w]{32}" + }] +} \ No newline at end of file diff --git a/openshift/templates/laravel-sqlite.json b/openshift/templates/laravel-sqlite.json new file mode 100644 index 00000000..2d99a2da --- /dev/null +++ b/openshift/templates/laravel-sqlite.json @@ -0,0 +1,279 @@ +{ + "kind": "Template", + "apiVersion": "v1", + "metadata": { + "name": "laravel-sqlite-example", + "annotations": { + "description": "An example Laravel application with a MySQL database", + "tags": "quickstart,php,laravel,sqlite", + "iconClass": "icon-laravel" + } + }, + "labels": { + "template": "laravel-sqlite-example" + }, + "objects": [{ + "kind": "Service", + "apiVersion": "v1", + "metadata": { + "name": "laravel-sqlite-example", + "annotations": { + "description": "Exposes and load balances the application pods" + } + }, + "spec": { + "ports": [{ + "name": "web", + "port": 8080, + "targetPort": 8080 + }], + "selector": { + "name": "laravel-sqlite-example" + } + } + }, { + "kind": "Route", + "apiVersion": "v1", + "metadata": { + "name": "laravel-sqlite-example" + }, + "spec": { + "host": "${APPLICATION_DOMAIN}", + "to": { + "kind": "Service", + "name": "laravel-sqlite-example" + } + } + }, { + "kind": "ImageStream", + "apiVersion": "v1", + "metadata": { + "name": "laravel-sqlite-example", + "annotations": { + "description": "Keeps track of changes in the application image" + } + } + }, { + "kind": "BuildConfig", + "apiVersion": "v1", + "metadata": { + "name": "laravel-sqlite-example", + "annotations": { + "description": "Defines how to build the application" + } + }, + "spec": { + "source": { + "type": "Git", + "git": { + "uri": "${SOURCE_REPOSITORY_URL}", + "ref": "${SOURCE_REPOSITORY_REF}" + }, + "contextDir": "${CONTEXT_DIR}" + }, + "strategy": { + "type": "Source", + "sourceStrategy": { + "from": { + "kind": "ImageStreamTag", + "namespace": "openshift", + "name": "php:5.6" + } + } + }, + "output": { + "to": { + "kind": "ImageStreamTag", + "name": "laravel-sqlite-example:latest" + } + }, + "triggers": [{ + "type": "ImageChange" + }, { + "type": "ConfigChange" + }, { + "type": "GitHub", + "github": { + "secret": "${GITHUB_WEBHOOK_SECRET}" + } + }] + } + }, { + "kind": "DeploymentConfig", + "apiVersion": "v1", + "metadata": { + "name": "laravel-sqlite-example", + "annotations": { + "description": "Defines how to deploy the application server" + } + }, + "spec": { + "strategy": { + "type": "Rolling", + "recreateParams": { + "pre": { + "failurePolicy": "Retry", + "execNewPod": { + "command": [ + "./migrate-database.sh" + ], + "containerName": "laravel-sqlite-example" + } + } + } + }, + "triggers": [{ + "type": "ImageChange", + "imageChangeParams": { + "automatic": true, + "containerNames": [ + "laravel-sqlite-example" + ], + "from": { + "kind": "ImageStreamTag", + "name": "laravel-sqlite-example:latest" + } + } + }, { + "type": "ConfigChange" + }], + "replicas": 1, + "selector": { + "name": "laravel-sqlite-example" + }, + "template": { + "metadata": { + "name": "laravel-sqlite-example", + "labels": { + "name": "laravel-sqlite-example" + } + }, + "spec": { + "containers": [{ + "name": "laravel-sqlite-example", + "image": "laravel-sqlite-example", + "ports": [{ + "containerPort": 8080 + }], + "readinessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 3, + "httpGet": { + "path": "/health.php", + "port": 8080 + } + }, + "livenessProbe": { + "timeoutSeconds": 3, + "initialDelaySeconds": 30, + "httpGet": { + "path": "/", + "port": 8080 + } + }, + "env": [{ + "name": "CLUSTER_NAME", + "value": "${CLUSTER_NAME}" + }, { + "name": "ROUTER_SHARD", + "value": "${ROUTER_SHARD}" + }, { + "name": "DB_CONNECTION", + "value": "${DATABASE_ENGINE}" + }, { + "name": "APP_KEY", + "value": "${LARAVEL_APP_KEY}" + }, { + "name": "APP_ENV", + "value": "${LARAVEL_APP_ENV}" + }, { + "name": "APP_DEBUG", + "value": "${LARAVEL_APP_DEBUG}" + }, { + "name": "OPCACHE_REVALIDATE_FREQ", + "value": "${OPCACHE_REVALIDATE_FREQ}" + }], + "resources": { + "limits": { + "memory": "${MEMORY_LIMIT}" + } + } + }] + } + } + } + }], + "parameters": [{ + "name": "SOURCE_REPOSITORY_URL", + "displayName": "Git Repository URL", + "description": "The URL of the repository with your application source code.", + "value": "https://github.com/luciddreamz/laravel-ex.git", + "required": true + }, { + "name": "SOURCE_REPOSITORY_REF", + "displayName": "Git Reference", + "description": "Set this to a branch name, tag or other ref of your repository if you are not using the default branch." + }, { + "name": "LARAVEL_APP_ENV", + "displayName": "Laravel Application Environment", + "description": "Determines the 'environment' your application is currently.", + "value": "development", + "required": true + }, { + "name": "LARAVEL_APP_DEBUG", + "displayName": "Laravel Application Debug Mode", + "description": "Enable or disable detailed error messages.", + "value": "true", + "required": true + }, { + "name": "OPCACHE_REVALIDATE_FREQ", + "displayName": "OPcache Revalidation Frequency", + "description": "How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.", + "value": "0" + }, { + "displayName": "Cluster Name", + "name": "CLUSTER_NAME", + "description": "The name of your current OpenShift cluster (console.CLUSTER_NAME.openshift.com).", + "value": "preview", + "required": true + }, { + "displayName": "Router Shard", + "name": "ROUTER_SHARD", + "description": "The router shard used by routes in your current OpenShift cluster (http://PROJECT_NAME-APPLICATION_NAME.ROUTER_SHARD.CLUSTER_NAME.openshiftapps.com/).", + "value": "44fs", + "required": true + }, { + "name": "MEMORY_LIMIT", + "displayName": "Memory Limit", + "description": "Maximum amount of memory the Laravel container can use.", + "value": "512Mi", + "required": true + }, { + "name": "CONTEXT_DIR", + "displayName": "Context Directory", + "description": "Set this to the relative path to your project if it is not in the root of your repository." + }, { + "name": "APPLICATION_DOMAIN", + "displayName": "Application Hostname", + "description": "The exposed hostname that will route to the Laravel service, if left blank a value will be defaulted.", + "value": "" + }, { + "name": "GITHUB_WEBHOOK_SECRET", + "displayName": "GitHub Webhook Secret", + "description": "A secret string used to configure the GitHub webhook.", + "generate": "expression", + "from": "[a-zA-Z0-9]{40}" + }, { + "name": "DATABASE_ENGINE", + "displayName": "Database Engine", + "description": "Database engine: mysql, pgsql, or sqlite (default).", + "value": "sqlite", + "required": true + }, { + "name": "LARAVEL_APP_KEY", + "displayName": "Laravel Encryption Key", + "description": "Set this to a 32 character random string.", + "generate": "expression", + "from": "[\\w]{32}" + }] +} \ No newline at end of file diff --git a/public/health.php b/public/health.php new file mode 100644 index 00000000..9c8bca74 --- /dev/null +++ b/public/health.php @@ -0,0 +1,28 @@ +getMessage()); +} + +echo "OK"; +?> \ No newline at end of file diff --git a/readme.md b/readme.md index 7f8816d6..88171754 100644 --- a/readme.md +++ b/readme.md @@ -1,27 +1,90 @@ -# Laravel PHP Framework +Laravel 5.2 Quickstart on OpenShift +=================================== +[Laravel](http://laravel.com/) is a free, open source PHP web application framework, designed for the development of model–view–controller (MVC) web applications. -[![Build Status](https://travis-ci.org/laravel/framework.svg)](https://travis-ci.org/laravel/framework) -[![Total Downloads](https://poser.pugx.org/laravel/framework/d/total.svg)](https://packagist.org/packages/laravel/framework) -[![Latest Stable Version](https://poser.pugx.org/laravel/framework/v/stable.svg)](https://packagist.org/packages/laravel/framework) -[![Latest Unstable Version](https://poser.pugx.org/laravel/framework/v/unstable.svg)](https://packagist.org/packages/laravel/framework) -[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://packagist.org/packages/laravel/framework) +This quickstart was created to make it easy to get started with Laravel 5.2 on OpenShift v3. -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching. +The simplest way to install this application is to use the OpenShift quickstart template. To install the quickstart, follow [these directions](#installation). -Laravel is accessible, yet powerful, providing tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked. +## Installation ## -## Official Documentation +1. Create an account at [http://www.openshift.com/devpreview/register.html](http://www.openshift.com/devpreview/register.html) -Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs). +2. [Install the OpenShift CLI tools](https://docs.openshift.com/online/getting_started/beyond_the_basics.html#btb-installing-the-openshift-cli) -## Contributing +3. Add the Laravel template(s) to your project: -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions). + ``` + $ oc create -f https://raw.githubusercontent.com/luciddreamz/laravel-ex/master/openshift/templates/laravel-mysql.json + ``` + or -## Security Vulnerabilities + ``` + $ oc create -f https://raw.githubusercontent.com/luciddreamz/laravel-ex/master/openshift/templates/laravel-postgresql.json + ``` + or -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed. + ``` + $ oc create -f https://raw.githubusercontent.com/luciddreamz/laravel-ex/master/openshift/templates/laravel-sqlite.json + ``` -## License +4. Fork this GitHub repo -The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). +5. From the [web console](https://console.preview.openshift.com/console/), select your project, click *Add to Project*, and select the Laravel template under the PHP heading + +6. Replace the user name in the Git Repository URL parameter with your GitHub user name to point the template to your fork + +7. Scroll to the bottom of the page and click *[ Create ]* to deploy your application + +8. Follow [these instructions](https://docs.openshift.com/online/getting_started/basic_walkthrough.html#bw-configuring-automated-builds) to configure automated builds, allowing you to push your code to your GitHub repo and automatically trigger a new deployment + +## OpenShift Considerations ## +These are some special considerations you may need to keep in mind when running your application on OpenShift. + +### Local vs. Remote Development ### +This Laravel quickstart provides separate configuration files for both local and remote development. Use `.env` for local development, and `.s2i/environment` for remote development. + +### Remote Development ### +Your application is configured to automatically use an OpenShift MySQL, PostgreSQL, or SQLite database in when deployed on OpenShift using the included templates (see `openshift/templates`). + +Additionally, your `APP_ENV`, `APP_URL`, and `APP_KEY` can be set by following the [installation](#installation) instructions with the included templates. + +### Laravel Migrations ### +The `php artisan migrate --force` command is automatically executed during deployment when using any of the included templates (see `openshift/templates`). + +### Composer ### +During the build process, `composer install` is automatically executed over the root directory. See the [PHP 5.6 builder image](https://github.com/sclorg/s2i-php-container/tree/master/5.6) for more details, or more specifically see [here](https://github.com/sclorg/s2i-php-container/blob/master/5.6/s2i/bin/assemble#L9-L26). + +### 'Development' Mode ### +By default, this Quickstart is configured in 'development' mode to make debugging your application easier. + +When you develop your Laravel application in OpenShift, you can also enable the 'production' environment by setting environment variables, using the `oc` client, like: + +``` +$ oc get services +NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE +laravel-mysql-example 172.30.79.234 8080/TCP 23m +$ oc set env dc/laravel-mysql-example LARAVEL_APP_ENV=production LARAVEL_APP_DEBUG=false OPCACHE_REVALIDATE_FREQ=2 +``` + +Next, run `oc status` to confirm that an updated deployment has been kicked off. + +For more information on environment variables impacting PHP behavior on OpenShift, see the [PHP 5.6 builder image](https://github.com/sclorg/s2i-php-container/tree/master/5.6#environment-variables). + +For more information on Laravel environment variables, see the [Laravel environment configuration documentation](https://laravel.com/docs/5.2/configuration#environment-configuration). + +### Log Files ### +Your application is configured to use the OpenShift log directory. You can use the `oc logs` command to stream the latest log file entries from your running pod: + +``` +$ oc get pods +NAME READY STATUS RESTARTS AGE +laravel-mysql-example-1-build 0/1 Completed 0 26m +laravel-mysql-example-1-hj2k1 1/1 Running 0 23m +$ oc logs laravel-mysql-example-1-hj2k1 +``` + +To stop tailing the logs, press *Ctrl + c*. + +## Additional Resources ## +Documentation for the Laravel framework can be found on the [Laravel website](http://laravel.com/docs). Check out OpenShift's [Documentation](https://docs.openshift.com/online/using_images/s2i_images/php.html) for help running PHP on OpenShift. \ No newline at end of file