Q:

Google App Engine run command after deploy

Is there a way to run a list of linux commands on the docker after deployement finish automatically, like lifecycle (valable for Kubernetes ) on the yaml file?
I do not want to have to ssh to the instance and run my command.
I need to install ssh-client and some time vim and other.

A:

For those who are looking for a solution to this problem.
App Engine with runtime: python or other default source in the app.yaml, there won't be too much customization.
To be able to create your own build you have to use runtime: custom and add Dockerfile file in same directory (root).
This is what it looks like:
app.yaml:
Only the first line change.
    runtime: custom

    # the PROJECT-DIRECTORY is the one with settings.py and wsgi.py
    entrypoint: gunicorn -b :$PORT mysite.wsgi # specific to a GUnicorn HTTP server deployment
    env: flex # for Google Cloud Flexible App Engine

    # any environment variables you want to pass to your application.
    # accessible through os.environ['VARIABLE_NAME']
    env_variables:
    # the secret key used for the Django app (from PROJECT-DIRECTORY/settings.py)
      SECRET_KEY: 'lkfjop8Z8rXWbrtdVCwZ2fMWTDTCuETbvhaw3lhwqiepwsfghfhlrgldf'
      DEBUG: 'False' # always False for deployment
      DB_HOST: '/cloudsql/app-example:us-central1:example-postgres'
      DB_PORT: '5432' # PostgreSQL port
      DB_NAME: 'example-db'
      DB_USER: 'mysusername'   # either 'postgres' (default) or one you created on the PostgreSQL instance page
      DB_PASSWORD: 'sgvdsgbgjhrhytriuuyokkuuywrtwerwednHUQ'

      STATIC_URL: 'https://storage.googleapis.com/example/static/' # this is the url that you sync static files to
      
    automatic_scaling:
        min_num_instances: 1
        max_num_instances: 2

    handlers:
    - url: /static
      static_dir: static

    beta_settings:
      cloud_sql_instances: app-example:us-central1:example-postgres

    runtime_config:
      python_version: 3 # enter your Python version BASE ONLY here. Enter 2 for 2.7.9 or 3 for 3.6.4

Dockerfile:
    FROM gcr.io/google-appengine/python

    # Create a virtualenv for dependencies. This isolates these packages from
    # system-level packages.
    # Use -p python3 or -p python3.7 to select python version. Default is version 2.
    RUN virtualenv /env -p python3

    # Setting these environment variables are the same as running
    # source /env/bin/activate.
    ENV VIRTUAL_ENV /env
    ENV PATH /env/bin:$PATH

    # Install custom linux packages (python-qt4 for open-cv)
    RUN apt-get update -y && apt-get install vim python-qt4 ssh-client git -y

    # Add the application source code and install all dependencies into the virtualenv
    ADD . /app
    RUN pip install -r /app/requirements.txt

    # add my ssh key for github
    RUN mv /app/.ssh / && \
        chmod 600 /.ssh/*

    # Run a WSGI server to serve the application.
    EXPOSE 8080

    # gunicorn must be declared as a dependency in requirements.txt.
    WORKDIR /app
    CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 Blacks.wsgi:application --timeout 0 --preload && \
        python3 manage.py makemigrations && \
        python3 manage.py migrate

