---
# System prepended metadata

title: Untitled

---


```yaml
image: lorisleiva/laravel-docker:stable
.init_ssh: &init_ssh |
  eval $(ssh-agent -s)
  echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  mkdir -p ~/.ssh
  chmod 700 ~/.ssh
  [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

  # Replace the last line with the following lines if you'd rather
  # leave StrictHostKeyChecking enabled (replace yourdomain.com):
  #
  #  ssh-keyscan yourdomain.com >> ~/.ssh/known_hosts
  #  chmod 644 ~/.ssh/known_hosts

.change_file_permissions: &change_file_permissions |
  find . -type f -not -path "./vendor/*" -exec chmod 664 {} \;
  find . -type d -not -path "./vendor/*" -exec chmod 775 {} \;

composer:
  stage: build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-composer
    paths:
      - vendor/
  script:
    - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
  artifacts:
    expire_in: 1 week
    paths:
      - vendor/
  only:
    - dev
    - production

npm:
  stage: build
  cache:
    key: ${CI_COMMIT_REF_SLUG}-npm
    paths:
      - node_modules/
  script:
    - cd ${CI_PROJECT_DIR}/client-app/
    - yarn install
    - yarn production
  artifacts:
    expire_in: 1 week
    paths:
      - node_modules/
      - public/css/
      - public/js/
  only:
    - dev
    - production
codestyle:
  stage: test
  dependencies: []
  script:
    - phpcs --standard=phpcs.xml --extensions=php src
  only:
    - dev
    - production
staging:
  stage: deploy
  script:
    - *init_ssh
    - *change_file_permissions
    - rsync -avz --progress --exclude='.env' . ${CI_PROJECT_SSH_USER}@${CI_PROJECT_SSH_HOST}:${CI_PROJECT_PATH}
    - ssh ${CI_PROJECT_SSH_USER}@${CI_PROJECT_SSH_HOST} 'cd public_html && php artisan migrate --force --step && php artisan optimize:clear && php artisan view:cache && php artisan config:cache && php artisan route:cache && php artisan event:cache && php artisan horizon:terminate'
  environment:
    name: staging
    url: ${CI_PROJECT_URL_STG}
  only:
    - dev

production:
  stage: deploy
  script:
    - *init_ssh
    - *change_file_permissions
    - rsync -avz /var/www/public_html/images root@<remote-ip>:/var/www/public_html
  environment:
    name: production
    url: ${CI_PROJECT_URL_PROD}
  when: manual
  only:
    - production
```