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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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.