Skip to content

Instantly share code, notes, and snippets.

@ibrunotome
Last active February 23, 2022 15:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibrunotome/9ca65e998fd92488ac2247adcf8c1526 to your computer and use it in GitHub Desktop.
Save ibrunotome/9ca65e998fd92488ac2247adcf8c1526 to your computer and use it in GitHub Desktop.
Cloud Build example settings for a Laravel application
steps:
- name: 'gcr.io/cloud-builders/gsutil'
args:
- cp
- .env.testing
- .env
- name: 'docker/compose:1.23.1'
args:
- run
- app
- composer
- install
- --optimize-autoloader
- --no-interaction
- --no-ansi
- --no-progress
- --no-scripts
- --prefer-dist
- name: 'docker/compose:1.23.1'
args:
- run
- app
- vendor/bin/phpunit
- --no-coverage
- name: 'gcr.io/cloud-builders/gsutil'
args:
- cp
- ${_APP_YAML_CONFIG}
- app.yaml
- name: 'gcr.io/cloud-builders/gcloud'
args:
- app
- deploy
- --no-promote
timeout: '600s'
@bhaidar
Copy link

bhaidar commented Jun 7, 2021

Can we run php artisan migrate somwhere here? Thanks

@arnoldmartinez
Copy link

arnoldmartinez commented Sep 16, 2021

Dude please if you can upload a configuration file to run migrations it would be great, with docker compose using community builders or another way. Thanks.

@ibrunotome
Copy link
Author

@bhaidar @arnoldmartinez Sorry fellas, I don't use google app engine anymore. All the steps to deploy on Kubernetes (GKE) here in Portuguese, running migrations etc: https://ibrunotome.github.io/multiplas-aplicacoes-em-um-cluster-kubernetes/

And @arnoldmartinez, how do you want to use docker-compose to run a migration inside GAE? This makes no sense.

@arnoldmartinez
Copy link

Sorry, maybe I didn't explain myself, I currently have a Github repository of a project with Laravel, in order to do continuous integration I want a trigger to be fired in cloud build when we create a pull request and run the tests and migrations to be able to validate that the code does not break when it is integrated into develop.

I am new to cloud build and docker, I have read a little about how to use it and to be able to run migrations I have to have a database installed in this case mysql, I have searched the internet and repos on Github if someone has made an example of integration still using cloud build but I have only found deployment examples with docker compose.

When I saw your gist I saw that it runs phpunit but how can we run the migrations?

Thanks greetings.

@ibrunotome
Copy link
Author

@arnoldmartinez this way:

- name: 'docker/compose:1.23.1'
  args:
    - run
    - app
    - php
    - artisan
    - migrate

Where app is your service name in docker-compose.

@ibrunotome
Copy link
Author

Github actions is also an easy and free option to run your continuous integration workflow, example:

name: Tests

on: [ pull_request ]

jobs:
  tests:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Shutdown Databases
        run: |
          sudo service postgresql stop

      - name: Create .env
        run: cp .env.testing .env

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-php-

      - name: Install dependencies
        run: composer install --prefer-dist --no-progress

      - name: Run the containers
        run: |
          docker-compose -f docker-compose.ci.yml up -d app
          sleep 1

      - name: Run tests
        run: docker exec -t app php artisan test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment