-
Notifications
You must be signed in to change notification settings - Fork 53
94 lines (83 loc) · 3.38 KB
/
Copy pathexecutor.yml
File metadata and controls
94 lines (83 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Executor
on:
schedule:
- cron: "0 6 * * *" # Daily at 6 AM UTC
workflow_dispatch: # Allow manual triggering
env:
REGISTRY: ghcr.io
IMAGE_NAME: aevea/action-kaniko/executor
SOURCE_REPO: chainguard-forks/kaniko
jobs:
check-and-build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Get latest tag from source repo
id: source-tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_TAG=$(gh release view --repo ${{ env.SOURCE_REPO }} --json tagName -q '.tagName' 2>/dev/null || true)
if [ -z "$LATEST_TAG" ]; then
# Fallback to tags if no releases
LATEST_TAG=$(gh api repos/${{ env.SOURCE_REPO }}/tags --jq '.[0].name')
fi
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest source tag: $LATEST_TAG"
- name: Check if tag already exists in registry
id: check-tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if the image with this tag already exists using GitHub Packages API
EXISTING_TAGS=$(gh api /users/aevea/packages/container/action-kaniko%2Fexecutor/versions --jq '.[].metadata.container.tags[]' 2>/dev/null || true)
if echo "$EXISTING_TAGS" | grep -qx "${{ steps.source-tag.outputs.tag }}"; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.source-tag.outputs.tag }} already exists, skipping build"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag ${{ steps.source-tag.outputs.tag }} does not exist, will build"
fi
- name: Checkout source repository
if: steps.check-tag.outputs.exists == 'false'
uses: actions/checkout@v6
with:
repository: ${{ env.SOURCE_REPO }}
ref: ${{ steps.source-tag.outputs.tag }}
- name: Set up Docker Buildx
if: steps.check-tag.outputs.exists == 'false'
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: steps.check-tag.outputs.exists == 'false'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push executor image
if: steps.check-tag.outputs.exists == 'false'
uses: docker/build-push-action@v6
with:
context: .
file: deploy/Dockerfile
target: kaniko-executor
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.source-tag.outputs.tag }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
build-args: |
TARGETARCH=amd64
TARGETOS=linux
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
run: |
if [ "${{ steps.check-tag.outputs.exists }}" = "true" ]; then
echo "## Build Skipped" >> $GITHUB_STEP_SUMMARY
echo "Tag \`${{ steps.source-tag.outputs.tag }}\` already exists in the registry." >> $GITHUB_STEP_SUMMARY
else
echo "## Build Complete" >> $GITHUB_STEP_SUMMARY
echo "Successfully built and pushed \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.source-tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
fi