Skip to content

Commit f8dcabe

Browse files
committed
adds drupal8 example
1 parent bb89d12 commit f8dcabe

File tree

9 files changed

+214
-0
lines changed

9 files changed

+214
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ php:
2626
env:
2727
globals:
2828
- GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/credentials.json
29+
- GOOGLE_VERSION_ID=$TRAVIS_JOB_ID
2930

3031
before_install:
3132
- php dump_credentials.php

managed_vms/drupal8/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
drupal8.test
2+
tests/config/install_drupal8.yml

managed_vms/drupal8/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file will go away once gcloud implements fingerprinting.
2+
FROM gcr.io/php-mvm-a/php-nginx:latest
3+
4+
# The docker image will configure the document root according to this
5+
# environment variable.
6+
ENV DOCUMENT_ROOT /app

managed_vms/drupal8/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Drupal 8 on Managed VMs
2+
=======================
3+
4+
## Overview
5+
6+
This guide will help you deploy Drupal 8 on [App Engine Managed VMs][1]
7+
8+
## Prerequisites
9+
10+
Before setting up Drupal 8 on Managed VMs, you will need to complete the following:
11+
12+
1. Create a [Google Cloud Platform project][2]. Note your **Project ID**, as you will need it
13+
later.
14+
1. Create a [Google Cloud SQL instance][3]. You will use this as your Drupal MySQL backend.
15+
16+
## Install Drupal 8
17+
18+
### Download
19+
20+
Use the [Drupal 8 Console][4] to install a drupal project with the following command:
21+
22+
```sh
23+
drupal site:new PROJECT_NAME 8.0.0
24+
```
25+
26+
Alternatively, you can download a compressed file from the [Drupal Website][5].
27+
28+
### Installation
29+
30+
1. Set up your Drupal 8 instance using the web interface
31+
```sh
32+
cd /path/to/drupal
33+
php -S localhost:8080
34+
```
35+
Open [http://localhost:8080](http://localhost:8080) in your browser after running these steps
36+
37+
1. **BETA** You can also try setting up your Drupal 8 instance using the [Drupal 8 Console][4]
38+
```sh
39+
cd /path/to/drupal
40+
drupal site:install \
41+
--langcode en \
42+
--db-type mysql \
43+
--db-name DATABASE_NAME
44+
--db-user DATABASE_USERNAME
45+
--db-pass DATABASE_PASSWORD
46+
--site-name 'My Drupal Site On Google' \
47+
--site-mail [email protected] \
48+
--account-name admin \
49+
--account-mail [email protected] \
50+
--account-pass admin
51+
```
52+
53+
You will want to use the Cloud SQL credentials you created in the **Prerequisites** section as your
54+
Drupal backend.
55+
56+
## Copy over App Engine files
57+
58+
For your app to deploy on App Engine Managed VMs, you will need to copy over the files in this
59+
directory:
60+
61+
```sh
62+
# clone this repo somewhere
63+
git clone https://github.com/GoogleCloudPlatform/php-docs-samples /path/to/php-docs-samples
64+
cd /path/to/php-docs-samples/
65+
66+
# copy the four files below to the root directory of your Drupal project
67+
cp managed_vms/drupal8/{app.yaml,php.ini,Dockerfile,nginx-app.conf} /path/to/drupal
68+
```
69+
70+
The four files needed are as follows:
71+
72+
1. [`app.yaml`](app.yaml) - The App Engine configuration for your project
73+
1. [`Dockerfile`](Dockerfile) - Container configuration for the PHP runtime
74+
1. [`php.ini`](php.ini) - Optional ini used to extend the runtime configuration.
75+
1. [`nginx-app.conf`](nginx-app.conf) - Nginx web server configuration needed for `Drupal 8`
76+
77+
## Disable CSS and JS Cache
78+
79+
For now, you need to disable the CSS and JS preprocessed caching that Drupal 8 enables by default.
80+
To do this, go to `/admin/config/development/performance` and deselect the two
81+
chechboxes (`Aggregate CSS files` and `Aggregate JS files`) under **Bandwidth Optimizations**.
82+
83+
Alternatively, you can use the [Drupal 8 Console][4] to change this config setting:
84+
85+
```sh
86+
# this command must be run inside the root directory of a drupal project
87+
$ cd /path/to/drupal
88+
# this will expand your text editor
89+
$ drupal config:edit system.performance
90+
```
91+
92+
Change the values `preprocess` under `css` and `js` to `false`.
93+
94+
[1]: https://cloud.google.com/appengine/docs/managed-vms/
95+
[2]: https://console.cloud.google.com
96+
[3]: https://cloud.google.com/sql/docs/getting-started
97+
[4]: https://www.drupal.org/project/console
98+
[5]: https://www.drupal.org/8/download

managed_vms/drupal8/app.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
runtime: custom
2+
vm: true

managed_vms/drupal8/nginx-app.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
location / {
2+
# try to serve file directly, fallback to front controller
3+
try_files $uri /index.php$is_args$args;
4+
}

managed_vms/drupal8/php.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
suhosin.post.max_vars = 1000
2+
suhosin.request.max_vars = 1000
3+
4+
; we should tighten up these restrictions eventually
5+
suhosin.executor.func.blacklist =
6+
disable_functions =
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
commands:
2+
# Download Drupal
3+
- command: site:new
4+
arguments:
5+
directory: drupal8.test
6+
version: 8.0.3
7+
# Install Drupal
8+
- command: site:install
9+
options:
10+
langcode: en
11+
db-type: mysql
12+
db-host: @@DRUPAL_DATABASE_HOST@@
13+
db-name: @@DRUPAL_DATABASE_NAME@@
14+
db-user: @@DRUPAL_DATABASE_USER@@
15+
db-pass: @@DRUPAL_DATABASE_PASS@@
16+
site-name: 'Drupal 8 on Managed VMs E2E Test'
17+
site-mail: [email protected]
18+
account-name: @@DRUPAL_ADMIN_USERNAME@@
19+
account-pass: @@DRUPAL_ADMIN_PASSWORD@@
20+
account-mail: [email protected]
21+
arguments:
22+
profile: standard
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
SAMPLE_DIR="${DIR}/.."
6+
DRUPAL_DIR="${SAMPLE_DIR}/drupal8.test"
7+
8+
VARS=(
9+
GOOGLE_PROJECT_ID
10+
GOOGLE_VERSION_ID
11+
DRUPAL_ADMIN_USERNAME
12+
DRUPAL_ADMIN_PASSWORD
13+
DRUPAL_DATABASE_NAME
14+
DRUPAL_DATABASE_USER
15+
DRUPAL_DATABASE_PASS
16+
)
17+
18+
# Check for necessary envvars.
19+
PREREQ="true"
20+
for v in "${VARS[@]}"; do
21+
if [ -z "${!v}" ]; then
22+
echo "Please set ${v} envvar."
23+
PREREQ="false"
24+
fi
25+
done
26+
27+
# Exit when any of the necessary envvar is not set.
28+
if [ "${PREREQ}" = "false" ]; then
29+
exit 1
30+
fi
31+
32+
# Install drupal console
33+
if [ ! -e ${HOME}/bin/drupal ]; then
34+
curl https://drupalconsole.com/installer -L -o drupal
35+
chmod +x drupal
36+
mv drupal "${HOME}/bin/drupal"
37+
fi
38+
39+
# cleanup installation dir
40+
rm -Rf $DRUPAL_DIR
41+
INSTALL_FILE="${DIR}/config/install_drupal8.yml"
42+
43+
cp "${INSTALL_FILE}.dist" $INSTALL_FILE
44+
sed -i -e "s/@@DRUPAL_DATABASE_NAME@@/${DRUPAL_DATABASE_NAME}/" $INSTALL_FILE
45+
sed -i -e "s/@@DRUPAL_DATABASE_USER@@/${DRUPAL_DATABASE_USER}/" $INSTALL_FILE
46+
sed -i -e "s/@@DRUPAL_DATABASE_PASS@@/${DRUPAL_DATABASE_PASS}/" $INSTALL_FILE
47+
sed -i -e "s/@@DRUPAL_DATABASE_HOST@@/${DRUPAL_DATABASE_HOST}/" $INSTALL_FILE
48+
sed -i -e "s/@@DRUPAL_ADMIN_USERNAME@@/${DRUPAL_ADMIN_USERNAME}/" $INSTALL_FILE
49+
sed -i -e "s/@@DRUPAL_ADMIN_PASSWORD@@/${DRUPAL_ADMIN_PASSWORD}/" $INSTALL_FILE
50+
51+
# download and install
52+
drupal init --root=$DIR
53+
drupal chain --file=$INSTALL_FILE
54+
55+
cd $DRUPAL_DIR
56+
57+
# run some setup commands
58+
drupal theme:download bootstrap 8.x-3.0-beta2
59+
drupal cache:rebuild all
60+
61+
## Perform steps outlined in the README ##
62+
63+
# Copy configuration files to the drupal project
64+
cp $SAMPLE_DIR/{app.yaml,php.ini,Dockerfile,nginx-app.conf} $DRUPAL_DIR
65+
66+
# Deploy to gcloud
67+
gcloud preview app deploy \
68+
--no-promote --quiet --stop-previous-version --force \
69+
--project=${GOOGLE_PROJECT_ID} \
70+
--version=${GOOGLE_VERSION_ID}
71+
72+
# perform the test
73+
curl -vf https://${GOOGLE_VERSION_ID}-dot-${GOOGLE_PROJECT_ID}.appspot.com

0 commit comments

Comments
 (0)