Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running unit tests in Google Cloud Build?

I'm trying to set up CI/CD for several Python projects (all GAE/GCF). I can deploy the code just fine but I want to run the entire test suite before the deploy steps. How can I do that? Do I have to setup a whole docker build step in order to get this done or is there a simpler way?

like image 220
swigganicks Avatar asked Nov 07 '22 01:11

swigganicks


1 Answers

Here's how I do it:

  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: ['-c', 'docker build . --tag my_app']

  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: ['-c', 'docker tag my_app:latest eu.gcr.io/my_project/my_app']

  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: ['-c', 'docker push eu.gcr.io/my_project/my_app']

  - name: 'gcr.io/cloud-builders/docker'
    entrypoint: 'bash'
    args: ['-c', 'docker run my_app pytest']

  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', 'app.yaml', '--image-url=eu.gcr.io/my_project/my_app:latest']

I build and tag my container image. Then I push it up to Google Cloud Repo. Then I run my tests with pytest and then I deploy to Google Cloud Engine.

like image 173
worldofchris Avatar answered Nov 15 '22 10:11

worldofchris