DevOps Blog - Nicolas Paris

Laravel on Google Cloud Run

GCPLaravel

About Google Cloud Run

Google launch a month ago Google Cloud Run, something between Google App Engine with
flexible environment and Kubernetes. With cost optimization, GAE flex can't have 0 instance
for running the service. It's zero-op and doesn't have the complexity of Kubernetes.

The idea is to submit a docker image that Google Cloud Run will deploy within a minute
(or two).

The pricing model seems interesting, the ability to have 0 instance running can be
useful. I'm not sure how the price would scale in heavy production load.

Cloud Run

About the sample Laravel app

You can get the code on Github. Look for the cloud-run tag on the repository as the project
is kind of a sandbox and can move.

This is not a Laravel tutorial, generate a resource LogController, or just the index
and store as I done. The idea is to store some logs and read them.

POST http://localhost:8080/api/log content='foobar'
GET http://localhost:8080/api/log

Dockerfile

Cloud run needs a dockerfile and an application that run on 8080 port.

FROM composer:1.6.5 as build
WORKDIR /app
COPY site /app
RUN composer install

FROM php:7.2-apache
RUN docker-php-ext-install pdo pdo_mysql

EXPOSE 8080
COPY --from=build /app /var/www/
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
COPY site/.env.prod /var/www/.env
RUN chmod 777 -R /var/www/storage/
RUN echo "Listen 8080" >> /etc/apache2/ports.conf
RUN chown -R www-data:www-data /var/www/ \
&& a2enmod rewrite

Few comments on it

Build the image

Let's build the image.

You might need to setup permission, you will be prompt with a link on
the google dock to setup permission.

gcloud builds submit --tag gcr.io/nipsandbox/logs .

It will submit the build, and perform the following steps

It should look like this

Cloud Build

Cloud Registery

Deploy on Google Run

On the cloud registry, choose the google cloud run deployment like this
(or any other way)

Cloud Run

The deployment is fast.

Cloud Run

Cloud Run