Git Product home page Git Product logo

lab-github-actions's Introduction

lab-github-actions

This is for NYU DevOps lab on using GitHub Actions with Redis for Continuous Integration

Introduction

This lab contains a .ci.yaml file that shows you how to run your tests and request that a Redis service be attached while running them. It also uses Code Coverage to determine how complete your testing is.

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%)

Setup

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.

You can read about why in my article Creating Reproducible Development Environments.

Prerequisite Installation for Intel Mac & PC

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.

Download VirtualBox

Download Vagrant

Then all you have to do is clone this repo and invoke vagrant:

    git clone https://github.com/nyu-devops/lab-github-actions.git
    cd lab-github-actions
    vagrant up
    vagrant ssh
    cd /vagrant
    honcho start

You can also automatically set the environment variable FLASK_APP using a .env file. There is an example in this repo called dot-env-example that you can simply copy.

    cp dot-env-example .env

The .env file will be loaded when you do flask run so that you don't have to specify any environment variables.

Alternate for M1 Macs using Vagrant and Docker

You can also use Docker Desktop for 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.

Just add --provider docker to the vagrant up command like this:

vagrant up --provider docker

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.

Alternate install using VSCode and Docker

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:

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.

Then you can start your development environment up with:

    git clone https://github.com/nyu-devops/lab-github-actions.git
    cd lab-github-actions
    code .

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.

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.

Alternate manual install using local Python

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:

    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt

You will also need Docker on your computer to run a container for the database.

docker run -d --name redis -p 6379:6379 -v redis:/data redis:alpine

This will run Redis on Alpine and have it forward port 6379 so that your application and communicate with it.

You can now run nosetests to run the TDD tests locally.

You can also test the application manually by running it with:

honcho start

Manually running the Tests

Run the tests using nosetests and coverage

nosetests

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.

What's featured in the project?

    * routes.py -- the main Service using Python Flask and Redis
    * test_service.py -- test cases using unittest
    * .github/workfloows/ci.yml -- the GitHub Actions file that automates testing

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.

lab-github-actions's People

Contributors

rofrano avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.