Skip to content

Instantly share code, notes, and snippets.

@mborodov
Last active March 22, 2021 12:14
Show Gist options
  • Save mborodov/4f9bbb0b5b483eb48758bb311a46d052 to your computer and use it in GitHub Desktop.
Save mborodov/4f9bbb0b5b483eb48758bb311a46d052 to your computer and use it in GitHub Desktop.
Gitlab CI/CD config for PSR2 check and deploy via SSH
# Для всех Job'ов используем один образ
image: tetraweb/php:7.0
# Устанавливаем переменные для работы CI
variables:
CHECK_FILES: ./src/
CHECK_EXCLUDE_DIRS: ./vendor/*
CHECK_STANDARDS: PSR1,PSR2
DEPLOY_USER: root
DEPLOY_SERVER: infoservice.pro
DEPLOY_PATH: /apps/project-runner-test/
# Включаем кеш для библиотек композера
cache:
paths:
- vendor/
# Описываем стадии
stages:
- check-code-on-psr2-standards
- deploy-production
# Стадия проверки кода на стандарты PSR1 и PSR2
phpcs-check:
stage: check-code-on-psr2-standards
before_script:
- docker-php-ext-enable zip
- composer install --no-suggest --prefer-dist
script:
- ./vendor/bin/phpcs
--standard=$CHECK_STANDARDS
--ignore=$CHECK_EXCLUDE_DIRS
--error-severity=1
--warning-severity=8
--extensions=php $CHECK_FILES
# Стадия деплоя на production сервер
deploy-master:
stage: deploy-production
before_script:
- mkdir -p ~/.ssh
- echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- ssh $DEPLOY_USER@$DEPLOY_SERVER "
cd $DEPLOY_PATH &&
git checkout master &&
git reset --hard HEAD &&
git pull origin master &&
composer install &&
chown -R www-data:www-data $DEPLOY_PATH"
environment:
name: production
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment