forked from aws/aws-codebuild-docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (89 loc) · 3.6 KB
/
Copy pathbuild-ec2-images.yml
File metadata and controls
101 lines (89 loc) · 3.6 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
95
96
97
98
99
100
101
name: Build EC2 Compute Images
on:
push:
paths:
- 'ubuntu/standard/*/Dockerfile'
- 'ubuntu/standard/*/**'
- 'al/x86_64/standard/*/Dockerfile'
- 'al/x86_64/standard/*/**'
- 'al/aarch64/standard/*/Dockerfile'
- 'al/aarch64/standard/*/**'
pull_request:
paths:
- 'ubuntu/standard/*/Dockerfile'
- 'ubuntu/standard/*/**'
- 'al/x86_64/standard/*/Dockerfile'
- 'al/x86_64/standard/*/**'
- 'al/aarch64/standard/*/Dockerfile'
- 'al/aarch64/standard/*/**'
workflow_dispatch:
inputs:
images:
description: 'Comma-separated image paths to build (e.g. ubuntu/standard/8.0,al/x86_64/standard/6.0). Leave empty to build all.'
required: false
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.changed.outputs.images }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect changed images
id: changed
run: |
# Unmaintained images to exclude from builds
UNMAINTAINED="ubuntu/standard/5.0 ubuntu/standard/6.0 al/x86_64/standard/4.0 al/x86_64/standard/corretto8 al/x86_64/standard/corretto11 al/aarch64/standard/2.0"
is_maintained() {
for skip in $UNMAINTAINED; do [ "$1" = "$skip" ] && return 1; done
return 0
}
# Manual override via workflow_dispatch
if [ -n "${{ inputs.images }}" ]; then
JSON=$(echo "${{ inputs.images }}" | tr ',' '\n' | jq -R . | jq -sc .)
echo "images=$JSON" >> "$GITHUB_OUTPUT"
exit 0
fi
# Build all maintained when triggered manually without specifying images
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
JSON=$(find ubuntu/standard al/x86_64/standard al/aarch64/standard -name Dockerfile -printf '%h\n' 2>/dev/null | sort | while read dir; do is_maintained "$dir" && echo "$dir"; done | jq -R . | jq -sc .)
echo "images=$JSON" >> "$GITHUB_OUTPUT"
exit 0
fi
# Auto-detect from diff
IMAGES=()
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
else
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
fi
for dir in $(find ubuntu/standard al/x86_64/standard al/aarch64/standard -name Dockerfile -printf '%h\n' 2>/dev/null | sort); do
is_maintained "$dir" || continue
if echo "$CHANGED_FILES" | grep -q "^${dir}/"; then
IMAGES+=("$dir")
fi
done
if [ ${#IMAGES[@]} -eq 0 ]; then
echo "images=[]" >> "$GITHUB_OUTPUT"
else
JSON=$(printf '%s\n' "${IMAGES[@]}" | jq -R . | jq -sc .)
echo "images=$JSON" >> "$GITHUB_OUTPUT"
fi
- name: Summary
run: echo "Changed images - ${{ steps.changed.outputs.images }}"
build:
needs: detect-changes
if: needs.detect-changes.outputs.images != '[]'
runs-on:
- codebuild-aws-docker-images-x86-${{ github.run_id }}-${{ github.run_attempt }}
image:${{ contains(matrix.image, 'aarch64') && 'arm-3.0' || 'linux-5.0' }}
instance-size:large
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.detect-changes.outputs.images) }}
steps:
- uses: actions/checkout@v6
- name: Build ${{ matrix.image }}
run: docker build -t codebuild-test/${{ matrix.image }} ${{ matrix.image }}