Setting up a project

Updated on 28 Dec 2018

Creating project, git and deploy folders

To start with, lets create some folders and set appropriate ownership and permissions

Directory Explanation
myProject This is our working directory where we write code and do stuff.
myGitRepo This is a local git repo. Ownership can be brent and group can be jenkins (or www-data provided jenkins is part of that group). The group must have write access to this directory.
myDeploy This is where the application will be deployed to. The ownership is jenkins and group is www-data - typically because this is a web application. jenkins has ownership because it needs to update the folder access times. It will also be writing files to this location.

Installing git

First task is to install git.

sudo apt-get install git
sudo apt-get install git-gui

Setting up a local git repo

We can set up a local git repo fairly easily. First we need to create a folder for our git repo.

mkdir /home/brent/myCI2/myGitRepo

Now go into that directory and intialize the git repo.

cd /home/brent/myCI2/myGitRepo
git init --bare

Now we go to our project working area and initialize git there.

cd /home/brent/myCI2/myProject
git init

Local credentials

Git would have required a user.name and user.email to be set. This has probably already been done on a global scale, however we can set a different name and email for this project. This differs from other versions where we have omitted the --global option.

git config user.email "brent@ubuntu"
git config user.name "brent"
git config credential.helper store 

Add the ignore file

Create a ignore file .gitignore for git. These are the files and folders that will be exempt from source control. The Yii vendor and runtime directory would be common to exclude, as well as the composer.lock file.

Add the remote

Now that the user.name and user.email has been set up, we can now finish configuring git for our project. Let’s add the remote and make the initial commit and push.

git remote add origin /home/brent/myCI2/myGitRepo
git add --all
git commit -m "my first commit"
git push origin master