Skip to content

Commit 01b7d26

Browse files
committed
feat(agentless): only push agent containers on merges to main
1 parent e797d1d commit 01b7d26

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

.github/workflows/agentless-container.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Build and push agentless container image
22

33
# Configures this workflow to run every time a tag is created
44
on:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- containers/agentless/**
10+
- .github/workflows/agentless-container.yaml
511
push:
612
branches:
713
- main
@@ -57,7 +63,10 @@ jobs:
5763
done
5864
TAGS=$(echo $TAGS | tr '[:upper:]' '[:lower:]')
5965
60-
docker buildx build --push --platform linux/amd64,linux/arm64 $TAGS --metadata-file=metadata.json -f ../containers/agentless/Dockerfile ../containers/agentless
66+
# GITHUB_BASE_REF is only set when the action source event is a pull request.
67+
# in that case don't push.
68+
export PUSH=$(if [ -z ${GITHUB_BASE_REF+x} ]; then echo "--push"; else echo ""; fi)
69+
docker buildx build $PUSH --platform linux/amd64,linux/arm64 $TAGS --metadata-file=metadata.json -f ../containers/agentless/Dockerfile ../containers/agentless
6170
6271
cat metadata.json
6372
echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT
@@ -66,6 +75,7 @@ jobs:
6675
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
6776
- name: Generate artifact attestation
6877
uses: actions/attest-build-provenance@v2
78+
if: ${{ env.GITHUB_BASE_REF != '' }}
6979
with:
7080
subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/agentless
7181
subject-digest: ${{ steps.build.outputs.digest }}

0 commit comments

Comments
 (0)