Deploy project to development/production server – how to?

Hi all.

I’ve googled this question but found only testing but i need to deploy code to my server root.

Gitlab 8.x, runner – shell (configured from server with my application).

.gitlab-ci.yml:

cache:
    paths:
        - vendor/
        - logs/

before_script:
    - composer selfupdate --no-progress --no-interaction
    - composer install --no-progress --no-interaction

stages:
    - test
    - deploy

develop-deploy:
    stage: deploy
    script:
        - php -v
        - echo "IS_DEV=1" > ./.env
        - ./vendor/bin/phinx migrate -e development
    only:
        - develop

develop-test:
    stage: test
    script:
        - php -v
        - ./vendor/bin/phpunit --configuration phpunit.xml --coverage-text
    only:
        - develop

master-deploy:
    stage: deploy
    script:
        - php -v
        - echo "IS_DEV=0" > ./.env
        - ./vendor/bin/phinx migrate -e production
    only:
        - master

master-test:
    stage: test
    script:
        - php -v
        - ./vendor/bin/phpunit --configuration phpunit.xml --coverage-text
    only:
        - master

But there are two problems:

  1. Builds are in /home/gitlab-runner/builds/ – how to change it to /var/www/myproject/builds/ (where is root for nginx)?
  2. There is no current/latest link to last success build – where i can find it? Or how to detect?

Thanks all for any help.

Trying to write deploy via Deployer and see error:

➤ Executing task deploy:release
                                                                                                              
  [Symfony\Component\Process\Exception\ProcessFailedException]                                                
  The command "mkdir /var/www/myproject/api.dev/releases/20160527115803" failed.                          
  Exit Code: 1(General error)                                                                                 
  Working directory: /home/gitlab-runner/builds/13d4b14b/0/My-Project/api                                 
  Output:                                                                                                     
  ================                                                                                            
  Error Output:                                                                                               
  ================                                                                                            
  mkdir: cannot create directory `/var/www/myproject/api.dev/releases/20160527115803': Permission denied

I tried these commands, but no effect (ubuntu):

usermod -a -G www-data gitlab-runner
chgrp www-data /var/www
chmod g+rwx -R /var/www
pkill -KILL -u gitlab-runner

So, how can i give write permissions to gitlab runner and not to break existing right for nginx?

Hi trogwar,

do you have found a Solution for your Problem and like to share it?

No, i don’t have solution and i can’t share it.

mkdir /var/www/myproject/…

This is not at all Gitlab related, you are simply trying to write in a folder you don’t own. Gitlab-runner runs a gitlab-runner but /var/www is owned by www-data (the Apache user).

Put shortly you can use

setfacl -m user:gitlab-runner:rwx /var/www

as an administrator to give gitlab-runner enough permission to perform what you want. More info here.

While ACL is a modern and robust system you should be aware of the security risks this implies. Any user with the gitlab-runner privileges could read and destroy the content of this folder.