Skip to content

Commit 043c9b8

Browse files
committed
add custom runtime gae flex stuff
1 parent 74f4964 commit 043c9b8

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

cloud_sql/sqlserver/pdo/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM gcr.io/google_appengine/php72
2+
3+
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
4+
5+
COPY . .
6+
7+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
8+
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
9+
10+
RUN apt-get update && \
11+
ACCEPT_EULA=Y apt-get -y install \
12+
autoconf \
13+
build-essential \
14+
msodbcsql17 \
15+
unixodbc-dev \
16+
unzip
17+
18+
RUN pecl install pdo_sqlsrv
19+
RUN echo "extension=pdo_sqlsrv.so" > /opt/php72/lib/ext.enabled/ext-pdo_sqlsrv.ini
20+
# RUN phpenmod pdo_sqlsrv
21+
RUN composer update

cloud_sql/sqlserver/pdo/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ $ php -S localhost:8080
5555

5656
Navigate towards http://localhost:8080 to verify your application is running correctly.
5757

58-
## Google App Engine Standard
58+
## Google App Engine Flex
5959

60-
To run on GAE-Standard, create an App Engine project by following the setup for these [instructions](https://cloud.google.com/appengine/docs/standard/php7/quickstart#before-you-begin).
60+
To run on App Engine Flex, create an App Engine project by following the setup for these [instructions](https://cloud.google.com/appengine/docs/standard/php7/quickstart#before-you-begin).
6161

6262
First, update `app.yaml` with the correct values to pass the environment variables into the runtime.
6363

64+
In order to use the `sqlsrv` extension, you will need to build a [custom runtime](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/quickstart). The `Dockerfile` in this sample contains a simple example of a custom PHP 7.2 runtime based off of the default App Engine Flex image with the `pdo_sqlsrv` extension installed.
65+
66+
Then, make sure that the service account `service-{PROJECT_NUMBER}>@gae-api-prod.google.com.iam.gserviceaccount.com` has the IAM role `Cloud SQL Client`.
67+
6468
Next, the following command will deploy the application to your Google Cloud project:
6569

6670
```bash
67-
$ gcloud app deploy
71+
$ gcloud beta app deploy
6872
```

cloud_sql/sqlserver/pdo/app.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: php72
15+
runtime: custom
16+
env: flex
1617

1718
# Remember - storing secrets in plaintext is potentially unsafe. Consider using
1819
# something like https://cloud.google.com/secret-manager/ to help keep secrets
@@ -23,6 +24,12 @@ env_variables:
2324
DB_NAME: my-db
2425
DB_HOSTNAME: "172.17.0.1"
2526

27+
beta_settings:
28+
# The connection name of your instance, available by using
29+
# 'gcloud beta sql instances describe [INSTANCE_NAME]' or from
30+
# the Instance details page in the Google Cloud Platform Console.
31+
cloud_sql_instances: ::=tcp:1433
32+
2633
# Defaults to "serve index.php" and "serve public/index.php". Can be used to
2734
# serve a custom PHP front controller (e.g. "serve backend/index.php") or to
2835
# run a long-running PHP script as a worker process (e.g. "php worker.php").

cloud_sql/sqlserver/pdo/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"require": {
1414
"php": ">= 7.2",
15+
"ext-pdo_sqlsrv": "*",
1516
"slim/slim": "^4.5",
1617
"slim/twig-view": "^3.1",
1718
"pimple/pimple": "^3.3",

0 commit comments

Comments
 (0)