Pipeline DevSecOps ជាមួយ Jenkins
Pipeline Jenkins លើ AWS EC2 ដែលឈប់នៅពេល SonarQube quality gate បរាជ័យ ស្កេនកូដ និង image ជាមួយ Trivy រួចដាក់ container ឱ្យដំណើរការ និងពិនិត្យ health។
- ប្រភេទ
- គម្រោងផ្ទាល់ខ្លួន
- ឆ្នាំ
- 2026
- ស្ថានភាព
- លំហាត់បានបញ្ចប់
- បច្ចេកវិទ្យា
ការសិក្សាករណីលម្អិតនេះមានជាភាសាអង់គ្លេសនៅឡើយ។
បញ្ហា
A structured DevOps exercise: take a small Express API from a commit to a running container, with security checks built into the release path rather than run as a separate report.
Make code quality, vulnerability scanning and a post-deploy check part of every build, so problems are visible before — not after — the container is running.
តួនាទីរបស់ខ្ញុំ
The repository holds my Jenkinsfile, Dockerfile and a step-by-step guide to setting up the Jenkins and SonarQube servers on EC2.
វិធីសាស្ត្រ
The pipeline is the release gate: every check runs in the same declarative pipeline and can stop it, in a fixed order — tool checks, quality gate, file-system scan, image build and scan, then deploy and health check.
ស្ថាបត្យកម្ម
Two Ubuntu EC2 instances: one runs Jenkins with Docker and Trivy, the other runs SonarQube. Jenkins sends analysis to SonarQube and waits for its webhook with the quality-gate result before continuing.
- GitHub repository
- Jenkins
- Trivy
- Docker
- SonarQube
- NodeAPI container
លំហូរសំណើ
ការសម្រេចចិត្តបច្ចេកទេស
- SonarQube quality gate
- Turns code-quality findings into a pass/fail decision on the release.
- Trivy
- One scanner for vulnerable dependencies, secrets and misconfiguration in both source and image.
- Separate SonarQube server
- Keeps SonarQube’s memory needs away from the build agent.
- node:22-alpine, non-root
- A small base image and an unprivileged user reduce what an attacker gets from a compromised process.
ការអនុវត្ត
The Jenkinsfile is a declarative pipeline of twelve stages. Trivy runs as a container with the vulnerability database cached on the agent, so scans don’t download it every time.
The Dockerfile installs production dependencies with npm ci, runs as an unprivileged user and declares a HEALTHCHECK against /health.
បញ្ហាប្រឈម និងដំណោះស្រាយ
បញ្ហាប្រឈម
SonarQube analyses asynchronously, so a pipeline can move on before the quality-gate result exists.
ដំណោះស្រាយ
The pipeline waits for SonarQube’s webhook with waitForQualityGate and abortPipeline: true.
បញ្ហាប្រឈម
Trivy downloads its vulnerability database on every run.
ដំណោះស្រាយ
Trivy runs as a container with the database cached on the agent.
បញ្ហាប្រឈម
A container can start and still not serve requests.
ដំណោះស្រាយ
The Dockerfile declares a HEALTHCHECK, and the pipeline calls /health after deploying and fails the build if it does not pass.
បញ្ហាប្រឈម
SonarQube’s memory needs compete with builds on the same machine.
ដំណោះស្រាយ
SonarQube runs on its own EC2 instance and reports back to Jenkins.
សុវត្ថិភាព និងភាពជឿជាក់
- waitForQualityGate abortPipeline: true stops the release when SonarQube’s gate fails.
- The container runs as a non-root user.
- Security groups limit SSH and the Jenkins and SonarQube interfaces to known addresses, as documented in the setup guide.
ការធ្វើតេស្ត
The health-check stage is the automated verification: the build fails if the deployed container does not answer on /health. The sample API has no unit tests.
ការប្តូរយកអ្វីមួយ
ជម្រើស
A separate SonarQube server
តម្លៃដែលត្រូវបង់
Two instances to provision, secure and pay for instead of one.
ជម្រើស
Deploying with docker run on the Jenkins server
តម្លៃដែលត្រូវបង់
Simple to follow, but there is no separate environment and no rollback step.
ជម្រើស
Scanner images on the latest tag
តម្លៃដែលត្រូវបង់
Always the newest rules, but results can change between runs without a code change.
លទ្ធផល
An end-to-end pipeline in which code quality and runtime health gate the deployment and both source and image are scanned on every build.
មេរៀន និងជំហានបន្ទាប់
ចំណុចខ្វះខាតដែលដឹង
- Trivy reports findings of every severity but is not configured with --exit-code, so vulnerabilities are visible in the log without failing the build.
- Deployment is a docker run on the Jenkins server itself; there is no separate environment or rollback step.
- Trivy and SonarQube images use the latest tag, so results can change between runs without a code change.
អ្វីដែលខ្ញុំនឹងកែប្រែបន្ទាប់
- Make Trivy fail the build on high and critical findings with --exit-code.
- Deploy to a separate environment with a rollback step.
- Pin scanner image versions so results only change when the pipeline does.
គម្រោងបន្ទាប់វេទិកា microservices សម្រាប់ការលក់រាយ