1. Build and Test the Docker Image
First, we compile the image locally without pushing it, then spin up a container to validate the/live endpoint.
Tagging images with the Git SHA ensures traceability. Use
${{ github.sha }} for an immutable reference.2. Push the Docker Image to Docker Hub
Once tests pass, rebuild (with cache reuse) and push the image in a dedicated job.Ensure your
DOCKERHUB_TOKEN is stored as a GitHub repository secret to prevent credential leaks.3. Inspecting the Workflow Logs
During the push step, the logs will indicate cache reuse and the push command:build-push-action automatically leverages layers from the testing job to speed up the push.
4. Verifying on Docker Hub
After completion, navigate to your Docker Hub repository. You should find a new tag matching the commit SHA, for example:Job Summary
Links and References
- GitHub Actions Documentation
- Docker Buildx Action
- Docker Login Action
- Docker Build-Push Action
- Docker Hub