Προαπαιτούμενα
											
										
																			
											
												Εγκαταστήστε Java
											
										
																			
											
												Εγκαταστήστε το GoCD
											
										
																			
											
												Διαμόρφωση Αποθήκευσης Αποκλεισμού
											
										
																			
											
												Ρύθμιση τείχους προστασίας
											
										
																			
											
												Ρύθμιση ελέγχου ταυτότητας
											
										
																			
											
												Ασφάλιση GoCD με Let's Encrypt SSL
											
										
																			
											
												Εγκατάσταση GoCD Agent
											
										
																	
												
						
												
Το GoCD είναι ένα σύστημα συνεχούς παράδοσης και αυτοματισμού ανοιχτού κώδικα. Σας επιτρέπει να μοντελοποιείτε πολύπλοκες ροές εργασίας χρησιμοποιώντας την παράλληλη και διαδοχική εκτέλεσή της. Ο χάρτης ροής αξίας σάς επιτρέπει να οπτικοποιείτε εύκολα μια περίπλοκη ροή εργασίας με ευκολία. Το GoCD σάς επιτρέπει να συγκρίνετε εύκολα δύο εκδόσεις και να αναπτύξετε οποιαδήποτε έκδοση της εφαρμογής θέλετε. Το οικοσύστημα GoCD αποτελείται από διακομιστή GoCD και παράγοντα GoCD. Το GoCD είναι υπεύθυνο για τον έλεγχο των πάντων, όπως η εκτέλεση της διεπαφής χρήστη που βασίζεται στο web και η διαχείριση και η παροχή εργασιών στον πράκτορα. Οι πράκτορες Go είναι υπεύθυνοι για την εκτέλεση των εργασιών και των αναπτύξεων.
Προαπαιτούμενα
- Μια παρουσία διακομιστή Vultr CentOS 7 με τουλάχιστον 1 GB RAM.
- Ένας χρήστης sudo .
- Ένα όνομα τομέα στραμμένο προς τον διακομιστή.
Για αυτό το σεμινάριο, θα χρησιμοποιήσουμε 192.168.1.1ως δημόσια διεύθυνση IP και gocd.example.comως όνομα τομέα που δείχνει προς την παρουσία του Vultr. Βεβαιωθείτε ότι έχετε αντικαταστήσει όλες τις εμφανίσεις του παραδείγματος ονόματος τομέα και διεύθυνσης IP με την πραγματική.
Ενημερώστε το βασικό σας σύστημα χρησιμοποιώντας τον οδηγό Πώς να ενημερώσετε το CentOS 7 . Μόλις το σύστημά σας ενημερωθεί, προχωρήστε στην εγκατάσταση Java.
Εγκαταστήστε Java
Το GoCD απαιτεί Java έκδοση 8 και υποστηρίζει τόσο Oracle Java όσο και OpenJDK. Σε αυτό το σεμινάριο, θα εγκαταστήσουμε την Java 8 από το OpenJDK.
Το OpenJDK μπορεί να εγκατασταθεί εύκολα, καθώς το πακέτο είναι διαθέσιμο στο προεπιλεγμένο YUMαποθετήριο.
sudo yum -y install java-1.8.0-openjdk-devel
Εάν η Java έχει εγκατασταθεί σωστά, τότε θα μπορείτε να επαληθεύσετε την έκδοσή της.
java -version
Θα έχετε παρόμοιο αποτέλεσμα με το παρακάτω κείμενο.
[user@vultr ~]$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
Προτού προχωρήσουμε περαιτέρω, θα χρειαστεί να ρυθμίσουμε τις μεταβλητές JAVA_HOMEκαι JRE_HOMEπεριβάλλον. Βρείτε την απόλυτη διαδρομή του εκτελέσιμου Java στο σύστημά σας.
readlink -f $(which java)
Το παρακάτω κείμενο θα βγει στο τερματικό σας.
[user@vultr ~]$ readlink -f $(which java)
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre/bin/java
Τώρα, ορίστε τις μεταβλητές JAVA_HOMEκαι JRE_HOMEπεριβάλλον σύμφωνα με τη διαδρομή του καταλόγου Java.
echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64" >> ~/.bash_profile
echo "export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-5.b12.el7_4.x86_64/jre" >> ~/.bash_profile
Σημείωση:  Βεβαιωθείτε ότι χρησιμοποιείτε τη διαδρομή Java που έχετε στο σύστημά σας. Η διαδρομή που χρησιμοποιείται σε αυτό το σεμινάριο ενδέχεται να αλλάξει όταν κυκλοφορήσει μια νέα έκδοση της Java 8.
Εκτελέστε το bash_profileαρχείο.
source ~/.bash_profile
Τώρα μπορείτε να εκτελέσετε την echo $JAVA_HOMEεντολή για να βεβαιωθείτε ότι έχει οριστεί η μεταβλητή περιβάλλοντος.
[user@vultr ~]$ echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64
Εγκαταστήστε το GoCD
Το GoCD είναι γραμμένο σε Java, επομένως η Java είναι η μόνη εξάρτηση για την εκτέλεση του GoCD. Το GoCD μπορεί να εγκατασταθεί με τη βοήθεια του YUM. Εγκαταστήστε το επίσημο αποθετήριο του στο σύστημα.
sudo curl https://download.gocd.org/gocd.repo -o /etc/yum.repos.d/gocd.repo
Εγκαταστήστε τον διακομιστή GoCD στο σύστημά σας.
sudo yum install -y go-server
Εκκινήστε το GoCD και ενεργοποιήστε το να ξεκινά αυτόματα κατά την εκκίνηση.
sudo systemctl start go-server
sudo systemctl enable go-server
Πριν αποκτήσουμε πρόσβαση στον πίνακα εργαλείων GoCD, ας δημιουργήσουμε έναν νέο κατάλογο για την αποθήκευση των τεχνουργημάτων. Τα τεχνουργήματα μπορούν να αποθηκευτούν στον ίδιο δίσκο στον οποίο είναι εγκατεστημένα το λειτουργικό σύστημα και οι εφαρμογές. Εναλλακτικά, μπορείτε να χρησιμοποιήσετε έναν αποκλειστικό δίσκο ή μονάδα αποθήκευσης μπλοκ για την αποθήκευση των τεχνουργημάτων.
Εάν θέλετε να χρησιμοποιήσετε τον ίδιο δίσκο για την αποθήκευση των τεχνουργημάτων, απλώς δημιουργήστε έναν νέο κατάλογο και παρέχετε την ιδιοκτησία στον χρήστη GoCD.
sudo mkdir /opt/artifacts
sudo chown -R go:go /opt/artifacts
Το λογισμικό GoCD συνιστά τη χρήση ενός πρόσθετου διαμερίσματος ή μονάδας δίσκου για την αποθήκευση των τεχνουργημάτων. Σε μια πλατφόρμα συνεχούς ενοποίησης και παράδοσης, τα τεχνουργήματα δημιουργούνται πολύ συχνά. Ο χώρος στο δίσκο μειώνεται με την πάροδο του χρόνου όταν δημιουργούνται συνεχώς νέα τεχνουργήματα. Σε κάποιο στάδιο, το σύστημά σας θα εξαντληθεί από ελεύθερο χώρο στο δίσκο και οι υπηρεσίες που εκτελούνται στο σύστημά σας θα αποτύχουν. Για να ξεπεράσετε αυτό το ζήτημα, μπορείτε να επισυνάψετε μια νέα μονάδα αποθήκευσης μπλοκ Vultr για να αποθηκεύσετε τα τεχνουργήματα. Εάν εξακολουθείτε να θέλετε να χρησιμοποιήσετε την αποθήκευση τεχνουργημάτων στην ίδια μονάδα δίσκου, μεταβείτε στην ενότητα "Ρύθμιση τείχους προστασίας".
Αναπτύξτε μια νέα μονάδα αποθήκευσης μπλοκ και συνδέστε την στην παρουσία διακομιστή GoCD. Τώρα δημιουργήστε ένα νέο διαμέρισμα στη συσκευή αποθήκευσης μπλοκ.
sudo parted -s /dev/vdb mklabel gpt
sudo parted -s /dev/vdb unit mib mkpart primary 0% 100%
Δημιουργήστε το σύστημα αρχείων στο νέο δίσκο.
sudo mkfs.ext4 /dev/vdb1
Τοποθετήστε τη μονάδα αποθήκευσης μπλοκ.
sudo mkdir /mnt/artifacts
sudo cp /etc/fstab /etc/fstab.backup
echo "
/dev/vdb1 /mnt/artifacts ext4 defaults,noatime 0 0" | sudo tee -a /etc/fstab
sudo mount /mnt/artifacts
Τώρα, εκτελέστε dfκαι θα δείτε τη νέα μονάδα αποθήκευσης μπλοκ τοποθετημένη σε /mnt/artifacts.
[user@vultr ~]$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       20616252 6313892  13237464  33% /
...
/dev/vdb1       10188052   36888   9610596   1% /mnt/artifacts
Παρέχετε την ιδιοκτησία του καταλόγου στον χρήστη GoCD.
sudo chown -R go:go /mnt/artifacts
Ρύθμιση τείχους προστασίας
Αλλάξτε τη διαμόρφωση του τείχους προστασίας για να επιτρέπονται οι θύρες 8153και 8154μέσω του τείχους προστασίας. Η θύρα 8153ακούει για μη ασφαλείς συνδέσεις και η θύρα 8154για ασφαλείς συνδέσεις.
sudo firewall-cmd --zone=public --add-port=8153/tcp --permanent
sudo firewall-cmd --zone=public --add-port=8154/tcp --permanent
sudo firewall-cmd --reload
Τώρα μπορείτε να αποκτήσετε πρόσβαση στον πίνακα εργαλείων GoCD στο http://192.168.1.1:8153. Για πρόσβαση στον πίνακα εργαλείων GoCD σε ασφαλή σύνδεση, αποκτήστε πρόσβαση https://192.168.1.1:8154. Θα λάβετε κάποιο σφάλμα που δείχνει ότι τα πιστοποιητικά δεν είναι έγκυρα. Μπορείτε να αγνοήσετε με ασφάλεια το σφάλμα καθώς τα πιστοποιητικά είναι αυτο-υπογεγραμμένα. Για λόγους ασφαλείας, θα πρέπει πάντα να χρησιμοποιείτε τον πίνακα εργαλείων μέσω μιας ασφαλούς σύνδεσης.
Προτού ρυθμίσετε μια νέα διοχέτευση, μεταβείτε στο " Admin >> Server Configuration" από την επάνω γραμμή πλοήγησης.
Εισαγάγετε τη διεύθυνση URL στον μη Site URLασφαλή ιστότοπο στο πεδίο " " και τον ασφαλή ιστότοπο στο πεδίο " Secure Site URL".

Στη συνέχεια, δώστε τα στοιχεία του διακομιστή SMTP για αποστολή ειδοποιήσεων μέσω email από το GoCD.

Τέλος, δώστε τη διαδρομή προς την τοποθεσία όπου θέλετε να αποθηκεύσετε τα τεχνουργήματα. Εάν έχετε επιλέξει να αποθηκεύσετε τα τεχνουργήματα στον ίδιο δίσκο με το λειτουργικό σύστημα, πληκτρολογήστε /opt/artifacts; εάν έχετε επιλέξει να επισυνάψετε μια μονάδα αποθήκευσης μπλοκ, τότε μπορείτε να εισαγάγετε /mnt/artifacts.
Also, you can configure GoCD to auto-delete the old artifacts. Configure the next option according to your disk size. However, the auto-delete option does not take a backup of your old artifacts. To manually take a backup and then delete the old artifacts, disable auto delete by choosing the "Never" option for the "Auto delete old artifacts" option.

You will need to restart the GoCD server so that the new changes are applied.
sudo systemctl restart go-server
Setup Authentication
By default, the GoCD dashboard is not configured to use any kind of authentication, but it supports authentication using a password file and LDAP. In this tutorial, we will set up password-based authentication.
Note: Setting up authentication is an optional step, but it is strongly recommended for public facing servers, such as Vultr.
Install Apache tools so that we can use the htpasswd command to create an encrypted password file.
sudo yum -y install httpd-tools
Create a password file with the htpasswd command using Bcrypt encryption. 
sudo htpasswd -B -c /etc/go/passwd_auth goadmin
Provide the password for the user twice. You will see the following output.
[user@vultr ~]$ sudo htpasswd -B -c /etc/go/passwd_auth goadmin
New password:
Re-type new password:
Adding password for user goadmin
You can add as many users as you want using the same command above, but removing the -c option. The -c option will replace the existing file, replacing old users with the new user.
sudo htpasswd -B /etc/go/passwd_auth gouser1
Since, we have created the password file, access the GoCD dashboard again. Navigate to "Admin >> Security >> Authorization Configurations" from the top navigation bar. Click on the Add button and provide an ID. Choose "Password File Authentication Plugin for GoCD" for plugin ID and direct the path to the password file. Now click on the "Check Connection" button to verify that GoCD can use the password file for authentication.

Finally, save the authentication method. Reload the dashboard and it will automatically log you out. You will see a login screen now. Log in using the credentials created earlier.
You will need to promote the administrator user manually, otherwise, all the users will have administrator privileges. Navigate to "Admin >> User Summary" from the top navigation bar.
Now select the admin user you've created and click on the "Roles" drop-down. Promote the user to the only administrator by selecting the "Go System Administrator" checkbox.

To add the users in GoCD created in the password file, click on the "ADD" button and search for the user to add them. Users are also automatically added to the GoCD dashboard on their first login. Obviously, for users to log in, they must be added to the password file we have created earlier.
Securing GoCD with Let's Encrypt SSL
By default, GoCD listens to ports 8153 and 8154 on secure connections. Though port 8154 provides a secure connection to the application, it also displays browser errors as it uses a self-signed certificate. In this section of the tutorial, we will install and secure Nginx with Let's Encrypt free SSL certificate. The Nginx web server will work as a reverse proxy to forward the incoming requests to GoCD's HTTP endpoint.
Install Nginx.
sudo yum -y install nginx
Start Nginx and enable it to automatically start at boot time.
sudo systemctl start nginx
sudo systemctl enable nginx
Install Certbot, which is the client application for Let's Encrypt CA.
sudo yum -y install certbot
Before you can request certificates, you will need to allow ports 80 and 443, or standard HTTP and HTTPS services, through the firewall. Also, remove port 8153, which listens to the unsecured connections.
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --add-service=https --permanent
sudo firewall-cmd --zone=public --remove-port=8153/tcp --permanent
sudo firewall-cmd --reload
Note: To obtain certificates from Let's Encrypt CA, the domain for which the certificates are to be generated must be pointed towards the server. If not, make the necessary changes to the DNS records of the domain and wait for the DNS to propagate before making the certificate request again. Certbot checks the domain authority before providing the certificates.
Generate the SSL certificates.
sudo certbot certonly --webroot -w /usr/share/nginx/html -d gocd.example.com
The generated certificates are likely to be stored in /etc/letsencrypt/live/gocd.example.com/. The SSL certificate will be stored as fullchain.pem and private key will be stored as privkey.pem.
Let's Encrypt certificates expire in 90 days, so it is recommended to set up auto-renewal of the certificates using cron jobs.
Open the cron job file.
sudo crontab -e
Add the following line to the end of the file.
30 5 * * * /usr/bin/certbot renew --quiet
The above cron job will run every day at 5:30 AM. If the certificate is due for expiry, it will automatically renew.
Now, change the Nginx default configuration file to take out the default_server line.
sudo sed -i 's/default_server//g' /etc/nginx/nginx.conf
Create a new configuration file for the GoCD web interface.
sudo nano /etc/nginx/conf.d/gocd.conf
Populate the file.
upstream gocd {
server 127.0.0.1:8153;
}
server {
    listen 80 default_server;
    server_name gocd.example.com;
    return 301 https://$host$request_uri;
}
server {
    listen 443 default_server;
    server_name gocd.example.com;
    ssl_certificate           /etc/letsencrypt/live/gocd.example.com/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/gocd.example.com/privkey.pem;
    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;
    access_log  /var/log/nginx/gocd.access.log;
location / {
        proxy_pass http://gocd;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
    }
location /go {
    proxy_pass http://gocd/go;
    proxy_http_version 1.1;
    proxy_set_header Upgrade websocket;
    proxy_set_header Connection upgrade;
    proxy_read_timeout 86400;
    }
  }
Check for errors in the new configuration file.
sudo nginx -t
If you see the following output, the configuration is error free.
[user@vultr ~]$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If you have received some kind of error, make sure to double check the path to the SSL certificates. Restart the Nginx web server to implement the change in configuration.
sudo systemctl restart nginx
Now you can access the GoCD dashboard at https://gocd.example.com. Log in to your dashboard using the administrator credentials and navigate to "Admin >> Server Configuration" from the top navigation bar.

Set the "Site URL" and "Secure Site URL" to https://gocd.example.com. Port 8154 still needs to be accessible through the firewall so that the remote agents may connect to the server through port 8154, in case they are unable to connect through the standard HTTP port.
Installing GoCD Agent
In the GoCD continuous integration environment, GoCD agents are the workers that are responsible for the execution of all the tasks. When a change in the source is detected, the pipeline is triggered and the jobs are assigned to the available workers for execution. The agent then executes the task and reports the final status after execution.
To run a pipeline, at least one agent must to be configured. Proceed to install the GoCD agent on the GoCD server.
Since we have already imported the GoCD repository into the server, we can directly install Go Agent.
sudo yum install -y go-agent
Now, start the GoCD server and enable it to automatically start at boot time.
sudo systemctl start go-agent
sudo systemctl enable go-agent
The GoCD agent running on the localhost is automatically enabled when detected.