Skip to content

Instantly share code, notes, and snippets.

@tristanbailey
Created September 27, 2019 09:16
Show Gist options
  • Save tristanbailey/275a3e62b5b45d1b345729d30769facf to your computer and use it in GitHub Desktop.
Save tristanbailey/275a3e62b5b45d1b345729d30769facf to your computer and use it in GitHub Desktop.
CircleCI Working example config for php Laravel 2019-09
# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
docker:
- image: circleci/php:7.2-node-browsers
# CircleCI defaults:
# environment:
# DB_CONNECTION: mysql
# DB_DATABASE: circle_test
# DB_USERNAME: root
# DB_PASSWORD:
# DB_HOST: '127.0.0.1'
# DB_PORT: 3306
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# Using the RAM variation mitigates I/O contention
# for database intensive operations.
- image: circleci/mysql:5.7-ram
environment:
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_DATABASE: circle_test
MYSQL_USER: username
MYSQL_PASSWORD: password
#- image: redis:2.8.19
working_directory: /home/circleci/project
steps:
- add_ssh_keys:
fingerprints:
- "1a:8e:8a:41:PUT YOUR KEY OWN HERE"
# Mysql takes maybe 10+ seconds to be ready
- run:
name: Wait for db
command: dockerize -wait tcp://localhost:3306 -timeout 1m
# update image and load mysql client, and ext
- run: sudo apt update
- run: sudo apt install python2.7-dev libcurl4-gnutls-dev librtmp-dev libpng-dev curl
- run: sudo apt install -y mariadb-client-10.3
- run: sudo docker-php-ext-install zip json curl gd mysqli pdo pdo_mysql
- checkout
# prepare the database
#- run: mysql -h 127.0.0.1 -u root -prootpw circle_test --execute="SHOW TABLES;"
# Download and cache dependencies
- restore_cache:
keys:
# "composer.lock" can be used if it is committed to the repo
- v1-dependencies-{{ checksum "composer.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: composer install -n --prefer-dist
- save_cache:
key: v1-dependencies-{{ checksum "composer.json" }}
paths:
- ./vendor
- restore_cache:
keys:
- node-v1-{{ checksum "package.json" }}
- node-v1-
- run: yarn install
- save_cache:
key: node-v1-{{ checksum "package.json" }}
paths:
- node_modules
- run: php artisan config:clear
#- run: touch storage/testing.sqlite
#- run: chown www-data:www-data storage/testing.sqlite
#- run: php artisan migrate --env=testing --database=sqlite_testing --force
- run: php artisan migrate --env=production --force
- run: php artisan db:seed
# little test in the build
- run: mysql -h 127.0.0.1 -u root -prootpw circle_test --execute="SHOW TABLES;"
# run tests with phpunit or codecept
- run:
command: |
mkdir -p ~/phpunit;
./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml tests
when: always
- store_test_results:
path: ~/phpunit
- store_artifacts:
path: ~/phpunit
worth setting the env vars, and your .env / .env.testing files for the right db settings
circlci defaults
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: circle_test
MYSQL_USER: root
MYSQL_PASSWORD:
laravel:
DB_DATABASE: circle_test
DB_USERNAME: root
DB_PASSWORD:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment