Practice & Assessment
Test your understanding of DevOps Scripting Patterns
Multiple Choice Questions
5What does `set -x` do in a Bash script?
Why is `set +x` used around secret-handling code when `set -x` is active?
What does `trap rollback ERR` accomplish in a deployment script?
What does `kubectl rollout status deployment/myapp --timeout=300s` return if the rollout fails?
In a multi-subcommand CLI, why source subcommand files instead of executing them as separate scripts?
Coding Challenges
1Tested Deployment Toolkit
Build a deployment script `deploy.sh` with the following functions: `preflight(env)` validates environment name and checks required commands; `build(version)` tags a docker image; `push(version)` pushes to a registry; `wait_healthy(url, retries, delay)` polls a health endpoint until success or max retries; `rollback()` runs on ERR trap. Write a BATS test file `test/deploy.bats` with at least 4 tests: test that `preflight` fails on an invalid environment, test that `wait_healthy` returns non-zero after max retries, test that rollback is invoked on build failure (mock docker), and test that the version argument is required. Input: none (tests mock dependencies). Output: passing BATS test suite. Time estimate: 30 minutes.
Mini Project
Production-Ready DevOps Toolkit CLI
Build `devtool` โ a full CLI with subcommands: `deploy` (from lesson 6.3), `monitor` (from module 5 project), `config` (from module 4 project), and `logs` (tails and filters logs from a service with --level, --since, --follow flags). Structure as a multi-file project with `lib/` and `commands/` directories. Source subcommands from the main dispatcher. Include: colored help output that auto-adjusts for non-TTY environments; `--version` flag; ShellCheck-clean code (zero warnings); a Makefile with `install`, `uninstall`, and `test` targets; a BATS test suite covering at least one test per subcommand; proper secret handling with `set +x` around credential operations; and a README with usage examples. This project uses concepts from all six modules.
