Skip to content

Commit 64605a1

Browse files
author
Takashi Matsuo
authored
Changes for env: flex (GoogleCloudPlatform#325)
* Changes for env: flex Now we're using the GCS plugin from the github release. * No need for testing the redirect any more
1 parent 9282a88 commit 64605a1

File tree

11 files changed

+49
-175
lines changed

11 files changed

+49
-175
lines changed

appengine/wordpress/src/Project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function runComposer()
8989
$output, $ret);
9090
$this->info = array_merge($this->info, $output);
9191
if ($ret !== 0) {
92-
$this->info[] = 'Failed to run composer update in ' . $dir
92+
$this->info[] = 'Failed to run composer update in ' . $this->dir
9393
. '. Please run it by yourself before running WordPress.';
9494
}
9595
}

appengine/wordpress/src/WordPressSetup.php

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class WordPressSetup extends Command
3636
'https://downloads.wordpress.org/plugin/memcached.3.0.1.zip';
3737
const LATEST_GAE_WP =
3838
'https://downloads.wordpress.org/plugin/google-app-engine.1.6.zip';
39+
const LATEST_GCS_PLUGIN =
40+
'https://github.com/GoogleCloudPlatform/wordpress-plugins/releases/download/gcs-0.1/gcs-0.1.zip';
3941

4042
const FLEXIBLE_ENV = 'Flexible Environment';
4143
const STANDARD_ENV = 'Standard Environment';
@@ -297,34 +299,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
297299
if (!$this->report($output, $project)) {
298300
return self::DEFAULT_ERROR;
299301
}
300-
$output->writeln('Downloading the Batcache plugin...');
301-
$project->downloadArchive(
302-
'Batcache plugin', self::LATEST_BATCACHE,
303-
'/wordpress/wp-content/plugins'
304-
);
305-
if (!$this->report($output, $project)) {
306-
return self::DEFAULT_ERROR;
307-
}
308-
309-
$output->writeln('Downloading the Memcached plugin...');
310-
$project->downloadArchive(
311-
'Memcached plugin', self::LATEST_MEMCACHED,
312-
'/wordpress/wp-content/plugins'
313-
);
314-
if (!$this->report($output, $project)) {
315-
return self::DEFAULT_ERROR;
316-
}
317-
318-
$output->writeln('Copying drop-ins...');
319-
$dir = $project->getDir();
320-
copy(
321-
$dir . '/wordpress/wp-content/plugins/batcache/advanced-cache.php',
322-
$dir . '/wordpress/wp-content/advanced-cache.php'
323-
);
324-
copy(
325-
$dir . '/wordpress/wp-content/plugins/memcached/object-cache.php',
326-
$dir . '/wordpress/wp-content/object-cache.php'
327-
);
328302

329303
$keys = array(
330304
'project_id' => '',
@@ -334,6 +308,34 @@ protected function execute(InputInterface $input, OutputInterface $output)
334308
'db_password' => '',
335309
);
336310
if ($env === self::STANDARD_ENV) {
311+
$output->writeln('Downloading the Batcache plugin...');
312+
$project->downloadArchive(
313+
'Batcache plugin', self::LATEST_BATCACHE,
314+
'/wordpress/wp-content/plugins'
315+
);
316+
if (!$this->report($output, $project)) {
317+
return self::DEFAULT_ERROR;
318+
}
319+
320+
$output->writeln('Downloading the Memcached plugin...');
321+
$project->downloadArchive(
322+
'Memcached plugin', self::LATEST_MEMCACHED,
323+
'/wordpress/wp-content/plugins'
324+
);
325+
if (!$this->report($output, $project)) {
326+
return self::DEFAULT_ERROR;
327+
}
328+
329+
$output->writeln('Copying drop-ins...');
330+
$dir = $project->getDir();
331+
copy(
332+
$dir . '/wordpress/wp-content/plugins/batcache/advanced-cache.php',
333+
$dir . '/wordpress/wp-content/advanced-cache.php'
334+
);
335+
copy(
336+
$dir . '/wordpress/wp-content/plugins/memcached/object-cache.php',
337+
$dir . '/wordpress/wp-content/object-cache.php'
338+
);
337339
$copyFiles = array(
338340
'app.yaml' => '/',
339341
'cron.yaml' => '/',
@@ -351,11 +353,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
351353
return self::DEFAULT_ERROR;
352354
}
353355
} else {
356+
// Download gcs plugin
357+
$project->downloadArchive(
358+
'GCS plugin', self::LATEST_GCS_PLUGIN,
359+
'/wordpress/wp-content/plugins'
360+
);
354361
$copyFiles = array(
355362
'app.yaml' => '/',
356363
'cron.yaml' => '/',
357364
'composer.json' => '/',
358-
'gcs-media.php' => '/wordpress/wp-content/plugins/',
359365
'nginx-app.conf' => '/',
360366
'php.ini' => '/',
361367
'wp-config.php' => '/wordpress/',

appengine/wordpress/src/files/flexible/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
runtime: php
2-
vm: true
2+
env: flex
33

44
beta_settings:
55
cloud_sql_instances: {{db_connection}}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"require": {
3-
"google/appengine-php-sdk": "^1.9"
3+
"google/cloud": "~0.21"
44
},
55
"require-dev": {
6-
"wp-cli/wp-cli": "^0.24.1"
6+
"wp-cli/wp-cli": "~1.1"
77
}
88
}

appengine/wordpress/src/files/flexible/deploy_wrapper.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

appengine/wordpress/src/files/flexible/gcs-media.php

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
location / {
2-
try_files $uri $uri/ /index.php?q=$uri&$args;
2+
try_files $uri /index.php?q=$uri&$args;
33
}
44

5-
# Add trailing slash to */wp-admin requests.
6-
rewrite /wp-admin$ https://$host$uri/ permanent;
7-
8-
location /_ah/health {
9-
return 200 'ok';
5+
location ~ ^/wp-admin {
6+
try_files $uri $uri/index.php?$args;
107
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
extension=bcmath.so
2+
extension=gd.so
23
zend_extension=opcache.so

appengine/wordpress/src/files/flexible/wp-config.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,13 @@
1919
*/
2020

2121
// Register GCS stream wrapper
22-
set_include_path(__DIR__ . '/../vendor/google/appengine-php-sdk');
23-
require_once(__DIR__ . '/../vendor/autoload.php');
24-
stream_wrapper_register(
25-
'gs',
26-
'\google\appengine\ext\cloud_storage_streams\CloudStorageStreamWrapper',
27-
0);
2822

29-
// Bucket name for the media upload
30-
define('GOOGLE_CLOUD_STORAGE_BUCKET', '{{project_id}}.appspot.com');
23+
require_once(__DIR__ . '/../vendor/autoload.php');
24+
$storageClient = new Google\Cloud\Storage\StorageClient();
25+
$storageClient->registerStreamWrapper();
3126

3227
// $onGae is true on production.
33-
$onGae = filter_var(getenv('GAE_VM'), FILTER_VALIDATE_BOOLEAN);
34-
35-
// Cache settings
36-
define('WP_CACHE', $onGae);
37-
$batcache = [
38-
'seconds' => 0,
39-
'max_age' => 30 * 60, // 30 minutes
40-
'debug' => false
41-
];
42-
if ($onGae) {
43-
$memcached_servers = array(
44-
'default' => array(
45-
getenv('MEMCACHE_PORT_11211_TCP_ADDR')
46-
. ':' . getenv('MEMCACHE_PORT_11211_TCP_PORT')
47-
)
48-
);
49-
}
28+
$onGae = (getenv('GAE_VERSION') !== false);
5029

5130
// Disable pseudo cron behavior
5231
define('DISABLE_WP_CRON', true);
@@ -57,16 +36,13 @@
5736
} else {
5837
define('HTTP_HOST', 'localhost');
5938
}
60-
// Use https on MVMs.
39+
// Use https on production.
6140
define('WP_HOME', $onGae ? 'https://' . HTTP_HOST : 'http://' . HTTP_HOST);
6241
define('WP_SITEURL', $onGae ? 'https://' . HTTP_HOST : 'http://' . HTTP_HOST);
6342

6443
// Force SSL for admin pages
6544
define('FORCE_SSL_ADMIN', $onGae);
6645

67-
// Get HTTPS value from the App Engine specific header.
68-
$_SERVER['HTTPS'] = $onGae ? $_SERVER['HTTP_X_APPENGINE_HTTPS'] : false;
69-
7046
// ** MySQL settings - You can get this info from your web host ** //
7147
if ($onGae) {
7248
/** Production environment */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require-dev": {
3-
"wp-cli/wp-cli": "^0.24.1"
3+
"wp-cli/wp-cli": "~1.1"
44
}
55
}

0 commit comments

Comments
 (0)