Skip to content

Commit 7aa76cf

Browse files
committed
Seeded labs with starter code
1 parent ecfb015 commit 7aa76cf

File tree

18 files changed

+424
-119
lines changed

18 files changed

+424
-119
lines changed

README.md

Lines changed: 14 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,21 @@
1-
# lab-github-actions
1+
# Intro to CI/CD Practice Code
22

3-
[![Build Status](https://github.com/nyu-devops/lab-github-actions/actions/workflows/workflow.yml/badge.svg)](https://github.com/nyu-devops/lab-github-actions/actions)
3+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4+
[![Python 3.9](https://img.shields.io/badge/Python-3.9-green.svg)](https://shields.io/)
45

5-
This is for NYU DevOps lab on using GitHub Actions with Redis for Continuous Integration
6+
This repository contains the practice code for the labs in **IBM-CD0215EN-SkillsNetwork Introduction to CI/CD**
67

7-
## Introduction
8+
## Contents
89

9-
This lab contains a `workflow.yml` file in the `.github/workflows/` folder that shows you how to run your tests and start a Redis service be attached while running them. It also uses Code Coverage to determine how complete your testing is.
10+
- Lab 1: [Build an empty Pipeline](labs/01_base_pipeline/README.md)
11+
- Lab 2: [Adding GitHub Triggers](labs/02_add_git_trigger/README.md)
12+
- Lab 3: [Use Tekton CD Catalog](labs/03_use_tekton_catalog/README.md)
13+
- Lab 4: [Integrate Unit Test Automation](labs/04_unit_test_automation/README.md)
14+
- Lab 5: [Building an Image](labs/05_build_an_image/README.md)
15+
- Lab 6: Deploy to Kubernetes
1016

11-
GitHub Actions can be used as an alternative to Travis CI to run tests on every Pull Request to facilitate implementing Continuous Integration for your development team. Every Pull Request is an opportunity for a code review and any Pull Request that lowers the test coverage should be rejected until more test cases are added to bring the coverage back up to the threshold set by the team. (usually 90% to 95%)
17+
## Instructor
1218

13-
## Setup
19+
John Rofrano, Senior Technical Staff Member, DevOps Champion, @ IBM Research
1420

15-
To complete this lab you will need to Fork this repo because you need to make a change in order to trigger GitHub Actions. When making a Pull Request, you want to make sure that your request is merging with your Fork because the Pull Request of a Fork will default to come back to this repo and not your Fork.
16-
17-
You can read about why in my article [Creating Reproducible Development Environments](https://medium.com/nerd-for-tech/creating-reproducible-development-environments-fac8d6471f35).
18-
19-
### Prerequisite Installation for Intel Mac & PC
20-
21-
The easiest way to use this lab is with **Vagrant** and **VirtualBox**. if you don't have this software the first step is down download and install it.
22-
23-
Download [VirtualBox](https://www.virtualbox.org/)
24-
25-
Download [Vagrant](https://www.vagrantup.com/)
26-
27-
Then all you have to do is clone this repo and invoke vagrant:
28-
29-
```bash
30-
git clone https://github.com/nyu-devops/lab-github-actions.git
31-
cd lab-github-actions
32-
vagrant up
33-
vagrant ssh
34-
cd /vagrant
35-
honcho start
36-
```
37-
38-
You can also automatically set the environment variable FLASK_APP using a `.env` file.
39-
There is an example in this repo called `dot-env-example` that you can simply copy.
40-
41-
```sh
42-
cp dot-env-example .env
43-
```
44-
45-
The `.env` file will be loaded when you do `flask run` so that you don't have to specify
46-
any environment variables.
47-
48-
### Alternate for M1 Macs using Vagrant and Docker
49-
50-
You can also use [Docker Desktop for Apple Silicon](https://docs.docker.com/docker-for-mac/apple-silicon/) as a provider instead of VirtualBox. This is useful for owners of Apple M1 Silicon Macs which cannot run VirtualBox because they have a CPU based on ARM architecture instead of Intel.
51-
52-
Just add `--provider docker` to the `vagrant up` command like this:
53-
54-
```sh
55-
vagrant up --provider docker
56-
```
57-
58-
This will use a Docker container instead of a Virtual Machine (VM). Of course Intel Macs and Windows PCs can use this as well. Just install the appropreate Docker Desktopo build.
59-
60-
### Alternate install using VSCode and Docker
61-
62-
You can also develop in Docker containers using **Visual Studio Code**. This project contains a `.devcontainer` folder that will set up a Docker environment in VSCode for you. You will need the following:
63-
64-
- Docker Desktop for [Mac](https://docs.docker.com/docker-for-mac/install/) or [Windows](https://docs.docker.com/docker-for-windows/install/)
65-
- Microsoft Visual Studio Code ([VSCode](https://code.visualstudio.com/download))
66-
- [Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) VSCode Extension
67-
68-
It is a good idea to add VSCode to your path so that you can invoke it from the command line. To do this, open VSCode and type `Shift+Command+P` on Mac or `Shift+Ctrl+P` on Windows to open the command palete and then search for "shell" and select the option **Shell Command: Install 'code' command in Path**. This will install VSCode in your path.
69-
70-
Then you can start your development environment up with:
71-
72-
```bash
73-
git clone https://github.com/nyu-devops/lab-github-actions.git
74-
cd lab-github-actions
75-
code .
76-
```
77-
78-
The first time it will build the Docker image but after that it will just create a container and place you inside of it in your `/app` folder which actually contains the repo shared from your computer. It will also install all of the VSCode extensions needed for Python development.
79-
80-
If it does not automatically prompt you to open the project in a container, you can select the green icon at the bottom left of your VSCode UI and select: **Remote Containers: Reopen in Container**.
81-
82-
### Alternate manual install using local Python
83-
84-
This option is not recommended because developing natively on your local computer does ensure that the code will work on anyone elses computer or in production. I strongly recommend that you us one of thee reproducible development environments above but if you have Python 3 installed on your computer you can make a virtual environment and run the code locally with:
85-
86-
```bash
87-
python3 -m venv venv
88-
source venv/bin/activate
89-
pip install -r requirements.txt
90-
```
91-
92-
You will also need Docker on your computer to run a container for the database.
93-
94-
```bash
95-
docker run -d --name redis -p 6379:6379 -v redis:/data redis:alpine
96-
```
97-
98-
This will run Redis on Alpine and have it forward port `6379` so that your application and communicate with it.
99-
100-
You can now run `nosetests` to run the TDD tests locally.
101-
102-
You can also test the application manually by running it with:
103-
104-
```bash
105-
honcho start
106-
```
107-
108-
## Manually running the Tests
109-
110-
Run the tests using `nosetests` and `coverage`
111-
112-
```bash
113-
nosetests
114-
```
115-
116-
Nose is configured to automatically include the flags `--with-spec --spec-color --with-coverage` so that red-green-refactor is meaningful. If you are in a command shell that supports colors, passing tests will be green while failing tests will be red.
117-
118-
## What's featured in the project?
119-
120-
```text
121-
* routes.py -- the main Service using Python Flask and Redis
122-
* test_service.py -- test cases using unittest
123-
* .github/workfloows/ci.yml -- the GitHub Actions file that automates testing
124-
````
125-
126-
This repository is part of the NYU class CSCI-GA.2810-001: DevOps and Agile Methodologies taught by John Rofrano, Adjunct Instructor, NYU Courant Institute of Mathematical Sciences, Graduate Division, Computer Science, and NYU Stern School of Business.
21+
## <h3 align="center"> © IBM Corporation 2022. All rights reserved. <h3/>

labs/01_base_pipeline/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Create a base pipeline
2+
3+
This folder holds the files for the lab _Create a Base Pipeline_ which is part of the **IBM-CD0215EN-Skills Network Introduction to CI/CD** course.

labs/01_base_pipeline/pipeline.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Pipeline
3+
metadata:
4+
name: <place-name-here>
5+
spec:
6+
tasks:

labs/01_base_pipeline/tasks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: <place-name-here>
5+
spec:
6+
steps:

labs/02_add_git_trigger/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Adding GitHub Triggers
2+
3+
This folder holds the files for the lab: _Adding GitHub Triggers_ which is part of the **IBM-CD0215EN-Skills Network Introduction to CI/CD** course.

labs/02_add_git_trigger/pipeline.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Pipeline
3+
metadata:
4+
name: cd-pipeline
5+
spec:
6+
params:
7+
- name: repo-url
8+
- name: branch
9+
default: "master"
10+
tasks:
11+
- name: clone
12+
taskRef:
13+
name: checkout
14+
params:
15+
- name: repo-url
16+
value: "$(params.repo-url)"
17+
- name: branch
18+
value: "$(params.branch)"
19+
20+
- name: lint
21+
taskRef:
22+
name: echo
23+
params:
24+
- name: message
25+
value: "Calling Flake8 linter..."
26+
runAfter:
27+
- clone
28+
29+
- name: tests
30+
taskRef:
31+
name: echo
32+
params:
33+
- name: message
34+
value: "Running unit tests with PyUnit..."
35+
runAfter:
36+
- lint
37+
38+
- name: build
39+
taskRef:
40+
name: echo
41+
params:
42+
- name: message
43+
value: "Building image for $(params.repo-url) ..."
44+
runAfter:
45+
- tests
46+
47+
- name: deploy
48+
taskRef:
49+
name: echo
50+
params:
51+
- name: message
52+
value: "Deploying $(params.branch) branch of $(params.repo-url) ..."
53+
runAfter:
54+
- build

labs/02_add_git_trigger/tasks.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: echo
5+
spec:
6+
params:
7+
- name: message
8+
description: The message to echo
9+
type: string
10+
steps:
11+
- name: echo-message
12+
image: alpine:3
13+
command: [/bin/echo]
14+
args: ["$(params.message)"]
15+
16+
---
17+
apiVersion: tekton.dev/v1beta1
18+
kind: Task
19+
metadata:
20+
name: checkout
21+
spec:
22+
params:
23+
- name: repo-url
24+
description: The URL of the git repo to clone
25+
type: string
26+
- name: branch
27+
description: The branch to clone
28+
type: string
29+
steps:
30+
- name: checkout
31+
image: bitnami/git:latest
32+
command: [git]
33+
args: ["clone", "--branch", "$(params.branch)", "$(params.repo-url)"]

labs/03_use_tekton_catalog/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Use Tekton CD Catalog
2+
3+
This folder holds the files for the lab: _Use Tekton CD Catalog_ which is part of the **IBM-CD0215EN-Skills Network Introduction to CI/CD** course.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Pipeline
3+
metadata:
4+
name: cd-pipeline
5+
spec:
6+
params:
7+
- name: repo-url
8+
- name: branch
9+
default: "master"
10+
tasks:
11+
- name: clone
12+
taskRef:
13+
name: checkout
14+
params:
15+
- name: repo-url
16+
value: "$(params.repo-url)"
17+
- name: branch
18+
value: "$(params.branch)"
19+
20+
- name: lint
21+
taskRef:
22+
name: echo
23+
params:
24+
- name: message
25+
value: "Calling Flake8 linter..."
26+
runAfter:
27+
- clone
28+
29+
- name: tests
30+
taskRef:
31+
name: echo
32+
params:
33+
- name: message
34+
value: "Running unit tests with PyUnit..."
35+
runAfter:
36+
- lint
37+
38+
- name: build
39+
taskRef:
40+
name: echo
41+
params:
42+
- name: message
43+
value: "Building image for $(params.repo-url) ..."
44+
runAfter:
45+
- tests
46+
47+
- name: deploy
48+
taskRef:
49+
name: echo
50+
params:
51+
- name: message
52+
value: "Deploying $(params.branch) branch of $(params.repo-url) ..."
53+
runAfter:
54+
- build

labs/03_use_tekton_catalog/tasks.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: tekton.dev/v1beta1
2+
kind: Task
3+
metadata:
4+
name: echo
5+
spec:
6+
params:
7+
- name: message
8+
description: The message to echo
9+
type: string
10+
steps:
11+
- name: echo-message
12+
image: alpine:3
13+
command: [/bin/echo]
14+
args: ["$(params.message)"]
15+
16+
---
17+
apiVersion: tekton.dev/v1beta1
18+
kind: Task
19+
metadata:
20+
name: checkout
21+
spec:
22+
params:
23+
- name: repo-url
24+
description: The URL of the git repo to clone
25+
type: string
26+
- name: branch
27+
description: The branch to clone
28+
type: string
29+
steps:
30+
- name: checkout
31+
image: bitnami/git:latest
32+
command: [git]
33+
args: ["clone", "--branch", "$(params.branch)", "$(params.repo-url)"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Integrate Unit Test Automation
2+
3+
This folder holds the files for the lab: _Integrate Unit Test Automation_ which is part of the **IBM-CD0215EN-Skills Network Introduction to CI/CD** course.

0 commit comments

Comments
 (0)