Skip to content

Instantly share code, notes, and snippets.

@mlvnds
Last active July 27, 2018 08:11
Show Gist options
  • Save mlvnds/bea421b4fced65556bc89428bc4a6bf3 to your computer and use it in GitHub Desktop.
Save mlvnds/bea421b4fced65556bc89428bc4a6bf3 to your computer and use it in GitHub Desktop.
Template circleci 2 pour projet en php7.0
version: 2
jobs:
build:
docker:
- image: 6d6c70/php:php7.0-jessie
environment:
SYMFONY__ENV: prod
- image: mariadb:10.1.34
environment:
MYSQL_DATABASE: default
MYSQL_ROOT_PASSWORD: 123
working_directory: /repo
steps:
- checkout
- run:
name: "Install mysql client"
command: "apt-get update && apt-get install -y mysql-client"
- run:
name: "Set database host value"
command: "sed -i'' -e 's/database_host:.*$/database_host: 127.0.0.1/g' app/config/parameters.yml.dist"
- restore_cache:
keys:
- my-composer-cache-{{ checksum "composer.lock" }}
- run:
name: "Wait until mariadb container have boot up"
command: |
TIMEOUT=30
until mysql -h 127.0.0.1 -P 3306 -uroot -p123 -e "select 1" || [[ $TIMEOUT == 0 ]] ; do
echo "MariaDB not boot, timeout in $((TIMEOUT--))..."
sleep 1
done
if [[ $TIMEOUT == 0 ]] ; then exit 1; fi
- run:
name: "Run composer install"
command: composer install --prefer-dist --no-interaction --optimize-autoloader --no-progress
- save_cache:
name: "Caching vendor folder"
key: my-composer-cache-{{ checksum "composer.lock" }}
paths:
- vendor/
- run:
name: "Create db"
command: php bin/console doctrine:database:create
- run:
name: "Run doctrine update"
command: php bin/console doctrine:schema:update --force
deploy:
docker:
- image: webdevops/ansible:debian-9
working_directory: /repo
steps:
- checkout
- run:
name: "Install ansible roles"
command: ansible-galaxy install cbrunnkvist.ansistrano-symfony-deploy
- run:
name: "Install ssh"
command: apt-get update && apt-get install -y ssh
- run:
name: "Deploy"
command: |
if [ "${CIRCLE_BRANCH}" != "master" ] ; then
ansible-playbook -i app/config/ansistrano/hosts_staging app/config/ansistrano/deploy.yml
else
ansible-playbook -i app/config/ansistrano/hosts_production app/config/ansistrano/deploy.yml
fi
workflows:
version: 2
build_and_deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only:
- master
- develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment