Prerequisites
Ensure you have the following jobs configured in your workflow:- unit-testing
- code-coverage
Using docker/build-push-action for Build & Test
We’ll leverage Docker’s official build-push-action to compile and test the image locally (push: false). This action supports multiple platforms and advanced build features via Buildx.

By setting
push: false you prevent the image from being sent to a registry, enabling quick feedback on build and tests.Workflow Snippet
Build & Test Action Summary
Dockerfile
Place thisDockerfile in your repository root to define the container:
- Starts from the lightweight Node.js 18 Alpine image
- Sets
/usr/appas the working directory - Installs dependencies from
package.json - Copies the rest of your application code
- Defines default environment variables for MongoDB
- Exposes port 3000 and launches the app using
npm start
Application Health Endpoints
Ensure your Express app exposes a simple/live endpoint for the workflow test. Example in app.js:
Be sure your placeholder environment variables in the Dockerfile match those used in your test commands to avoid runtime errors.
Workflow Run Results
Once the workflow is committed, GitHub Actions will execute the build-and-test job. You’ll see output like this:
