pythongoogle-cloud-platformgoogle-cloud-buildgoogle-cloud-repository

Simple Google Cloud deployment: Copy Python files from Google Cloud repository to app engine


I'm implementing continuous integration and continuous delivery for a large enterprise data warehouse project. All the code reside in Google Cloud Repository and I'm able to set up Google Cloud Build trigger, so that every time code of specific file type (Python scripts) are pushed to the master branch, a Google Cloud build starts.

The Python scripts doesn't make up an app. They contain an ODBC connection string and script to extract data from a source and store it as a CSV-file. The Python scripts are to be executed on a Google Compute Engine VM Instance with AirFlow installed.

So the deployment of the Python scripts is as simple as can be: The .py files are only to be copied from the Google Cloud repository folder to a specific folder on the Google VM instance. There is not really a traditionally build to run, as all the Python files are separate for each other and not part of an application.

I thought this would be really easy, but now I have used several days trying to figure this out with no luck. Google Cloud Platform provides several Cloud Builders, but as far as I can see none of them can do this simple task. Using GCLOUD also does not work. It can copy files but only from local pc to VM not from source repository to VM.

What I'm looking for is a YAML or JSON build config file to copy those Python files from source repository to Google Compute Engine VM Instance.

Hoping for some help here.


Solution

  • The files/folders in the Google Cloud repository aren't directly accessible (it's like a bare git repository), you need to first clone the repo then copy the desired files/folders from the cloned repo to their destinations.

    It might be possible to use a standard Fetching dependencies build step to clone the repo, but I'm not 100% certain of it in your case, since you're not actually doing a build:

    steps:
    - name: gcr.io/cloud-builders/git
      args: ['clone', 'https://github.com/GoogleCloudPlatform/cloud-builders']
    

    If not you may need one (or more) custom build steps. From Creating Custom Build Steps:

    A custom build step is a container image that the Cloud Build worker VM pulls and runs with your source volume-mounted to /workspace. Your custom build step can execute any script or binary inside the container; as such, it can do anything a container can do.

    Custom build steps are useful for:

    • Downloading source code or packages from external locations

      ...