Skip to content

Commit 8665e74

Browse files
committed
feat: added lowercase change for trivy AGAIN
1 parent de65b6f commit 8665e74

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

.github/workflows/ci-cd.yml

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,25 @@ jobs:
9292
name: build-artifacts
9393
path: dist/
9494

95-
- name: Set lower-case image ref and sha tag
95+
- name: Prepare lowercase image ref and tags
9696
id: prep
9797
shell: bash
9898
run: |
99-
echo "IMAGE_LC=${REGISTRY}/${IMAGE_NAME,,}" >> $GITHUB_ENV
100-
echo "SHA_TAG=sha-${GITHUB_SHA}" >> $GITHUB_ENV
99+
IMAGE_LC="${{ env.REGISTRY }}/$(echo '${{ env.IMAGE_NAME }}' | tr '[:upper:]' '[:lower:]')"
100+
SHA_TAG="sha-${GITHUB_SHA}"
101+
echo "IMAGE_LC=$IMAGE_LC" >> "$GITHUB_ENV"
102+
echo "SHA_TAG=$SHA_TAG" >> "$GITHUB_ENV"
103+
echo "TRIVY_REF=${IMAGE_LC}:${SHA_TAG}" >> "$GITHUB_ENV"
104+
echo "Will build/scan: ${IMAGE_LC}"
105+
echo "SHA tag: ${SHA_TAG}"
106+
107+
- name: Assert image ref is lowercase (fails fast)
108+
run: |
109+
if echo "$TRIVY_REF" | grep -q '[A-Z]'; then
110+
echo "::error::Image ref contains uppercase: $TRIVY_REF"
111+
exit 1
112+
fi
113+
echo "Image ref OK: $TRIVY_REF"
101114
102115
- name: Set up Docker Buildx
103116
uses: docker/setup-buildx-action@v3
@@ -113,26 +126,29 @@ jobs:
113126
id: meta
114127
uses: docker/metadata-action@v5
115128
with:
116-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
129+
images: ${{ env.IMAGE_LC }}
117130
tags: |
118131
type=sha,format=long
119132
type=ref,event=branch
120133
latest
121134
122-
- name: Build Docker image
135+
- name: Build Docker image (load locally for Trivy)
136+
id: build
123137
uses: docker/build-push-action@v5
124138
with:
125139
context: .
126140
push: false
127-
tags: ${{ steps.meta.outputs.tags }}
128-
labels: ${{ steps.meta.outputs.labels }}
129141
load: true
142+
tags: |
143+
${{ env.TRIVY_REF }}
144+
${{ steps.meta.outputs.tags }}
145+
labels: ${{ steps.meta.outputs.labels }}
130146

131147
- name: Run Trivy vulnerability scanner
132-
uses: aquasecurity/trivy-action@master
148+
uses: aquasecurity/trivy-action@0.24.0
133149
with:
134-
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${{ github.sha }}
135-
format: "table"
150+
image-ref: ${{ env.TRIVY_REF }}
151+
format: table
136152
exit-code: "1"
137153
ignore-unfixed: true
138154
vuln-type: "os,library"
@@ -161,18 +177,21 @@ jobs:
161177
with:
162178
token: ${{ secrets.TOKEN }}
163179

180+
- name: Prepare lowercase image ref
181+
shell: bash
182+
run: |
183+
IMAGE_LC="ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')"
184+
SHA_TAG="sha-${GITHUB_SHA}"
185+
echo "IMAGE_LC=$IMAGE_LC" >> $GITHUB_ENV
186+
echo "SHA_TAG=$SHA_TAG" >> $GITHUB_ENV
187+
echo "NEW_IMAGE=${IMAGE_LC}:${SHA_TAG}" >> $GITHUB_ENV
188+
echo "Will set: ${NEW_IMAGE}"
189+
164190
- name: Setup Git config
165191
run: |
166192
git config user.name "GitHub Actions"
167193
git config user.email "actions@github.com"
168194
169-
- name: Prepare image ref (lowercase)
170-
shell: bash
171-
run: |
172-
IMAGE_LC="ghcr.io/${GITHUB_REPOSITORY,,}"
173-
echo "IMAGE_LC=$IMAGE_LC" >> $GITHUB_ENV
174-
echo "SHA_TAG=sha-${GITHUB_SHA}" >> $GITHUB_ENV
175-
176195
- name: Update Kubernetes deployment file
177196
env:
178197
IMAGE_TAG: sha-${{ github.sha }}

0 commit comments

Comments
 (0)