Script Valley
CI/CD with GitHub Actions
Docker and Container Workflows/Assessment

Practice & Assessment

Test your understanding of Docker and Container Workflows

Multiple Choice Questions

5
1

What permission must be granted for GITHUB_TOKEN to push images to GitHub Container Registry?

2

What does fail-fast: false do in a matrix strategy?

3

How does GitHub ensure a service container is ready before workflow steps start?

4

What does tagging a Docker image with github.sha achieve?

5

What is the cache-to: type=gha,mode=max option in docker/build-push-action?

Coding Challenges

1
1

Build and Push a Docker Image to ghcr.io

Create a Node.js application with a valid Dockerfile. Write a GitHub Actions workflow that triggers on push to main. The workflow must: log in to ghcr.io using docker/login-action with GITHUB_TOKEN, build and push the image to ghcr.io using docker/build-push-action with gha layer caching enabled, and tag the image with both github.sha and latest. Set the packages: write permission. Expected output: the image visible in the repository's Packages tab on GitHub. Verify by navigating to github.com/[owner]/[repo]/pkgs/container/[image]. Estimated time: 25 minutes.

Medium

Mini Project

1

Containerized Integration Test Pipeline

Build a CI workflow for a Node.js REST API that uses PostgreSQL. The workflow triggers on pull_request to main and has two jobs. Job 1 (unit-tests): runs on ubuntu-latest, uses Node 20 with npm caching, runs npm ci and npm test. Job 2 (integration-tests): runs on ubuntu-latest with a postgres:16 service container (password testpassword, database testdb, with pg_isready health check on port 5432), runs npm ci and npm run test:integration with DATABASE_URL pointing to the service. Add a matrix strategy to the unit-tests job to run against Node 18 and Node 20 with fail-fast: false. Job 2 needs job 1. Verify all matrix combinations and the integration test job pass.

Hard