Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 6.1 (7 of 10): Packaging and CI/CD pipelines

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

50 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Friday, 5 pm, release time

A team has to release by hand. They copy files. They run tests, if they remember. They upload.

Today they forget one file. The app breaks for all users. Everyone goes home late.

A good team does not do this by hand. A machine does it the same way every time.

Key words

WordWhat it meansExample
Front endThe part the user sees and touches.HTML, CSS, JavaScript
Back endThe part on a server that holds the rules and data.Python, a database
PackageTo put a product's files together so it can be installed.
FrameworkReady-made code you build your app inside.
ExecutableOne file that a computer can run directly.game.exe
Continuous integrationJoining and checking every change straight away. Short name: CI.
Continuous deploymentPutting a change live by itself once it passes. Short name: CD.
PipelineA line of automatic steps that every change goes through.
CompileTurn code you write into code the computer can run.
AutomationA machine doing a job the same way every time.
DatabaseAn organised store of data that programs can search and change.
BuildTo turn source code into something that runs.
Unit testA small test of one part of the code.

The cells students fill in are left blank in this preview.

Many files, one product

A product has a front end and a back end. The front end may be HTML, CSS and a framework (ready-made code).

The back end may be Python and a database.

To give it to users you package it: you put every file in the right place. You can also compile the code and join it into one executable file.

The user does not want ten files and a list of steps. They want one thing that works.

Check: packaging a product

Have a go

Check: packaging a product

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Ways to package

WayWhat the user getsExample
Web productA web address. The files sit on a serverHTML, CSS and JavaScript served with a Python back end
Compiled executableOne file. The code is compiled and joined into itA game you install on a PC
InstallerA file that puts everything in placeA setup file for a desktop app
ContainerA box with the program and what it needsA back end that runs on any server

The cells students fill in are left blank in this preview.

CI and CD

Continuous integration (CI): every time a developer saves a change, a machine joins it to the main code, builds it and tests it.

Continuous deployment (CD): if all checks pass, the change goes live by itself.

The line of automatic steps is a pipeline. A bad change stops in the pipeline. Users never see it.

The five stages of a pipeline

flowchart LR
  src[1 Source code control: a change is pushed] --> build[2 Build automation: make the program]
  build --> unit[3 Unit test automation: run all tests]
  unit -->|all pass| deploy[4 Deployment automation: put it live]
  unit -->|a test fails| stop([Stop and tell the team])
  deploy --> watch[5 Monitoring: watch for problems]
  watch -.->|a problem is found| src

Match the stage to its job

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

What each stage does

StageJobExample tool
Source code controlKeeps the code and starts the pipeline on every pushGit, Gitea, GitHub
Build automationMakes the program from the codeGitHub Actions, Jenkins, Maven
Unit test automationRuns every test. Stops if one failspytest, JUnit
Deployment automationPuts the new version live, the same way each timeDocker, a deploy script
MonitoringWatches the live product and sends an alert on a problemLogs, uptime checks, dashboards

The cells students fill in are left blank in this preview.

A real pipeline file, line by line

A line in the fileWhat it tells the machine
on: pushStart every time somebody pushes code
runs-on: ubuntu-latestUse a fresh Linux computer for the job
run: pip install flask pytestInstall the libraries the product needs (the build)
run: pytestRun every unit test. A failed test stops the pipeline
run: ./deploy.shPut the new version live. It only runs if the tests passed

The cells students fill in are left blank in this preview.

A pipeline stops at the first failure

Code: python
def build():
    print("Building...")
    return True


def test():
    print("Testing...")
    return False   # change to True


def deploy():
    print("Deploying...")
    return True


for name, step in [("build", build), ("test", test), ("deploy", deploy)]:
    if not step():
        print("Stopped at", name)
        break

Make a free account to save your work and track your progress.

Build a pipeline runner

Write the heart of a pipeline. run_pipeline runs each stage in order and stops at the first one that fails. report_line gives a short message for the team. Press Run Tests.

Code: python
def run_pipeline(stages):
    # stages is a list of pairs: (name, check). check is a function that gives back True or False.
    # Run the stages in order. Stop at the first one that gives back False.
    # Give back a dictionary:
    #   {"ran": [names of stages that were run, in order],
    #    "passed": True if every stage passed, else False,
    #    "failed_at": the name of the stage that failed, or None}
    return None


def report_line(result):
    # Give back "Pipeline passed" when result["passed"] is True.
    # Otherwise give back "Pipeline stopped at <name>", for example: Pipeline stopped at test
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.