Skip to content

Commit af3df5b

Browse files
committed
dec-26 fix usedname in dockerhub
1 parent 4b56b75 commit af3df5b

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

.github/workflows/docker-pipeline.yaml

+38-23
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,50 @@ jobs:
4545
- name: Install Trivy
4646
run: |
4747
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
48-
49-
- name: Build and Scan Multi-Arch Images
50-
run: |
51-
find ./apps -name "Dockerfile" | while read dockerfile; do
52-
app_dir=$(dirname "$dockerfile")
53-
app_name=$(basename "$app_dir")
54-
echo "Building and pushing image for $app_name from $app_dir"
55-
docker buildx build \
56-
--platform linux/amd64,linux/arm64 \
57-
--tag shreeprakashagrahari05/$app_name:latest \
58-
--push \
59-
"$app_dir"
60-
echo "Scanning image for $app_name with Trivy"
61-
trivy image --severity HIGH,CRITICAL shreeprakashagrahari05/$app_name:latest || exit 1
62-
done
63-
64-
- name: Log in to DockerHub
65-
uses: docker/login-action@v2
66-
with:
67-
username: ${{ secrets.DOCKERHUBUSERNAME }}
68-
password: ${{ secrets.DOCKERHUBPASSWORD }}
69-
70-
7148
7249
- name: Log in to DockerHub
7350
uses: docker/login-action@v2
7451
with:
7552
username: ${{ secrets.DOCKERHUBUSERNAME }}
7653
password: ${{ secrets.DOCKERHUBPASSWORD }}
54+
55+
- name: Build, Scan, and Conditionally Push Docker Images
56+
run: |
57+
build_and_push_image() {
58+
local DOCKERFILE_DIR=$1
59+
local IMAGE_NAME=$2
60+
61+
echo "Building Docker image for scanning: $IMAGE_NAME..."
62+
docker buildx build --platform linux/amd64 \
63+
-t "${IMAGE_NAME}:latest" \
64+
-f "${DOCKERFILE_DIR}/Dockerfile" \
65+
${DOCKERFILE_DIR} --load
66+
67+
echo "Scanning Docker image with Trivy: $IMAGE_NAME..."
68+
SCAN_RESULTS=$(trivy image --format json --quiet "${IMAGE_NAME}:latest")
69+
70+
HIGH_SEVERITY=$(echo "$SCAN_RESULTS" | jq '.Results[] | select(.Severity == "HIGH" or .Severity == "CRITICAL")')
71+
72+
if [ -n "$HIGH_SEVERITY" ]; then
73+
echo "High-severity vulnerabilities found for $IMAGE_NAME. Aborting push."
74+
echo "$HIGH_SEVERITY" | jq
75+
exit 1
76+
else
77+
echo "No high-severity vulnerabilities found for $IMAGE_NAME. Rebuilding and pushing multi-arch image..."
78+
docker buildx build --platform linux/amd64,linux/arm64 \
79+
-t "${IMAGE_NAME}:latest" \
80+
-f "${DOCKERFILE_DIR}/Dockerfile" \
81+
${DOCKERFILE_DIR} --push
82+
fi
83+
}
84+
find ./apps -name "Dockerfile" | while read dockerfile; do
85+
app_dir=$(dirname "$dockerfile")
86+
app_name=$(basename "$app_dir")
87+
image_name="shreeprakashagrahari05/$app_name"
88+
89+
echo "Processing $image_name from $app_dir"
90+
build_and_push_image "$app_dir" "$image_name"
91+
done
7792
7893
7994

0 commit comments

Comments
 (0)