-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (167 loc) · 6.14 KB
/
push.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: "Build & push images"
concurrency:
group: bpi-${{ github.repository }}
on:
pull_request:
branches:
- master
push:
branches:
- master
env:
PYTHON_VERSION: 3.9
jobs:
gather:
name: Gather Info
runs-on: ubuntu-20.04
outputs:
directories: ${{ steps.set-directories.outputs.directories }}
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0
path: .
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- id: build-folder-patterns
name: Build Folder Patterns
uses: jannekem/run-python-script-action@v1
with:
script: |
with open("${{ github.workspace }}/build_folders.txt") as stream:
try:
build_folders = list(stream.read().splitlines())
build_folder_patterns = [folder + '/**' for folder in build_folders]
result = ' '.join(build_folder_patterns)
except Exception as ex:
raise ex
set_output('patterns', result)
print("Found the following folders to check for modifications...")
print(result)
- id: changed-files
name: Get changed directories
uses: tj-actions/[email protected]
with:
dir_names: true
files: ${{ steps.build-folder-patterns.outputs.patterns }}
files_separator: ' '
- id: set-directories
name: Set directories
uses: jannekem/run-python-script-action@v1
with:
script: |
import json
import re
added_dirs = "${{ steps.changed-files.outputs.added_files }}".split()
modified_dirs = "${{ steps.changed-files.outputs.modified_files }}".split()
dirs = added_dirs + modified_dirs
unique_dirs = [*set(dirs)]
regex = re.compile(r'.*/.*$')
filtered_dirs = [elem for elem in unique_dirs if not regex.match(elem)]
result = json.dumps(filtered_dirs)
set_output('directories', result)
print("Found the following added/modified directories...")
print(result)
deploy:
name: Deploy/check Image
runs-on: ubuntu-20.04
needs:
- gather
if: ${{ needs.gather.outputs.directories != '[]' }}
strategy:
fail-fast: false
matrix:
directory: ${{ fromJson(needs.gather.outputs.directories) }}
env:
IMAGE_BASENAME: "hub.opensciencegrid.org/slate/${{ matrix.directory }}"
LOCAL_IMAGE_TAG: "${{ matrix.directory }}:${{ github.sha }}"
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 1
path: .
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build image
uses: docker/build-push-action@v5
with:
context: "./${{ matrix.directory }}"
file: "./${{ matrix.directory }}/Dockerfile"
push: false
load: true
tags: ${{ env.LOCAL_IMAGE_TAG }}
timeout-minutes: 30
- name: List loaded images
working-directory: .
run: docker image ls
- name: Lint with Dockle
uses: erzz/dockle-action@v1
with:
image: ${{ env.LOCAL_IMAGE_TAG }}
exit-code: 0
failure-threshold: FATAL
timeout: "10m"
- name: Scan with Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.LOCAL_IMAGE_TAG }}
format: 'table'
exit-code: '0'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
continue-on-error: true
- id: inspect
name: Docker inspect
if: ${{ github.event_name != 'pull_request' }}
working-directory: .
run: |-
IMAGE_VERSION=$(docker inspect --format='{{ index .Config.Labels "org.opencontainers.image.version" }}' ${{ matrix.directory }}:${{ github.sha }})
echo "org.opencontainers.image.version: ${IMAGE_VERSION}"
IMAGE_TAGS=$(docker inspect --format='{{ index .Config.Labels "io.slateci.image.tags" }}' ${{ matrix.directory }}:${{ github.sha }})
echo "io.slateci.image.tags: ${IMAGE_TAGS}"
IMAGE_PROPOSED_TAGS="${IMAGE_VERSION} ${IMAGE_TAGS}"
echo "Proposed image tags: '${IMAGE_PROPOSED_TAGS}'"
echo "proposed-tags=${IMAGE_PROPOSED_TAGS}" >> $GITHUB_OUTPUT
- id: set-tags
name: Set tags
if: ${{ github.event_name != 'pull_request' }}
uses: jannekem/run-python-script-action@v1
with:
script: |
proposed_image_tags = "${{ steps.inspect.outputs.proposed-tags }}".split() + ['latest']
unique_tags = [*set(proposed_image_tags)]
full_tags = ["${{ env.IMAGE_BASENAME }}:" + tag for tag in unique_tags]
result = ','.join(full_tags)
set_output('final-tags', result)
print("Calculated the final image tags...")
print(result)
- name: Authenticate with OSG Harbor
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: hub.opensciencegrid.org
username: "${{ secrets.OSG_HUB_USERNAME }}"
password: "${{ secrets.OSG_HUB_ACCESS_TOKEN }}"
- name: Build/push image
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v5
with:
context: "./${{ matrix.directory }}"
file: "./${{ matrix.directory }}/Dockerfile"
push: true
tags: ${{ steps.set-tags.outputs.final-tags }}
timeout-minutes: 30
- name: Notify Slack of Failure
if: failure()
uses: slateci/github-actions/.github/actions/slack-notify-failure@v16
with:
slack_bot_token: '${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}'