-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
Provide a recipe for Google App Engine #177
Comments
Indeed, it would be great to get info about it. I haven't deployed Yii 2 to GAE so if you did, please share your experience. |
@samdark The above is basically my experience. To that I could add that the deployment is done via a Dockerfile and app.yaml files. What other details shall I provide? |
Well, examples of such files would be cool. |
I am attaching 2 Dockerfiles:
to deploy this to GAE, place second Dockerfile and app.yaml into your yii2 project, change the settings to suit your app and run, for example
Once it's deployed, ssh to your GAE instance (via a google web console), run
to get into your worker instance and then execute one of the gcsfuse mount commands. Since I am using fstab with gcsfuse I do
to mount all gs buckets as folders, as described in the /etc/fstab. The latter is done, by, for example
|
I don't know much about either GAE or dockers but I've seen a talk about a custom docker images they made for running PHP on their App Engine Flexible Runtime: They where also talking about PHP security patches they added to their images. see it here: https://youtu.be/9PedC_6ZC3Q?t=7m19s |
I just deployed a similar template to this to a flex engine which is same as the advanced one except that it has My steps where:
runtime: php
env: flex
api_version: 1
service: auth
runtime_config:
document_root: auth/web
beta_settings:
cloud_sql_instances: "[connectionName]"
env_variables:
# framework
YII_DEBUG: false
YII_ENV: prod
#db
POSTGRES_DSN: pgsql:dbname=alpha;host=/cloudsql/[connectionName]
POSTGRES_USER: [user]
POSTGRES_PASSWORD: [your-pass]
POSTGRES_PORT: 5432
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
handlers:
- url: /.*
script: index.php NOTE: I don't think that is the proper way to create microservices. You may better have an
'db' => [
'class' => 'yii\db\Connection',
'dsn' => getenv('POSTGRES_DSN'),
'username' => getenv('POSTGRES_USER'),
'password' => getenv('POSTGRES_PASSWORD'),
'charset' => 'utf8',
'enableSchemaCache' => true,
'schemaCacheDuration' => 3600,
'schemaCache' => 'cache',
], You can also change the entry script to this in case you think you may need to enable debug mode in their server: defined('YII_DEBUG') or define('YII_DEBUG', getenv('YII_DEBUG') === 'true');
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV') ?: 'prod');
Which I guess should be auto merged with their nginx configs that you can see here: https://github.com/GoogleCloudPlatform/php-docker/blob/4454562b9be8134d630feded98a5bdb206e686ab/php-base/nginx.conf#L106
"require": {
"php": "7.2.*",
"ext-gd": "*",
"ext-redis": "*",
"ext-intl": "*",
...
}, NOTE: That documentation says you can enable them by adding a
"post-install-cmd": [
"php init --env=Production --overwrite=All",
"php yii migrate/up --interactive=0"
],
There is many options you can also add like manually set version |
There is also a list of disabled functions here:
These needed could be whitelisted in the Yaml file within a comma separated string. I had to add this to make the yii2-queue extension work by runnig
|
@tunecino I just found your posts here about your experiences with yii2 and Google Cloud Platform... It is really helpful!! Actually we are running Craft CMS. But since it is based on yii2 I thought you might be able to help. Are you still running yii2 on GCP Appengine Flex? We are currently experiencing issues with the image transform queue. After a deployment we do a Right now I'm trying https://plugins.craftcms.com/async-queue as a solution. Did you have similar issues? Our app.yaml:
We are running Craft 4. |
@michaelhunziker I remember that I did opt out from Flex and switched to GCP AppEngine Standard instead because with Flex I was paying for a 24h running servers while the Standard one scales down to 0 instances so it costed nothing when there was no traffic. For Standard I remember starting with this template: https://github.com/prawee/yii2-gae-api Which worked for what I needed (RESTful APIs, 3 of them, each as an independent service/app: api, auth & shell for running migrations and console scripts). 2 things I remember I had to change with that template were:
The main idea is to keep everything standalone ready to scale either up or down. So avoid using any hard disk, use bucket for uploaded stuff & services (either from Google like logs or external when needed). Don't know much about Craft CMS but it is built on top of Yii, and what is good with Yii is that pretty much every class can be extended to make it do stuff in a different manner. For queued tasks, I simply used their built-in TaskQueue service, it looked something like this in my API code: use google\appengine\api\taskqueue\PushTask;
$task = new PushTask("/firebase-sync/$id");
$task_name = $task->add('queue-firebase-sync'); The same project, had a
And in SHELL, which was a different AppEngine service, I had this controller code to execute coming tasks: public function actionFirebaseSync($id)
{
$migration = new \app\commands\FirebaseSyncController('firebase-sync', Yii::$app);
$output = $migration->runAction('index', [$id, 'interactive' => false]);
return $this->buffer($output);
}
protected function buffer($output)
{
fclose(\STDOUT);
$buffer = ob_get_clean();
if ($output) {
if (YII_ENV === 'prod') {
$fp = fopen("gs://stdout0/stderr-".uniqid(), 'w');
fwrite($fp, $buffer);
fclose($fp);
}
throw new ServerErrorHttpException($buffer);
}
return $output;
} Which pretty much, runs Yii console/commands scripts & logs the output. I am roughly copying random code from an older version of an app I've worked on a long time ago, so please take it with a grant of salt, thinks may have changed overtime. I hope it helps. |
I have deployed yii2 based app to GAE. GAE can autoscale the instances horizontally. This presents some challenges:
It would be great to have comments on the above and best practice recommendations.
The text was updated successfully, but these errors were encountered: