google-app-enginegoogle-app-engine-pythongoogle-managed-vm

How do I customise a Google App Engine Managed VM with a Standard Runtime?


I would like to customise a (Python) Standard Runtime Managed VM. In theory, this should be possible by adding some extra commands to the VM Dockerfile.

Google's documentation states that a VM Dockerfile is automatically generated when the App is first deployed;

If you are using a standard runtime, the SDK will create a Dockerfile for you the first time you run the gcloud preview app deploy commands. The file will exist in a predetermined location:

  • If you are developing in Java, the Dockerfile appears in the root of the compiled Web Application Archive directory (WAR)
  • If you are developing in Python or Go, the Dockerfile appears in the root of your application directory.

And that extra commands can indeed be added;

You can add more docker commands to this file, while continuing to run and deploy your app with the standard runtime declaration.

However in practice the Dockerfile is automatically deleted immediately after deployment competes, preventing any customisation.

Has anyone managed to add Dockerfile commands to a Managed VM with a Standard Runtime? Any help would be gratefully appreciated.


Solution

  • I tried the same thing and did not succeed. There is however an equivalent way of doing this that I fell back to.

    You can create a custom runtime that mimics the standard runtime.

    You can do this because Google provides the Docker base images for all the standard runtimes. Mimicking a standard runtime is therefore simply a matter of selecting the right base image in the Dockerfile of the custom runtime. For the standard Python App Engine VM the Dockerfile is:

    FROM gcr.io/google_appengine/python-compat
    ADD . /app
    

    Now that you have recreated the standard runtime as a custom runtime, you can modify the Dockerfile to make any customizations you need.

    Important Note

    The development server does not support custom Dockerfiles (you will get an error about --custom-entrypoint), so you have to move your test environment to App Engine servers if you are doing this. I think this is true regardless of whether you are using a standard runtime and customizing the Dockerfile or using a custom runtime. See this answer.