Schulung-Teil6-Erste Schritte mit git

From revampedia
Jump to: navigation, search

Preface

This training session took place on 03-30-17. First we got to know git a little bit and then installed it. Afterwards we installed a project out of git. It won't work yet, as it's still missing some components, but I'm guessing that we'll do that in the next training session in two weeks.
We'll most likely move our test servers that we'll be able to access them from our regular workplaces. That way we can get exersizes to do until the next training session. It is planed that the physical server and virtual machines get static IP addresses, so accessing the machines will change slightly. But first a little repetition on how to access the virtual machine.


If there are still questions open after these instructions, please go to "Views" and then "Discussion" to leave your feedback, so I can add more Details to this page. jr

Repetition

Remote start of the server

First we wish to start our server. For that we use the program "wakeonlan". The general synthax for that is:

wakeonlan -i "broadcast IP" "MAC address"


In my case it was the command "wakeonlan -i 192.168.67.255 00:21:5a:6d:6d:42". My work colleges will have to enter a different MAC address but the remaining synthax stays the same.

Find out the IP address of the server

Next we want to find out what IP address our server received from the DHCP server. In my experience the server always took the same IP, but as that isn't garanteed, it's better to check first.

less /var/lib/dhcp/dhcpd.leases


Here we look for our entry with the help of the MAC ddress, so we can login to the server via SSH. With "q" you can leave less

Remote access to server

For the remote access we use the program "ssh". For security reasons the user root isn't allowed to login via SSH. For that reason we've created another username on the system when we set it up. To know to what address we need to connect to, we previously checke the entry on the DHCP server.

ssh "username"@"remote computer"


Find out the IP address of the virtual machine

Unfortunately I don't know a better way to find out the IP address of the virtual machine so far, so we have go through these steps to get there. As we are on the physical server (Xen-Hypervisor), we can get a list of the virtual machines.

sudo xl list

In this list each machine has it's own ID. We need this number for the next command.

sudo xl console "ID"


Now we have to enter username and password of the virtual machine and afterwards find out the IP address of it:

 ip a


It would also be possible to work from here, but the console we get here doesn't give us the full window. So, it's more comforable to open an SSH connection either from the physical server or from the workstation we're on to the virtual machine.
To get back to the server from the virtual machine, you need to press either Ctrl+5 or AltGr+]. If you wish to go directly from the workstation to the virtual machine, leave the server by typing "exit".


Update packages

Now that we're back on the virtual machine we wish to update the list of available packages in apt.

user1@vm1:~$ sudo apt update


If there is a newer version available for an already installed package, you can update it by typing

user1@vm1:~$ sudo apt upgrade


Install git

We updated our installed packages and have the list up to date. So now we install the program "git"

user1@vm1:~$ sudo apt install git


The installation shows us that it's dependant on other packages to work properly.

The following packages will be installed:
  git-man liberror-perl patch rsync

- "git-man" is the man page of the program git - "liberr-perl" is some library that has something to do with errors and was created in perl - "patch" is a program with instructions to change a file. It's counterpart is "diff" and instructions on how to use them, can be found here. - Rsync is a package/program for data transfer. We use it in our productive systems to create backups.

Monitor a folder with git

As we've installed the program now, we can monitor one or several folders in git. If the folder doesn't exist yet, you can create it by typing

mkdir "my_folder_for_git"


Next we change to the newly created folder (or an already existing one) by typing

cd "my_folder_for_git"


To start the monitoring we enter the following command:

git init


From now on all the files will be monitored.

Load Kivitendo through git

A page already exists for this in our Wiki, but I'll list once more how to do it. Our web server (apache2) has the user "www-data" on a debian system and uses the folder /var/www/. This folder belongs to root, so we have to work with the sudo command.

We want to create a new folder that belongs to the user www-data

user1@vm1:~$ sudo -u www-data mkdir /var/www/git


Unfortunately we get the message "permission denied". The reason for it is that the folder /var/www/ belongs to root and the user www-data lacks the permission to create the new folder. To learn more about the File Hierarchy System I created a page in German on the wiki. It will remain german-only until I know a way to have tables in more than one language. So, there is some additional informatioin there if you're not already an expert for Linux.
As we've failed as www-data we'll create the folder as root:

user1@vm1:~$ sudo mkdir /var/www/git


Now we change the file ownership and group owner of this new folder by typing

user1@vm1:~$ sudo chown www-data:www-data /var/www/git


Next we change to the newly created folder

user1@vm1:~$ cd /var/www/git


And we start to monitor the folder in git

user1@vm1:/var/www/git$ git init


While we're the user www-data we load a copy of Kivitendo into this folder

sudo -u www-data git clone https://github.com/kivitendo/kivitendo-erp.git


A new subfolder has been created in our folder /var/www/git/. So, we change to this new folder

user1@vm1:/var/www/git$ cd kivitendo-erp/


and look at everything in this folder

user1@vm1:/var/www/git/kivitendo-erp$ ls -la
insgesamt 112
drwxr-xr-x 19 www-data www-data 4096 Mär 30 14:17 .
drwxr-xr-x  3 www-data www-data 4096 Mär 30 14:17 ..
drwxr-xr-x  3 www-data www-data 4096 Mär 30 14:17 bin
drwxr-xr-x  2 www-data www-data 4096 Mär 30 14:17 config
drwxr-xr-x  6 www-data www-data 4096 Mär 30 14:17 css
lrwxrwxrwx  1 www-data www-data   14 Mär 30 14:17 dispatcher.fcgi -> dispatcher.fpl
-rwxr-xr-x  1 www-data www-data  621 Mär 30 14:17 dispatcher.fpl
-rwxr-xr-x  1 www-data www-data  507 Mär 30 14:17 dispatcher.pl
drwxr-xr-x  7 www-data www-data 4096 Mär 30 14:17 doc
-rw-r--r--  1 www-data www-data 1150 Mär 30 14:17 favicon.ico
drwxr-xr-x  8 www-data www-data 4096 Mär 30 14:17 .git
-rw-r--r--  1 www-data www-data  553 Mär 30 14:17 .gitignore
-rw-r--r--  1 www-data www-data  451 Mär 30 14:17 .htaccess
drwxr-xr-x  6 www-data www-data 4096 Mär 30 14:17 image
-rw-r--r--  1 www-data www-data  369 Mär 30 14:17 index.html
drwxr-xr-x  9 www-data www-data 4096 Mär 30 14:17 js
-rw-r--r--  1 www-data www-data  375 Mär 30 14:17 .jshintrc
drwxr-xr-x  4 www-data www-data 4096 Mär 30 14:17 locale
-rw-r--r--  1 www-data www-data 2236 Mär 30 14:17 .mailmap
drwxr-xr-x  4 www-data www-data 4096 Mär 30 14:17 menus
drwxr-xr-x  4 www-data www-data 4096 Mär 30 14:17 modules
drwxr-xr-x  3 www-data www-data 4096 Mär 30 14:17 scripts
drwxr-xr-x 26 www-data www-data 4096 Mär 30 14:17 SL
drwxr-xr-x  2 www-data www-data 4096 Mär 30 14:17 spool
drwxr-xr-x  4 www-data www-data 4096 Mär 30 14:17 sql
drwxr-xr-x 20 www-data www-data 4096 Mär 30 14:17 t
drwxr-xr-x  5 www-data www-data 4096 Mär 30 14:17 templates
drwxr-xr-x  3 www-data www-data 4096 Mär 30 14:17 users
-rw-r--r--  1 www-data www-data   15 Mär 30 14:17 VERSION


-> The file ".git" (dot at the beginning tells us that it is a hidden file) is necessary when a program/project is monitored by git.
-> In ".gitignore" are files/folders listed that will not be managed by git. Here you can enter personal settings that will not be the same for everyone. With an editor you can add additional folders.

More commands when working with git

Now that we've loaded a program through git we can get to know git a bit more. There are also web sites in the net to learn git basic commands in German. Other entries also exist already in our Wiki. They can be found here and here
The first command shows us all available branches. As we've only just gotten the program this number is very small and it just has the master branch.

user1@vm1:/var/www/git/kivitendo-erp$ git branch
* master


This command only works when we are in a folder that is being monitored by git. It we try this in a different folder we get the following error message:

user1@vm1:/var/www/git$ git branch
fatal: Not a git repository (or any of the parent directories): .git


To see what versions of a project are available in git, we enter the following command:

user1@vm1:/var/www/git/kivitendo-erp$ git tag


We can start a new branch with the next command:

user1@vm1:/var/www/git/kivitendo-erp$ sudo git checkout -b produktiv release-3.4.1


- The new branch is started with the "-b" parameter
- "produktiv" is the name that we chose for the new branch
- "release-3.4.1" is the version of Kivitendo that builds the basis of our new branch.

As we've created a new branch we now see more with the "git branch" command:

user1@vm1:/var/www/git/kivitendo-erp$ git branch
  master
* produktiv


Another command to see the current state is:

user1@vm1:/var/www/git/kivitendo-erp$ git status
Auf Branch produktiv
nichts zu committen, Arbeitsverzeichnis unverändert


If a new version of a program/project has been released and you wish to install it, you first need to change back to the master branch

user1@vm1:/var/www/git/kivitendo-erp$ sudo git checkout master
Zu Branch 'master' gewechselt
Ihr Branch ist auf dem selben Stand wie 'origin/master'.


and you'd get the new version by typing (won't work in my example here as we already have the most current version)

user1@vm1:/var/www/git/kivitendo-erp$ sudo git pull


To see what's changed from one release to the next you can type:

user1@vm1:/var/www/git/kivitendo-erp$ sudo git log


If you wish to change the branch again you enter the following command

user1@vm1:/var/www/git/kivitendo-erp$ sudo git checkout produktiv
Zu Branch 'produktiv' gewechselt


Closing words

Our version of Kivitendo doesn't work yet, as we don't have Postgres installed or configured.

If you turn of a virtual machine or a server, while you are in an SSH session, you can press "Enter"+~+. to get back to your client. You first press the Enter-key, then AltGr+~, next Spacebar and last .

Exercise for next time

Kivitendo is just one example of the programs/projects that can be found on git. Other programs that we use here and are available on git are NextCloud or Openki. The Linux-Kernel is also being developed on git.
The exercise for next time is to load another program onto the virtual machine from git. To see what's available you best visit the web site github.com. To get the link to the .git file you best check the README file.
,