Sikau

Project: Laptop to production · Day 4 · about 45 min

Final: one-command releases

A bash release script that validates, builds, swaps, verifies and records a version.

Releases without fear

Put it together: ./release.sh 1.1.0 should check the version, build the image with it, replace the running container, prove the new version answers, and record it — or fail loudly without recording anything.

Validate before doing anything

A release script should refuse bad input before it changes anything. Check the version with a regular expression, check you're in the right folder, and check required tools exist. Every failure prints a clear message to stderr and exits non-zero, so a typo like 1.1 can never half-deploy.

version="${1:-}"
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  echo "release: bad version: $version" >&2
  exit 2
fi
[ -f Dockerfile ] || { echo "release: run from cafe/" >&2; exit 2; }

The rest of this lesson

  • Build, swap, verifyexplain
  • Why record releasesexplain
  • release.sh, step by steporder
  • Input to resultmatch
  • release.shchallenge
  • Badge quizquiz
  • Project complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 4 lessons of Project: Laptop to production