feat(ci): Integrate Secure Docker BuildKit Stage with Dual-Image Build and Migration Validation
Summary
This MR enhances the CI/CD pipeline by adding an automated Docker build and validation stage. It implements a secure, daemonless architecture for building application containers and introduces automated migration testing to ensure that built images are deployment-ready.
Key Changes
-
Pipeline Expansion: Added a new
buildstage to.gitlab-ci.yml. -
Secure Build Engine: Configured
docker buildxwith thedocker-containerdriver, eliminating the need for the legacy, insecuredocker:dind(Docker-in-Docker) service on self-hosted runners. -
Dual-Image Build: Automates the creation and pushing of both the main
appand thedb-initutility images to the GitLab Container Registry. -
Automated Migration Testing: The
docker-buildjob now includes apostgisservice. After images are built, the pipeline executesinit_db.pyin a temporary container to verify that migrations run successfully against a live database. -
Optimized Caching: Implemented inline registry caching (
--cache-fromand--cache-to) to significantly reduce build times for subsequent runs. -
Tagging Strategy: Images are tagged with the short commit SHA and branch name. The
latesttag is automatically updated upon merges to the default branch.
Security & Architecture
Following mentor guidance, privileged mode has been avoided by utilizing the docker-container driver. This architecture isolates the build engine within its own unprivileged container on the host VM, adhering to modern security standards for self-hosted CI environments.
How to Verify
-
Monitor the Pipeline: Push this branch and verify that the new
docker-buildstage appears. -
Check Job Logs: Ensure the
db-initvalidation step prints"Database initialization completed successfully.". -
Inspect Registry: Verify that the GitLab Container Registry is populated with the new
appanddb-initimages with correct tags.
Checklist
-
No privilegedmode ordindservice used. -
Both appanddb-initimages are built. -
Migration validation passes against the integrated Postgres service. -
Caching is correctly configured. -
Tagging follows the project convention.
Closes #145
Edited by Kushal Lagichetty