2323 type : string
2424 required : false
2525 default : ' '
26- description : " The name of the artifact you are building. This is useful when a single pipeline builds more than a single artifact like a container with a shell inside and one without. If you build a single artifact - leave it empty."
26+ description : " The name of the artifact you are building. This is useful when a single pipeline builds more than a single artifact like a container with a shell inside and one without. If you build a single artifact - leave it empty."
2727 disable-artifact-registry-as-image-store :
2828 required : false
2929 default : false
3434 type : string
3535 required : false
3636 default : ' '
37+ nix-version :
38+ description : ' Pinned Nix version used for deterministic builds (must match other CI systems)'
39+ required : false
40+ type : string
41+ default : ' 2.34.4'
3742 secrets :
3843 devguard-token :
3944 description : ' DevGuard API token'
@@ -55,22 +60,27 @@ jobs:
5560 fi
5661
5762 echo "BUILD_ARGS=$BUILD_ARGS --no-push --tarPath /github/workspace/tmp-image.tar" >> $GITHUB_ENV
58-
63+
5964 - name : Checkout code
6065 uses : actions/checkout@v4
6166 with :
6267 submodules : recursive
6368 persist-credentials : false
69+
70+ - uses : cachix/install-nix-action@v31
71+ with :
72+ install_url : ${{ format('https://releases.nixos.org/nix/nix-{0}/install', inputs.nix-version) }}
73+ extra_nix_config : |
74+ experimental-features = nix-command flakes
75+
76+ - name : Install crane and devguard-scanner
77+ run : nix profile install nixpkgs#crane github:l3montree-dev/devguard#devguardScanner
78+
6479 - name : In-Toto Provenance record start
6580 id : in-toto-start
66- uses : docker://ghcr.io/l3montree-dev/devguard/scanner:main
67- with :
68- args : devguard-scanner intoto start --step=build --token=${{ secrets.devguard-token }} --apiUrl=${{ inputs.api-url }} --assetName=${{ inputs.asset-name }} --supplyChainId=${{ github.sha }}
81+ run : devguard-scanner intoto start --step=build --token=${{ secrets.devguard-token }} --apiUrl=${{ inputs.api-url }} --assetName=${{ inputs.asset-name }} --supplyChainId=${{ github.sha }}
6982 continue-on-error : true
7083
71- - name : Setup crane
72- 73-
7484 - name : Build Docker image with Kaniko
7585 # Building the Docker image using Kaniko
7686 id : build_image
8292 run : mv tmp-image.tar "${IMAGE_DESTINATION_PATH}"
8393 env :
8494 IMAGE_DESTINATION_PATH : ${{ inputs.image-destination-path }}
85-
95+
8696 - name : Use crane to get the digest
8797 run : |
8898 crane digest --tarball="${IMAGE_DESTINATION_PATH}" > image-digest.txt
@@ -97,29 +107,31 @@ jobs:
97107 path : ${{ inputs.image-destination-path }}
98108 if : inputs.disable-artifact-registry-as-image-store == false
99109
100- # Calculate the image tag with the same generator used in GitLab CI.
101- - name : Set IMAGE_TAG
102- uses : docker://ghcr.io/l3montree-dev/devguard/scanner:main
103- with :
104- args : >
105- sh -c '
106- if [ -n "$IMAGE" ]; then
107- IMAGE_TAG="$IMAGE"
108- else
109- if [ -n "$IMAGE_SUFFIX" ]; then
110- IMAGE_PATH="ghcr.io/${GITHUB_REPOSITORY}/${IMAGE_SUFFIX}"
111- else
112- IMAGE_PATH="ghcr.io/${GITHUB_REPOSITORY}"
113- fi
114-
115- devguard-scanner generate-tag --imagePath="$IMAGE_PATH" --ref="$GITHUB_REF_NAME" > image-tag-env.txt
116- IMAGE_TAG=$(grep '^IMAGE_TAG=' image-tag-env.txt | cut -d= -f2-)
117- fi
118-
119- IMAGE_TAG=$(echo "$IMAGE_TAG" | tr "[:upper:]" "[:lower:]")
120- echo "$IMAGE_TAG" > image-tag.txt
121- echo "IMAGE_TAG=$(cat image-tag.txt)" >> "$GITHUB_ENV"
122- '
110+ - name : Set image tag
111+ id : set-image-tag
112+ run : |
113+ if [ -n "$IMAGE" ]; then
114+ IMAGE_TAG="$IMAGE"
115+ echo "$IMAGE_TAG" > image-tag.txt
116+ echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_ENV"
117+ else
118+ if [ -n "$IMAGE_SUFFIX" ]; then
119+ IMAGE_PATH="ghcr.io/${GITHUB_REPOSITORY}/${IMAGE_SUFFIX}"
120+ else
121+ IMAGE_PATH="ghcr.io/${GITHUB_REPOSITORY}"
122+ fi
123+ devguard-scanner generate-tag \
124+ --imagePath="$IMAGE_PATH" \
125+ --ref="$GITHUB_REF_NAME" \
126+ >> image-tag-env.txt
127+ IMAGE_TAG=$(grep '^IMAGE_TAG=' image-tag-env.txt | cut -d= -f2-)
128+ ARTIFACT_NAME=$(grep '^ARTIFACT_NAME=' image-tag-env.txt | cut -d= -f2-)
129+ ARTIFACT_URL_ENCODED=$(grep '^ARTIFACT_URL_ENCODED=' image-tag-env.txt | cut -d= -f2-)
130+ echo "$IMAGE_TAG" > image-tag.txt
131+ echo "IMAGE_TAG=$IMAGE_TAG" >> "$GITHUB_ENV"
132+ echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_ENV"
133+ echo "ARTIFACT_URL_ENCODED=$ARTIFACT_URL_ENCODED" >> "$GITHUB_ENV"
134+ fi
123135 env :
124136 IMAGE_SUFFIX : ${{ inputs.image-suffix }}
125137 IMAGE : ${{ inputs.image }}
@@ -138,43 +150,33 @@ jobs:
138150 name : image-digest${{ inputs.image-suffix }}
139151 path : image-digest.txt
140152
141- - name : Set Artifact purl
153+ - name : Set artifact PURL
142154 run : |
143- if [ -n "$ARTIFACT_NAME" ]; then
144- PURL="$ARTIFACT_NAME"
155+ if [ -n "$ARTIFACT_NAME_INPUT" ]; then
156+ PURL="$ARTIFACT_NAME_INPUT"
157+ SAFE_PURL=$(echo -n "$PURL" | jq -s -R -r @uri)
145158 else
146- IMAGE_TAG=$(cat image-tag.txt)
147- REGISTRY_AND_IMAGE=${IMAGE_TAG%:*}
148- VERSION=${IMAGE_TAG##*:}
149- NAMESPACE_AND_NAME=${REGISTRY_AND_IMAGE#*/}
150- NAME=${NAMESPACE_AND_NAME##*/}
151- REPOSITORY_URL="$REGISTRY_AND_IMAGE"
152- PURL="pkg:oci/$NAME?repository_url=$REPOSITORY_URL"
159+ PURL="$ARTIFACT_NAME"
160+ SAFE_PURL="$ARTIFACT_URL_ENCODED"
153161 fi
154-
155162 echo "$PURL" > artifact-purl.txt
163+ echo "$SAFE_PURL" > artifact-purl-safe.txt
156164 echo "PURL=$PURL" >> $GITHUB_ENV
157165 echo "Using artifact name: $PURL"
158166 env :
159- ARTIFACT_NAME : ${{ inputs.artifact-name }}
167+ ARTIFACT_NAME_INPUT : ${{ inputs.artifact-name }}
160168
161169 - name : Upload artifact purl
162170 uses : actions/upload-artifact@v4
163171 with :
164172 name : artifact-purl${{ inputs.image-suffix }}
165173 path : artifact-purl.txt
166174
167- - name : create safe purl
168- run : |
169- SAFE_PURL=$(echo -n "$PURL" | jq -s -R -r @uri)
170- echo "$SAFE_PURL" > artifact-purl-safe.txt
171- echo "Safe artifact name: $SAFE_PURL"
172-
173175 - name : Upload safe artifact purl
174176 uses : actions/upload-artifact@v4
175177 with :
176178 name : artifact-purl-safe${{ inputs.image-suffix }}
177- path : artifact-purl-safe.txt
179+ path : artifact-purl-safe.txt
178180
179181 # Upload the calculated image tag as an artifact
180182 - name : Upload image tag
@@ -184,11 +186,9 @@ jobs:
184186 path : image-tag.txt
185187
186188 - name : In-Toto Provenance record stop
187- uses : docker://ghcr.io/l3montree-dev/devguard/scanner:main
188- with :
189- args : devguard-scanner intoto stop --step=build --products=image-digest.txt --products=image-tag.txt --token=${{ secrets.devguard-token }} --apiUrl=${{ inputs.api-url }} --assetName=${{ inputs.asset-name }} --supplyChainId=${{ github.sha }} --generateSlsaProvenance
189+ run : devguard-scanner intoto stop --step=build --products=image-digest.txt --products=image-tag.txt --token=${{ secrets.devguard-token }} --apiUrl=${{ inputs.api-url }} --assetName=${{ inputs.asset-name }} --supplyChainId=${{ github.sha }} --generateSlsaProvenance
190190 continue-on-error : true
191-
191+
192192 - name : Upload SLSA Provenance
193193 uses : actions/upload-artifact@v4
194194 with :
0 commit comments