CICD best practices
Asked by Suzy Rollandin:

Hi everyone, I would like to ask you a few questions (hoping I'm not totally off the mark).

We have a little "CICD" and I have to improve it. I'm a junior so I'm a little bit confused with some informations I've found.  
Indeed, we have a simple system : git, test servers and a production server.

We have configured pipelines in order to be able to launch our unit tests and then trigger the delivery of the files to the server concerned (the delivery in production is totally manual for the moment).  
During the merge in the branch corresponding to the concerned server, the steps are the following:  
- the unit tests are launched as this :  
- apt-get update \&\& apt-get install -y unzip libpng-dev zlib1g-dev libzip-dev  
- curl -sS <https://getcomposer.org/installer> \| php -- --install-dir=/usr/local/bin --filename=composer  
- docker-php-ext-install gd zip  
- composer install  
- composer require --dev mockery/mockery  
- ./vendor/bin/phpunit ./tests --testdox --colors=always

<br />

- once this step is over, a bash script is called  
- this bash script allows to update the git repository and the dependencies (npm and composer in particular). So this command is launched :  
'git reset --hard \&\& git checkout $branch_name \&\& git pull' "Update Git repository"

<br />

My questions are :   
Is it possible to do these steps without having the .git file on the concerned server ?  
Is it recommended or not to use git in a CICD ?  
Is it possible to run unit tests without installing php unit (via composer) ?   

Thanks for your time :)


Answers:
author: Erez Maadani
body: Hi [@Suzy Rollandin](/t5/user/viewprofilepage/user-id/5063705)

1. Git uses the .git folder to manage the containing folder as a git repository. This folder is used to mark the folder as managed by git and to hold all metadata relevant to the repo: HEAD commit hash, branches' hashes, etc'. The .git folder is created usually upon \`git init\` (creating new repo locally) or \`git clone\` (cloning a repo from a remote server). To answer your question, if you don't have the .git folder locally, it means you have to clone the repo you wish to build. If you do have the .git folder, it usually means that you just need to pull the latest changes and checkout the relevant branch for the build. The latter is usually faster (no need to clone the repo), and the first option is a bit more stable as you don't relay nor affected by current state of the build directory.

2. It depends on your requirements from the CICD and your preferred methodology. Many teams generate the version during the build and then commit \& push it back into the repository. Some teams/organizations object using git directly during the build as it allows developers to commit \& push code w/o going through pull request.

3. If installing php-unit has to be via composer - I don't know. However, the php-unit is a dependency, and as such, you can either fetch \& install it during build time or run your builds on servers/containers which already include this dependency.

comments: author: Suzy Rollandin
body: Hi [@Erez Maadani](/t5/user/viewprofilepage/user-id/5018344) thank you so much for your answers :)   
I will work on it !


Tags: atl-pipelines

bitbucket-cloud

cloud

continuous-delivery