# Your Pipeline Pack

Course: [CI/CD](https://www.devtutorials.ai/learn/cicd) · Section: Running Pipelines Well
Source: https://www.devtutorials.ai/learn/cicd/running-pipelines-well/your-pipeline-pack

> The capstone: fix a weak pipeline until it survives an incident gauntlet of bad pull requests, broken releases, a vulnerable image and an attacker, then push it to a real repo and download it as a pack.

## Your Pipeline Pack

This is the final project.

You start with a weak pipeline. It has many of the problems you met in this course. You fix it until it survives an **incident gauntlet**, then download it as a pack for your own project.

What you will make:

- a full CI pipeline: lint, type check, tests, one build.
- a container image: built once, scanned, tagged with the commit.
- a full CD pipeline: staging, smoke test, approved production, rollback.
- the files around it: CODEOWNERS, Dependabot and a setup checklist.

**Simple lesson:** everything you learned, in one pipeline you can really use.

### A Real-World Example

Think about a driving test.

- You have practised each skill alone: starting, turning, parking.
- The test puts them together on a real road.
- The examiner throws surprises at you: a red light, a sudden stop.
- Pass, and you get a licence you can use every day.

Now map it:

- **Each skill** = each lesson.
- **The real road** = the capstone pipeline.
- **The surprises** = the incident gauntlet.
- **The licence** = your downloaded pipeline pack.

**Simple lesson:** the gauntlet is your driving test. The pack is your licence.

## The Incident Gauntlet

The lab runs your pipeline against these incidents:

| Incident | It must… | Lesson that covers it |
|---|---|---|
| A pull request with a failing test | be blocked, with no hidden failure | Quality Gates on Pull Requests |
| A pull request that breaks a style rule | be blocked | Quality Gates on Pull Requests |
| A pull request with a type error | be blocked | Quality Gates on Pull Requests |
| A clean pull request | pass, and deploy nothing | Environments and Secrets |
| A clean merge to main | reach staging, then approved production, same image, OIDC sign-in | Deploy for Real |
| A broken release | stop at staging | Deploy and Smoke Test |
| A bug that only shows in production | be rolled back by itself | Rollback and Recovery |
| A base image with a critical security hole | be stopped before any deploy | Containers in CI |
| The attacker (GitHub) or a slow start (Azure) | be stopped, or pass after retries | Pipeline Security |

Work through the gauntlet one red line at a time. Each line tells you what is missing. The cheat sheets from earlier lessons have the exact YAML.

**Simple lesson:** each incident is a real thing that happens to real teams.

## Part 1: CI

Start with the pull request side.

- Split the checks into lint, type check and test jobs.
- Remove anything that hides a failure.
- Build the image only on main, then scan it with a gate.
- On GitHub: pin actions, read-only token, `persist-credentials: false`.

**Simple lesson:** no bad change gets past a pull request.

## Part 2: CD

CI is done for you here. Now make releases safe.

- Staging first, with a smoke test and retries.
- Production needs staging, uses `environment: production`, only from main.
- OIDC sign-in, never a stored password.
- A rollback job on failure.

**Simple lesson:** no bad release stays in production.

## Part 3: The Whole Pipeline

Now the real test. Start from the weak file and fix everything.

- This is the file that goes into your pack.
- The lab saves your work in this browser as you type.

**Real tools vs this lab:** the deploy steps are the real ones: `azure/webapps-deploy` (GitHub) and `AzureWebAppContainer@1` (Azure). The lab only pretends the Azure apps and the registry exist. The starter repo below holds this exact pipeline.

1. Download the starter repo and follow its README: your names, the one-time Azure setup, the GitHub variables.
2. Push to main. Watch lint, typecheck and test, then build-image, then deploy-staging.
3. Publish a release `v1.0.0` from that commit and approve production.
4. Open `https://<your-production-app>.azurewebsites.net/health`.

**What you should see:** every job green, and your app live on the web. That is a real CI/CD pipeline, made by you. Delete the resource group when you finish, so it does not cost money.

**Simple lesson:** one file that handles every incident.

## Choose a Release Strategy

Your pack deploys the whole app at once, with a smoke test and a rollback. When your app grows, try a canary.

**Simple lesson:** start simple. Add a canary when you have good metrics.

## Download Your Pack

Fill in your project's details. Check readiness. Then download.

What is inside:

- **The pipeline file**, with your staging and production addresses.
- **`.github/CODEOWNERS`**: your team owns the pipeline files.
- **`.github/dependabot.yml`**: weekly updates for actions and packages.
- **`docs/RELEASE-CHECKLIST.md`**: the one-time settings YAML cannot do, like approvals and OIDC trust.
- **`docs/PIPELINE-README.md`**: a short explanation for your team.

Before the first real run, do every item in `RELEASE-CHECKLIST.md`. Without required reviewers and branch rules on the real platform, the approval and main-only rules are only half there.

**Simple lesson:** the pack is a starting point for your real project. Read it, adjust it, own it.

## Quick Check

## Cheat Sheet

The shape of the final pipeline:

```text
pull request ─▶ lint ─┐
               typecheck ─┼─▶ (merge only if all green)
               test ─┘

push to main ─▶ lint, typecheck, test ─▶ build-image (once, SHA tag) ─▶ scan ─▶ attest
             ─▶ deploy-staging ─▶ smoke test staging
             ─▶ deploy-production (approval, OIDC, main only) ─▶ smoke test production
             ─▶ rollback-production (only on failure) ─▶ smoke test again
```

## Common mistakes

| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| Copying the pack without the checklist | The YAML does everything | Some rules are platform settings | No real approval, no branch rule |
| Keeping `shop-web-*` names | They will work | Use your own app and image names | "App does not exist" on the first run |
| Building again for production | It is the same code | Promote one image tag | Untested bits in production |
| Rollback never tried | It is in the file, so it works | Practise it on staging | It fails in a real outage |
| Treating the pack as finished | Done once, done forever | Review it like any product | It slowly goes out of date |

## What to Remember

- The gauntlet = the real incidents your pipeline must handle.
- CI blocks bad changes. CD blocks bad releases and undoes the rest.
- Your pack = pipeline + owners + updates + a setup checklist.
- Do the checklist before the first real run.

## Exercises

Next: **CI/CD Cheat Sheet**
