Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cloud_sql/sqlserver/pdo/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
FROM gcr.io/google_appengine/php72
FROM php:8.3-apache

COPY --from=composer:latest-bin /composer /usr/local/bin/composer

WORKDIR /var/www/html
COPY . .

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update && \
apt-get -y install gnupg2 curl ca-certificates && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \
curl -fsSL https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list
Comment on lines +8 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To minimize the Docker image size and follow best practices, it is recommended to use the --no-install-recommends flag with apt-get install and clean up the local package repository cache by removing /var/lib/apt/lists/* in the same RUN instruction.

RUN apt-get update && \\
    apt-get -y install --no-install-recommends gnupg2 curl ca-certificates && \\
    curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \\
    curl -fsSL https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list && \\
    rm -rf /var/lib/apt/lists/*


RUN apt-get update && \
ACCEPT_EULA=Y apt-get -y install \
autoconf \
build-essential \
msodbcsql17 \
msodbcsql18 \
unixodbc-dev \
unzip

RUN pecl install pdo_sqlsrv
RUN echo "extension=pdo_sqlsrv.so" > /opt/php72/lib/ext.enabled/ext-pdo_sqlsrv.ini
# RUN phpenmod pdo_sqlsrv
RUN pecl install pdo_sqlsrv && \
docker-php-ext-enable pdo_sqlsrv
RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
RUN composer update

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using composer update in a Dockerfile is discouraged because it resolves and updates all dependencies to their latest allowed versions during the image build. This makes the build non-deterministic, slow, and potentially prone to breaking if a dependency release contains bugs or breaking changes. It is highly recommended to use composer install (with --no-dev for production-ready environments) to ensure the exact versions from composer.lock are installed consistently.

RUN composer install --no-dev

2 changes: 1 addition & 1 deletion cloud_sql/sqlserver/pdo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ To run on App Engine Flex, create an App Engine project by following the setup f

First, update [app.yaml](app.yaml) with the correct values to pass the environment variables into the runtime.

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.
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 8.3 runtime with the `pdo_sqlsrv` extension installed.

Then, make sure that the App Engine default service account
`<PROJECT-ID>@appspot.gserviceaccount.com` has
Expand Down
17 changes: 12 additions & 5 deletions endpoints/getting-started/Dockerfile.custom
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# The Google App Engine php runtime is Debian Jessie with PHP installed
# and various os-level packages to allow installation of popular PHP
# libraries. The source is on github at:
# https://github.com/GoogleCloudPlatform/php-docker
FROM gcr.io/google_appengine/php
# Use the official PHP 8.3 Apache image for App Engine Flexible custom runtimes.
# https://hub.docker.com/_/php
FROM php:8.3-apache

COPY --from=composer:latest-bin /composer /usr/local/bin/composer

WORKDIR /var/www/html
COPY . .

RUN apt-get update && apt-get -y install unzip && \
composer install --no-dev && \
sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
Comment on lines +10 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To keep the Docker image size small, use --no-install-recommends with apt-get install and clean up the apt cache by removing /var/lib/apt/lists/* in the same RUN instruction.

RUN apt-get update && apt-get -y install --no-install-recommends unzip && \\
    rm -rf /var/lib/apt/lists/* && \\
    composer install --no-dev && \\
    sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

Loading