Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2016 15:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/01967ad9866c2fd339efdce75f83c6a8 to your computer and use it in GitHub Desktop.
Save anonymous/01967ad9866c2fd339efdce75f83c6a8 to your computer and use it in GitHub Desktop.
---
image: php:5.6
stages:
- test_build
- test
- dist_build
- deploy
before_script:
- apt-get update
# git is required so Composer can clone packages from source, and by the deploy task to clone the ansible repo
# libpng-dev is required by the PHP gd extension
# zlib (provided by zlib1g-dev) is required by the PHP zip extension
- apt-get install -y git libpng-dev zlib1g-dev
# PHP gd extension is required by the intervention image library
# PHP zip extension is required so Composer can use packages from dist
- docker-php-ext-install gd zip
# The timezone isn't set by default, which can generate errors causing the builds to fail
- echo -e "date.timezone = UTC\n" >> /usr/local/etc/php/conf.d/zzz_custom.ini
# PhpSpec and PhpUnit can run out of memory using the default 128M memory
- echo -e "memory_limit = 1024M\n" >> /usr/local/etc/php/conf.d/zzz_custom.ini
# Install Composer and install dependencies
- php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
- php composer-setup.php
- php -r "unlink('composer-setup.php');"
- mv composer.phar /usr/local/bin/composer
test_build:
stage: test_build
artifacts:
paths:
- app/
- bootstrap/
- client/
- codeigniter/
- config/
- database/
- public/
- resources/
- storage/
- tests/
- vendor/
- .env.example
- artisan
- phpcs.xml
- phpspec.yml
- phpunit.xml
cache:
paths:
- node_modules/
- vendor/
script:
- curl -sL https://deb.nodesource.com/setup_6.x | bash -
- apt-get install -y nodejs
- php /usr/local/bin/composer install --no-interaction --no-progress
- npm install
- node_modules/.bin/gulp --production
php_codesniffer:
stage: test
dependencies:
- test_build
script:
- php vendor/bin/phpcs
phpunit:
stage: test
dependencies:
- test_build
script:
# sqlite is required by the PHP pdo_sqlite extension
- apt-get install -y sqlite3 libsqlite3-dev
# PHP pdo_sqlite extension is required by PDO to connect to a SQLITE database
- docker-php-ext-install pdo_sqlite
# Copy and configure the environment file.
- cp .env.example .env
- php artisan key:generate
- php vendor/bin/phpunit
dist_build:
stage: dist_build
dependencies:
- test_build
artifacts:
paths:
- app/
- bootstrap/
- client/
- codeigniter/
- config/
- database/migrations/
- database/seeds/
- public/
- resources/
- storage/
- vendor/
- .env.example
- artisan
cache:
paths:
- vendor/
script:
- php /usr/local/bin/composer install --no-dev --no-interaction --no-progress --optimize-autoloader
deploy:
stage: deploy
script:
# libssl-dev is required so that ansible can be installed with pip
# openssh-client is required so we can use SSH
# python-dev is needed so that ansible can be installed with pip
# python-setuptools is required so we can install pip (which we use to install ansible)
- apt-get install -y libssl-dev openssh-client python-dev python-setuptools
# The following allows us to use SSH keys when using the Docker executor:
# http://docs.gitlab.com/ce/ci/ssh_keys/README.html#ssh-keys-when-using-the-docker-executor
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# Install ansible using pip, because the version in the debian
# apt repos is 1.7.* and shopworks/ansible requires 2.*
- easy_install pip
- pip install ansible
# Upgrade disribute pip package to fix
# "ERROR! Unexpected Exception: (setuptools 5.5.1 (/usr/lib/python2.7/dist-packages), Requirement.parse('setuptools>=11.3'))"
# See https://github.com/ansible/ansible/issues/16015
- pip install -U distribute
- echo "$ANSIBLE_VAULT_PASSWORD" > ~/.vault_pass.txt
- git clone git@gitlab.com:company/ansible.git /opt/ansible
- cd /opt/ansible/
- ansible-playbook -i production -e "gitlab_sha=$CI_BUILD_REF" -e "gitlab_project_id=$CI_PROJECT_ID" --vault-password-file ~/.vault_pass.txt deploy.yml
environment: production
when: manual
only:
- master@company/project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment