Skip to content

Commit 3369ec5

Browse files
authored
Merge pull request #4 from IntimateMerger/feature-refactor-workflow
Feature refactor workflow
2 parents f467504 + 1705c02 commit 3369ec5

4 files changed

Lines changed: 66 additions & 46 deletions

File tree

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Docker Image
1+
name: Build and Push
22

33
on:
44
push:
@@ -7,19 +7,18 @@ on:
77
- main
88
tags:
99
- '*.*.*.*-*' # Format: 1.27.1.2-0
10-
pull_request:
11-
branches:
12-
- master
13-
- main
1410
workflow_dispatch:
1511

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
15+
1616
env:
1717
DOCKER_IMAGE: intimatemerger/openresty
1818

1919
jobs:
2020
build:
2121
name: Build ${{ matrix.platform }}
22-
if: github.event_name != 'pull_request'
2322
runs-on: ${{ matrix.runner }}
2423
permissions:
2524
contents: read
@@ -46,7 +45,7 @@ jobs:
4645
uses: docker/login-action@v3
4746
with:
4847
username: ${{ vars.DOCKERHUB_USERNAME }}
49-
password: ${{ secrets.DOCKERHUB_PUSH_TOKEN }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN_PUBLIC }}
5049

5150
- name: Build and push by digest
5251
id: build
@@ -96,7 +95,7 @@ jobs:
9695
uses: docker/login-action@v3
9796
with:
9897
username: ${{ vars.DOCKERHUB_USERNAME }}
99-
password: ${{ secrets.DOCKERHUB_PUSH_TOKEN }}
98+
password: ${{ secrets.DOCKERHUB_TOKEN_PUBLIC }}
10099

101100
- name: Extract version from tag
102101
id: version
@@ -169,28 +168,3 @@ jobs:
169168
image: ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }}
170169
only-severities: critical,high
171170
exit-code: false
172-
173-
security-scan:
174-
runs-on: ubuntu-latest
175-
if: github.event_name == 'pull_request'
176-
permissions:
177-
contents: read
178-
security-events: write
179-
180-
steps:
181-
- name: Checkout code
182-
uses: actions/checkout@v6
183-
184-
- name: Run Trivy vulnerability scanner
185-
uses: aquasecurity/trivy-action@master
186-
with:
187-
scan-type: 'config'
188-
scan-ref: '.'
189-
format: 'sarif'
190-
output: 'trivy-results.sarif'
191-
192-
- name: Upload Trivy results to GitHub Security
193-
uses: github/codeql-action/upload-sarif@v4
194-
if: always()
195-
with:
196-
sarif_file: 'trivy-results.sarif'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Security Scan
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- main
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
security-scan:
15+
name: Trivy Security Scan
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
security-events: write
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v6
24+
25+
- name: Run Trivy vulnerability scanner
26+
uses: aquasecurity/trivy-action@master
27+
with:
28+
scan-type: 'config'
29+
scan-ref: '.'
30+
format: 'sarif'
31+
output: 'trivy-results.sarif'
32+
33+
- name: Upload Trivy results to GitHub Security
34+
uses: github/codeql-action/upload-sarif@v4
35+
if: always()
36+
with:
37+
sarif_file: 'trivy-results.sarif'

.trivyignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
AVD-DS-0002
33
# no health check
44
AVD-DS-0026
5+
# change directory
6+
AVD-DS-0013

CLAUDE.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,15 @@ LuaJIT is configured with `LUAJIT_NUMMODE=2` (number mode) and Lua 5.2 compatibi
7575

7676
## CI/CD Pipeline
7777

78-
### GitHub Actions Workflow
78+
### GitHub Actions Workflows
7979

80-
The repository uses `.github/workflows/docker-build.yml` for automated builds with a multi-stage digest-based approach:
80+
The repository uses two separate workflows for improved security and clarity:
81+
82+
#### 1. Build and Push (`.github/workflows/build-and-push.yaml`)
8183

8284
**Triggers**:
8385
- Push to `master`/`main` branch → Build & push to Docker Hub
8486
- Tags matching `*.*.*.*-*` (e.g., `1.27.1.2-0`) → Build & push with version tags
85-
- Pull requests → Security scan only (no build)
8687
- Manual dispatch → Build & push
8788

8889
**Generated Docker Tags**:
@@ -91,39 +92,45 @@ The repository uses `.github/workflows/docker-build.yml` for automated builds wi
9192
- `1.27` - Two-part version
9293

9394
**Required Secrets**:
94-
- `DOCKER_HUB_USERNAME` - Docker Hub username
95-
- `DOCKER_HUB_TOKEN` - Docker Hub access token with Read & Write permissions
95+
- `DOCKERHUB_USERNAME` (variable) - Docker Hub username
96+
- `DOCKERHUB_PUSH_TOKEN` (secret) - Docker Hub access token with Read & Write permissions
97+
98+
#### 2. Security Scan (`.github/workflows/security-scan.yaml`)
99+
100+
**Triggers**:
101+
- Pull requests to `master`/`main` branch
102+
103+
**Purpose**:
104+
- Runs Trivy configuration scanner on Dockerfile and workflow files
105+
- Uploads results to GitHub Security tab
106+
- **No Docker Hub access or secrets required** - provides fast security feedback in isolation
96107

97108
### Build Architecture
98109

99-
The workflow uses a three-stage process for efficient multi-platform builds:
110+
The build-and-push workflow uses a three-stage process for efficient multi-platform builds:
100111

101112
1. **build** (matrix job):
102113
- Runs on native runners: `ubuntu-latest` (amd64), `ubuntu-latest-arm` (arm64)
103114
- Each platform builds independently in parallel
104115
- Uses digest-based push (`push-by-digest=true`) for reliable multi-arch images
105116
- Platform-specific cache scopes for optimal cache utilization
106-
- Skipped for pull requests
107117

108118
2. **merge**:
109119
- Downloads all platform digests
110120
- Creates manifest list using `docker buildx imagetools create`
111121
- Pushes unified multi-platform image with appropriate tags
112122
- Runs Docker Scout CVE scan on final image
113123

114-
3. **security-scan** (PR only):
115-
- Runs Trivy configuration scanner
116-
- Uploads results to GitHub Security tab
117-
- Provides fast feedback without building images
118-
119124
### Security Features
120125

126+
- **Workflow Separation**: Build and security-scan workflows are completely isolated
127+
- PRs never trigger workflows that access Docker Hub secrets
128+
- Reduces attack surface for public repository
121129
- **SBOM Generation**: Enabled (`sbom: true`) for all builds to track dependencies
122130
- **Provenance**: Disabled (`provenance: false`) for maximum compatibility with cloud services (ECR, ACR, GCR)
123131
- **Vulnerability Scanning**:
124132
- Docker Scout (post-merge): Scans final multi-platform image for critical/high CVEs
125133
- Trivy (PRs only): Scans Dockerfile and configuration, uploads to GitHub Security
126-
- **Pull Request Isolation**: PRs run security scans only, no Docker builds or Docker Hub access
127134

128135
### Build Optimization
129136

0 commit comments

Comments
 (0)