Skip to content

Commit d88bbce

Browse files
authored
Downloading usns once instead of multiple times (#1306)
* fix: Adding action for downloading usns in a specific path * feat: downloading usns once
1 parent 5b3743f commit d88bbce

3 files changed

Lines changed: 152 additions & 1 deletion

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Download Latest USNs'
2+
3+
description: |
4+
Fetches the USNs form ubuntu.com/security/notices.json and stores them locally in a json format.
5+
6+
inputs:
7+
distro:
8+
description: 'Ubuntu distro codename to fetch (e.g. jammy, noble)'
9+
required: true
10+
limit:
11+
description: 'The page size of ubuntu API. Maximum items per page: 20'
12+
required: false
13+
offset:
14+
description: 'Number of notices to skip (optional). When omitted, the API starts from the first notice.'
15+
required: false
16+
usns-output-path:
17+
description: 'Exact path to output the USNs JSON file.'
18+
required: true
19+
20+
runs:
21+
using: 'composite'
22+
steps:
23+
- id: fetch
24+
name: Fetch USNs
25+
shell: bash
26+
run: |
27+
"${{ github.action_path }}/fetch_usns.sh" \
28+
--distro "${{ inputs.distro }}" \
29+
--usns-output-path "${{ inputs.usns-output-path }}" \
30+
--limit "${{ inputs.limit }}" \
31+
--offset "${{ inputs.offset }}"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
function main() {
7+
local distro=""
8+
local limit=""
9+
local offset=""
10+
local usns_output_path=""
11+
while [[ "${#}" != 0 ]]; do
12+
case "${1}" in
13+
--help|-h)
14+
shift 1
15+
usage
16+
exit 0
17+
;;
18+
19+
--distro|-d)
20+
distro="${2}"
21+
shift 2
22+
;;
23+
24+
--limit|-l)
25+
limit="${2}"
26+
shift 2
27+
;;
28+
29+
--offset|-o)
30+
offset="${2}"
31+
shift 2
32+
;;
33+
34+
--usns-output-path|-u)
35+
usns_output_path="${2}"
36+
shift 2
37+
;;
38+
39+
"")
40+
shift 1
41+
;;
42+
43+
*)
44+
echo "unknown argument \"${1}\"" >&2
45+
usage
46+
exit 1
47+
;;
48+
esac
49+
done
50+
51+
if [[ -z "${distro:-}" ]]; then
52+
echo "error: --distro is required" >&2
53+
usage
54+
exit 1
55+
fi
56+
57+
if [[ -z "${usns_output_path:-}" ]]; then
58+
echo "error: --usns-output-path is required" >&2
59+
usage
60+
exit 1
61+
fi
62+
63+
local url="https://ubuntu.com/security/notices.json?release=${distro}"
64+
65+
if [[ -n "${limit:-}" ]]; then
66+
url="${url}&limit=${limit}"
67+
fi
68+
69+
if [[ -n "${offset:-}" ]]; then
70+
url="${url}&offset=${offset}"
71+
fi
72+
73+
mkdir -p "$(dirname "${usns_output_path}")"
74+
curl -sSfL "${url}" > "${usns_output_path}" || { echo "error: failed to fetch notices for distro ${distro}" >&2; exit 1; }
75+
}
76+
77+
function usage() {
78+
cat <<-ENDUSAGE
79+
fetch_usns.sh [OPTIONS]
80+
81+
Fetches Ubuntu Security Notices (USNs) JSON for the given distro from ubuntu.com and saves it to the given path.
82+
83+
USAGE
84+
./scripts/fetch_usns.sh --distro jammy --limit 20 --offset 0 --usns-output-path ./jammy-usns.json
85+
86+
OPTIONS
87+
--distro <name> -d <name> Ubuntu distro to fetch (e.g. bionic, focal, jammy, noble). Required.
88+
--limit <n> -l <n> Maximum number of notices to fetch (optional). When omitted, the API returns 20 items.
89+
--offset <n> -o <n> Number of notices to skip (optional). When omitted, the API starts from the first notice.
90+
--usns-output-path <path> -u <path> Path to output USNs JSON file. Required.
91+
--help -h prints the command usage
92+
ENDUSAGE
93+
}
94+
95+
main "${@:-}"

stack/.github/workflows/create-release.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ concurrency: release
2424
env:
2525
STACKS_FILEPATH: "images.json"
2626
PATCHED_USNS_FILENAME: "patched-usns.json"
27+
USNS_NOTICES_ARTIFACT: "usns-notices"
2728
jobs:
2829
preparation:
2930
name: Preparation
@@ -205,13 +206,31 @@ jobs:
205206
echo "platforms=$platforms"
206207
echo "platforms=${platforms}" >> "$GITHUB_OUTPUT"
207208
209+
download_usns:
210+
name: Download USNs
211+
runs-on: ubuntu-24.04
212+
needs: [preparation]
213+
if: ${{ needs.preparation.outputs.polling_type == 'usn' }}
214+
steps:
215+
- name: Download latest USNs
216+
uses: paketo-buildpacks/github-config/actions/stack/download-latest-usns@main
217+
with:
218+
distro: ${{ needs.preparation.outputs.os_codename }}
219+
usns-output-path: "${{ github.workspace }}/${{ env.USNS_NOTICES_ARTIFACT }}.json"
220+
221+
- name: Upload USNs notices
222+
uses: actions/upload-artifact@v4
223+
with:
224+
name: ${{ env.USNS_NOTICES_ARTIFACT }}
225+
path: "${{ github.workspace }}/${{ env.USNS_NOTICES_ARTIFACT }}.json"
226+
208227
# The following job is specific to Ubuntu images. It checks for new
209228
# USNs (Ubuntu Security Notices) and triggers the flow to create
210229
# a new release with the latest images that have the USNs patched.
211230
poll_usns:
212231
name: Poll USNs
213232
runs-on: ubuntu-24.04
214-
needs: [preparation]
233+
needs: [preparation, download_usns]
215234
if: ${{ needs.preparation.outputs.polling_type == 'usn' }}
216235
strategy:
217236
matrix:
@@ -220,6 +239,11 @@ jobs:
220239
outputs:
221240
usns: ${{ steps.new_usns.outputs.usns }}
222241
steps:
242+
- name: Download USNs notices
243+
uses: actions/download-artifact@v4
244+
with:
245+
name: ${{ env.USNS_NOTICES_ARTIFACT }}
246+
223247
- name: Check for Previous Releases
224248
id: check_previous
225249
run: |
@@ -385,6 +409,7 @@ jobs:
385409
uses: paketo-buildpacks/github-config/actions/stack/get-usns@main
386410
with:
387411
distribution: ${{ needs.preparation.outputs.os_codename }}
412+
api_url: "file:///github/workspace/${{ env.USNS_NOTICES_ARTIFACT }}.json"
388413
packages_filepath: "./${{ matrix.arch.name }}-package-list-${{ matrix.stacks.name }}"
389414
last_usns_filepath: "./${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}-previous"
390415
usns_output_path: "./${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}"

0 commit comments

Comments
 (0)