Skip to content

Commit 9caac5e

Browse files
feat: Use pre-built docker images (#12)
1 parent 8ffaa44 commit 9caac5e

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

.github/workflows/build-docker-image.yaml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ name: Build Docker Image
22

33
on:
44
push:
5-
branches: [master]
5+
branches:
6+
- master
7+
- main
8+
- 'feature/**'
9+
- 'bugfix/**'
10+
- 'hotfix/**'
11+
- develop
12+
pull_request:
13+
branches:
14+
- master
15+
- main
616

717
jobs:
818
build:
@@ -14,6 +24,21 @@ jobs:
1424
steps:
1525
- uses: actions/checkout@v5
1626

27+
- name: Extract metadata
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: ghcr.io/itv/kics-github-action
32+
tags: |
33+
# set latest tag for default branch
34+
type=raw,value=latest,enable={{is_default_branch}}
35+
# use branch name for branch builds (push events)
36+
type=ref,event=branch
37+
# use pr number for pull requests
38+
type=ref,event=pr
39+
# use short sha with safe prefix for all events
40+
type=sha,prefix=sha-
41+
1742
- name: Login to GHCR
1843
uses: docker/login-action@v3
1944
with:
@@ -26,4 +51,10 @@ jobs:
2651
with:
2752
context: .
2853
push: true
29-
tags: ghcr.io/itv/kics-github-action:latest
54+
tags: ${{ steps.meta.outputs.tags }}
55+
labels: ${{ steps.meta.outputs.labels }}
56+
57+
- name: Output image details
58+
run: |
59+
echo "Built and pushed the following tags:"
60+
echo "${{ steps.meta.outputs.tags }}"

Dockerfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ FROM ${DOCKERHUB_REGISTRY}/checkmarx/kics:v2.1.13 as kics-env
33

44
FROM cgr.dev/chainguard/wolfi-base:latest
55

6+
# Install Node.js and npm
7+
RUN apk add --update nodejs npm
8+
69
COPY --from=kics-env /app /app
710

811
COPY ./entrypoint.sh /entrypoint.sh
912

1013
RUN chmod +x /entrypoint.sh
1114

12-
COPY ./ /app
15+
# Copy package files first for better Docker layer caching
16+
COPY package*.json /app/
17+
18+
# Set working directory and install dependencies
19+
WORKDIR /app
20+
RUN npm ci
21+
22+
# Copy rest of the application files
23+
COPY ./ /app/
24+
25+
# Build the application
26+
RUN npm run build --if-present
1327

1428
ENTRYPOINT ["/entrypoint.sh"]

action.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,26 @@ inputs:
104104
cloud_provider:
105105
description: "list of cloud providers to scan (alicloud, aws, azure, gcp)"
106106
required: false
107-
dockerhub_registry:
108-
description: "The Docker registry for the KICS base image. Overridden for private registries."
107+
use-ecr-registry:
108+
description: "Whether to use AWS ECR as the container registry"
109109
required: false
110-
default: "docker.io"
110+
default: "false"
111111
branding:
112112
icon: "shield"
113113
color: "green"
114114
runs:
115115
using: "composite"
116116
steps:
117-
- name: Build KICS Action Image
118-
shell: bash
119-
run: docker build --build-arg DOCKERHUB_REGISTRY="${{ inputs.dockerhub_registry }}" -t kics-action:latest "${{ github.action_path }}"
120-
121117
- name: Run KICS Scan
122118
shell: bash
123119
run: |
124-
docker run --name kics-scan \
120+
if [[ "${{ inputs.use-ecr-registry }}" == "true" ]]; then
121+
IMAGE="655028521085.dkr.ecr.eu-west-1.amazonaws.com/cp-gha-kics:0.0.2"
122+
else
123+
IMAGE="ghcr.io/itv/kics-github-action:develop"
124+
fi
125+
echo "Using image: $IMAGE"
126+
docker run --quiet --name kics-scan \
125127
-v "${{ github.workspace }}":"${{ github.workspace }}" \
126128
-w "${{ github.workspace }}" \
127129
-e GITHUB_ACTION \
@@ -177,4 +179,4 @@ runs:
177179
-e INPUT_INCLUDE_QUERIES="${{ inputs.include_queries }}" \
178180
-e INPUT_BOM="${{ inputs.bom }}" \
179181
-e INPUT_CLOUD_PROVIDER="${{ inputs.cloud_provider }}" \
180-
kics-action:latest
182+
$IMAGE

entrypoint.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,5 @@ cp -r "${CP_PATH}" "/app/"
8686

8787
cd /app
8888

89-
# install and run nodejs
90-
apk add --update nodejs npm
91-
npm ci
92-
npm run build --if-present
89+
# run nodejs application
9390
node dist/index.js

0 commit comments

Comments
 (0)