|
1 |
| -# lab-github-actions |
| 1 | +# Intro to CI/CD Practice Code |
2 | 2 |
|
3 |
| -[](https://github.com/nyu-devops/lab-github-actions/actions) |
| 3 | +[](https://opensource.org/licenses/Apache-2.0) |
| 4 | +[](https://shields.io/) |
4 | 5 |
|
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** |
6 | 7 |
|
7 |
| -## Introduction |
| 8 | +## Contents |
8 | 9 |
|
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 |
10 | 16 |
|
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 |
12 | 18 |
|
13 |
| -## Setup |
| 19 | +John Rofrano, Senior Technical Staff Member, DevOps Champion, @ IBM Research |
14 | 20 |
|
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/> |
0 commit comments