CI/CD Symfony 4 with GitLab

In my latest project (API endpoint based on Symfony and api-platform), I have the task to optimize and automate CI/CD processes. As a result: here is super-simplified version of the resulting GitLab pipiline:

stages:
    - test
    - deploy

variables:
  MYSQL_DATABASE: database
  MYSQL_USER: runner
  MYSQL_ROOT_PASSWORD: password
  MYSQL_PASSWORD: password

job1:
  image: uvigii/sf4:latest
  stage: test
  tags:
    - symfony

  before_script:
    - composer config cache-files-dir ./cache/composer
  script:
..............
    - composer install --optimize-autoloader
    - source .env.test
    - php bin/console
    - php bin/phpunit 
..............

job2:
    image: google/cloud-sdk:alpine
    tags:
         - symfony
    stage: deploy
    script:
         - gcloud components install app-engine-php         
         - echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
         - gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
         - gcloud --project $PROJECT_ID app deploy

    after_script:
         - rm /tmp/$CI_PIPELINE_ID.json

Docker image used is uvigii/sf4:latest. The reason I build the image is that it is as close as possible to the production ubuntu server, includes all the necessary libraries, includes composer, and is small in size.

Leave a Reply

Your email address will not be published. Required fields are marked *