-
Notifications
You must be signed in to change notification settings - Fork 2
148 lines (133 loc) · 5.65 KB
/
ci.yml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: ci
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
build_context:
description: 'Build directory'
required: true
jobs:
# Job to run change detection
changes:
runs-on: ubuntu-latest
outputs:
# Expose matched filters as job 'images' output variable
images: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- name: Set context from workflow_dispatch
if: github.event_name != 'workflow_dispatch'
id: manual_filter
run: |
echo "changes={ ${{ inputs.build_context}}: '${{ inputs.build_context}}/**' }"
- uses: dorny/paths-filter@v2
if: github.event_name != 'workflow_dispatch'
id: filter
with:
# Use context to get the branch where commits were pushed.
# If there is only one long-lived branch (e.g. master),
# you can specify it directly.
# If it's not configured, the repository default branch is used.
base: ${{ github.ref }}
filters: |
aws-cli: 'aws-cli/**'
buildpack-deps/ubuntu/jammy: 'buildpack-deps/ubuntu/jammy/**'
dokken/centos-7: 'dokken/centos-7/**'
dokken/centos-stream-9: 'dokken/centos-stream-9/**'
dokken/oraclelinux-7: 'dokken/oraclelinux-7/**'
dokken/oraclelinux-8: 'dokken/oraclelinux-8/**'
dokken/oraclelinux-9: 'dokken/oraclelinux-9/**'
dokken/ubuntu-20.04: 'dokken/ubuntu-20.04/**'
dokken/ubuntu-22.04: 'dokken/ubuntu-22.04/**'
doctl: 'doctl/**'
fpm: 'fpm/**'
meshcmd: 'meshcmd/**'
python/3.8/jammy: 'python/3.8/jammy/**'
python/3.8/slim-jammy: 'python/3.8/slim-jammy/**'
python/3.9/jammy: 'python/3.9/jammy/**'
python/3.9/slim-jammy: 'python/3.9/slim-jammy/**'
python/3.10/jammy: 'python/3.10/jammy/**'
python/3.10/slim-jammy: 'python/3.10/slim-jammy/**'
python/3.11/jammy: 'python/3.11/jammy/**'
python/3.11/slim-jammy: 'python/3.11/slim-jammy/**'
python/3.12/jammy: 'python/3.12/jammy/**'
python/3.12/slim-jammy: 'python/3.12/slim-jammy/**'
# Job to build and test each of the modified images
build:
needs: changes
strategy:
matrix:
# Parse JSON array containing names of all filters matching any of changed files
# e.g. ['image1', 'image2'] if both image folders contains changes
image: ${{ fromJSON(needs.changes.outputs.images) }}
if: ${{ needs.changes.outputs.images != '[]' && needs.changes.outputs.images != '' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ matrix.image }}
steps:
- uses: actions/checkout@v4
- name: Check the Containerfile with hadolint
run: |
$(git rev-parse --show-toplevel)/bin/lint.sh
- name: Install QEMU static binaries
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build locally for testing
uses: docker/bake-action@v4
with:
workdir: ${{ matrix.image }}
targets: local
load: true
- name: Run tests on the image with cinc-auditor
run: |
$(git rev-parse --show-toplevel)/bin/test.sh
- name: Login to DockerHub
if: github.event_name == 'push'
uses: docker/login-action@v2
with:
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
password: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
- name: Build and push
uses: docker/bake-action@v4
with:
workdir: ${{ matrix.image }}
push: ${{ github.event_name != 'pull_request' }}
- name: Get the image name
if: github.event_name != 'pull_request'
id: image_name
run: |
json_data="$(docker buildx bake --print 2>/dev/null)"
echo "image_name=$(echo "$json_data" | jq -r '.target.default.labels."org.opencontainers.image.title"')" >> $GITHUB_ENV
- name: Get the image description
if: github.event_name != 'pull_request'
id: image_description
run: |
json_data="$(docker buildx bake --print 2>/dev/null)"
echo "image_description=$(echo "$json_data" | jq -r '.target.default.labels."org.opencontainers.image.description"')" >> $GITHUB_ENV
- name: Get the image readme filepath
if: github.event_name != 'pull_request'
id: image_readme_filepath
run: |
# Check if .group.local.targets.default exists, and if it does, extract its value
json_data="$(docker buildx bake --print 2>/dev/null)"
if echo "$json_data" | jq -e '.target.default.labels["io.boxcutter.image.readme-filepath"]' > /dev/null; then
readme_filepath=$(echo $json_data | jq -r '.target.default.labels["io.boxcutter.image.readme-filepath"]')
echo "image_readme_filepath=$readme_filepath" >> $GITHUB_ENV
else
echo "image_readme_filepath=${{ matrix.image }}/README.md" >> $GITHUB_ENV
fi
- name: Update Docker Hub Description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
password: ${{ secrets.CONTAINER_DESCRIPTION_PASSWORD }}
repository: boxcutter/${{ env.image_name }}
short-description: ${{ env.image_description }}
readme-filepath: ${{ env.image_readme_filepath }}