Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the test fail #52

Open
wants to merge 24 commits into
base: sandro/video53
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified section_1/slides/0101_course_overview.pdf
Binary file not shown.
Binary file added section_1/slides/0104_install_jenkins_on_mac.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion section_4/code/cd_pipeline/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def approve() {


def runUnittests() {
sh "python section_4/code/cd_pipeline/tests/test_flask_app.py"
sh "pip3 install --no-cache-dir -r ./section_4/code/cd_pipeline/requirements.txt"
sh "python3 section_4/code/cd_pipeline/tests/test_flask_app.py"
}


Expand Down
5 changes: 2 additions & 3 deletions section_4/code/cd_pipeline/Jenkinsfile_part_2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pipeline {
stage("Test - UAT Stage") {
steps { runUAT(88) }
}

}
}

Expand Down Expand Up @@ -69,12 +68,12 @@ def deploy(environment) {
sh "docker ps -f name=${containerName} -q | xargs --no-run-if-empty docker stop"
sh "docker ps -a -f name=${containerName} -q | xargs -r docker rm"
sh "docker run -d -p ${port}:5000 --name ${containerName} hands-on-jenkins/myapp:${BUILD_NUMBER}"

}


def runUnittests() {
sh "python section_4/code/cd_pipeline/tests/test_flask_app.py"
sh "pip3 install --no-cache-dir -r ./section_4/code/cd_pipeline/requirements.txt"
sh "python3 section_4/code/cd_pipeline/tests/test_flask_app.py"
}


Expand Down
24 changes: 12 additions & 12 deletions section_4/code/cd_pipeline/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

# list of cat images
images = [
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26388-1381844103-11.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr01/15/9/anigif_enhanced-buzz-31540-1381844535-8.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26390-1381844163-18.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-1376-1381846217-0.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3391-1381844336-26.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/10/anigif_enhanced-buzz-29111-1381845968-0.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/9/anigif_enhanced-buzz-3409-1381844582-13.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr02/15/9/anigif_enhanced-buzz-19667-1381844937-10.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr05/15/9/anigif_enhanced-buzz-26358-1381845043-13.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-18774-1381844645-6.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr06/15/9/anigif_enhanced-buzz-25158-1381844793-0.gif",
"http://ak-hdl.buzzfed.com/static/2013-10/enhanced/webdr03/15/10/anigif_enhanced-buzz-11980-1381846269-1.gif"
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-26383-1381845104-25.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-26358-1381845043-13.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-25329-1381845415-0.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-23859-1381845509-0.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-19708-1381845008-7.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-19667-1381844937-10.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-3409-1381844582-13.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-3391-1381844336-26.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-1376-1381846217-0.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-26390-1381844163-18.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-26388-1381844103-11.gif",
"http://www.catshaming.co.uk/wp-content/uploads/2014/11/anigif_enhanced-buzz-27162-1381845360-0.gif"
]

@app.route('/')
Expand Down
2 changes: 1 addition & 1 deletion section_4/code/cd_pipeline/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Flask==0.12.2
Flask==2.3.2
18 changes: 18 additions & 0 deletions section_5/exercises/exercises.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Section 5: Exercises

### Theory

1. Which are the advantages of using Blue Ocean?

2. Which kind of tasks in Jenkins cannot be done via the Blue Ocean user interface?
3. What is a multibranch pipeline?

4. What is a pull request?

### Practice

1. Create a new pipeline with the visual editor but instead of outputting dummy message try to make it do something useful (e.g. build a web application, deploy it on localhost, and ping it). Use your favourite programming language and store the code in your repository on GitHub.

2. Create a new multibranch pipeline using the Jenkinfile employed in section 4. Make sure to put it at the root of a GitHub repository and use the master branch.

3. If you have the chance to deploy Jenkins on a domain name or on an IP address, try to replace the polling in Jenkins with a push notification from GitHub. [This link](https://medium.com/@marc_best/trigger-a-jenkins-build-from-a-github-push-b922468ef1ae) explains how to set up a push notification from GitHub to Jenkins.
17 changes: 17 additions & 0 deletions section_5/exercises/solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Section 5: Solutions to Exercises

### Theory

1. These are some advantages of Blue Ocean:

- Intuitive and visual tool
- Easy to use for anyone in the team
- Make it easier to debug and pinpoint errors in a pipeline job
- Native integration with branches and pull requests for GitHub and Bitbucket
- Modern UI and better user experience

2. Job configuration and Manage Jenkins are two tasks that cannot be accessed via the Blue Ocean user interface and automatically redirect to the classic UI.

3. A multibranch pipeline is a job that enables to implement different Jenkinsfiles for different branches in the same source control repository.

4. A pull request is a request made by a developer to the code maintainer to pull a source code change.
Binary file added section_5/slides/0501_what_is_blue_ocean.pdf
Binary file not shown.
Binary file added section_5/slides/0502_install_blue_ocean.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions section_6/code/install_java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# install java 1.8 on Amazon Linux
sudo yum update -y
sudo yum install -y java-1.8.0-openjdk-devel
sudo alternatives --config java
4 changes: 4 additions & 0 deletions section_6/code/install_jenkins_on_aws.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# install Jenkins on Amazon Linux
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat-stable/jenkins-ci.org.key
sudo yum install jenkins
30 changes: 30 additions & 0 deletions section_6/code/policy-jenkins-slave-node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1312295543082",
"Action": [
"ec2:DescribeSpotInstanceRequests",
"ec2:CancelSpotInstanceRequests",
"ec2:GetConsoleOutput",
"ec2:RequestSpotInstances",
"ec2:RunInstances",
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:TerminateInstances",
"ec2:CreateTags",
"ec2:DeleteTags",
"ec2:DescribeInstances",
"ec2:DescribeKeyPairs",
"ec2:DescribeRegions",
"ec2:DescribeImages",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"iam:PassRole"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
4 changes: 4 additions & 0 deletions section_6/code/ssh_to_ec2_instance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ssh into EC2 instance (replace key name and hostname)
ls -lah /path/jenkins-key.pem
chmod 400 /path/jenkins-key.pem
ssh -i /path/jenkins-key.pem ec2-user@ec2-123-456-78-9.compute-1.amazonaws.com
3 changes: 3 additions & 0 deletions section_6/code/start_jenkins_at_boot_time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# start Jenkins at boot time
sudo systemctl start jenkins.service
sudo systemctl enable jenkins.service
20 changes: 20 additions & 0 deletions section_6/exercises/exercises.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Section 6: Exercises

### Theory

1. What are the benefits of using a master/slave architecture in Jenkins?

2. What are the differences between a single master and a multi master configuration?

3. What is a VPC in AWS?

4. What is a security group in AWS?

5. What is IAM in AWS? What is a IAM policy?

### Practice

1. Create another slave node with a different label name and set up a Jenkins job that runs solely on that node.

2. Instead of running a dummy job on the slave, make it run something useful (e.g. tests). For example, you could run the web application created in section 4 on an EC2 instance and then use a slave node to run acceptance tests.

25 changes: 25 additions & 0 deletions section_6/exercises/solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Section 6: Solutions to Exercises

### Theory

1. The master/slave configuration allows to distribute builds in Jenkins and this has advantages in terms of:

- Flexibility: the slave nodes can be customized to run specific jobs (for example build and test on a specific browser or operating system).
- Resilience: the performance on the master node is improved as long running and resource consuming jobs are sent to slave nodes. Plus, even if a slave node fails, jobs running on other nodes are not affected.
- Scalability: slave nodes free resources from the master node, allow to run jobs in parallel thus sharing the load across multiple machines, and scale automatically since the number of slave nodes is increased at peak build times and decreased during low activity times.

2. In a single master configuration Jenkins is deployed on a single, large master with multiple slave nodes connected to it. In a multiple master configuration Jenkins is deployed on multiple smaller masters with multiple slave nodes connected to each other.

A single master configuration is easier to maintain and is well suited for a single team whereas the multi master configuration is more robust and is better suited for multiple teams.

3. VPC stands for virtual private cloud and is an isolated virtual network inside AWS. It is a good security practice to launch AWS resources inside a VPC so that they are isolated from other projects deployed on AWS.

4. A security group is a virtual firewall for controlling inbound and outbound traffic to resources in a VPC.

5. IAM stands for Identity and Access Management and it enables to access AWS services and resources securely. In particular, IAM is used to create users, permissions, and roles.

A IAM policy is a set of permissions usually attached to a user or a resource. IAM policies are expressed and stored as JSON files.

### Practice

1. To create a new slave node, add a new AMI in `Manage Jenkins` -> `Configure System` -> `Cloud` -> `Amazon EC2` -> `AMIs` -> `Add`. You can copy the same configuration used in video 6.4 but under `Labels` use a different label. Then create a new Jenkins job and in General thick the option `Restrict where this project can be run` and type in `Label expression` the label given to the new slave.
Binary file added section_6/slides/0601_overview.pdf
Binary file not shown.
Binary file not shown.
Binary file added section_6/slides/0603_install_jenkins_on_aws.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added section_6/slides/jenkins_build_farm_on_aws.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.