DevSecOps GitHub Actions Code - Explained
Overview
Alright, now that you’ve seen how the pipeline flows and what tools we’re using, let’s take a step back and walk through how this thing is actually put together. This section gives you a breakdown of each workflow file so you know what’s going on under the hood, and how everything ties together to give us a secure, automated CI/CD setup using GitHub Actions.
Code Overview
All of the workflow logic lives inside the .github/workflows
folder. Each file in this directory is responsible for a specific part of the pipeline—building images, running tests, scanning for vulnerabilities, and pushing to registries. The real magic happens in the main.yml
and pr.yml
files, which orchestrate the order of operations depending on whether code is being pushed to main or coming in through a pull request.
Main Workflow
This is the primary CI/CD pipeline that runs on every push to the main
branch or when manually triggered. It chains together the full DevSecOps flow—building the image, checking code quality, running tests and security scans, and pushing the Docker image.
- File:
main.yml
- Triggers on push to
main
or manual invocation - Sequentially calls
build-image
,lint-format
,unit-sec-test
, andpush-docker-image
- Triggers on push to
PR Workflow
This workflow runs when a pull request is opened, edited, or synchronized. It runs a subset of the pipeline to validate incoming changes before merging.
- File:
pr.yml
- Triggers on pull request events
- Executes
build-image
, followed bylint-format
, and thenunit-sec-test
Build Image Workflow
This workflow builds the Docker image from the current application source. It is invoked by both the main and PR workflows as an early validation step.
- File:
build-image.yml
- Builds a Docker image using the application code
- Tags the image with the commit SHA