Pelican blog on nginx with google app engine

Posted on sáb 18 agosto 2018 in Tutorials • 2 min read

If you plan to deploy a static server on google app engine, as you may have seen, you only have the option to do it with one of the predefined languages.

For example, if you have a blog deployed with Pelican which generate only static files, html, css, etc ... could be a good idea use for example an nginx server.

To implement this solution, first clone this repo

git clone https://github.com/GoogleCloudPlatform/appengine-custom-runtimes-samples
cd appengine-custom-runtimes-samples/nginx

Next you could startup the container on you local machine

docker build --tag=nginx_appengine .
docker run --rm -it --name nginx_example -p 8080:8080 nginx_appengine

Now open the url on the browser and can see the index page from standard nginx package

http://localhost:8080

Next you need to copy all the files on output directory generated with Pelican to the docker container, so you need to modify the Dockerfile to adapt with the directory name. Change the line:

ADD www/ /usr/share/nginx/www/ with ADD output/ /usr/share/nginx/www/

FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /var/log/app_engine
RUN mkdir -p /usr/share/nginx/www/_ah && \
    echo "healthy" > /usr/share/nginx/www/_ah/health

# Finally, all static assets.
ADD output/ /usr/share/nginx/www/
RUN chmod -R a+r /usr/share/nginx/www

Script to automate the complete deploy of Pelican blog to google app engine

#!/bin/bash
# script for automated deploy of Pelican blog to gclod

# Generate content
source ~/.virtualenvs/pelicanblog/bin/activate
pelican content

# Go to nginx Dockerfile directory
pushd gcloud/nginx/

# Delete old content files and copy new ones
rm -rf output/*
cp -R ../../output/* output/

# Deploy app
gcloud app deploy

# return to project dir
popd

Wait a few minutes and now you have a static pelican blog running on gcloud