-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaction.yml
More file actions
106 lines (96 loc) · 3.36 KB
/
Copy pathaction.yml
File metadata and controls
106 lines (96 loc) · 3.36 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
102
103
104
105
106
name: "wolfi-act"
description: "Dynamic GitHub Actions from Wolfi packages"
inputs:
packages:
description: "Comma-separated list of Wolfi packages to install"
required: true
command:
description: "Command to run"
required: true
apko-image:
description: "The apko image to build with"
required: true
default: "cgr.dev/chainguard/apko:latest"
debug:
description: "Whether or not to add debug logging"
required: false
default: 'false'
runs:
using: "composite"
steps:
- shell: bash
env:
INPUT_DEBUG: ${{ inputs.debug }}
INPUT_COMMAND: ${{ inputs.command }}
INPUT_PACKAGES: ${{ inputs.packages }}
INPUT_APKO_IMAGE: ${{ inputs.apko-image }}
run: |
set -e
debug_args=
debug_args_image="-exc"
debug="${INPUT_DEBUG}"
if [[ "${debug}" == "true" ]]; then
echo "[🐙] Enabling debug logging."
set -x
debug_args="2>/dev/null"
debug_args_image="-ec"
fi
if [[ "${INPUT_COMMAND}" == '' ]]; then
echo "[🐙] Missing input: command"
exit 1
fi
cat >./wolfi-act.apko.config.yaml <<EOL
contents:
repositories:
- https://packages.wolfi.dev/os
keyring:
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
packages:
- ca-certificates-bundle
- wolfi-baselayout
- busybox
- bash
EOL
packages="${INPUT_PACKAGES}"
if [[ "${packages}" != "" ]]; then
for package in $(echo "${packages}" | sed 's/,/\n/g'); do
echo " - ${package}" >> ./wolfi-act.apko.config.yaml
done
fi
printf "[🐙] Building ephemeral container image from Wolfi packages... "
eval docker run --rm \
-v "${PWD}":/work \
-w /work \
"${INPUT_APKO_IMAGE}" \
build \
--arch=x86_64 \
--sbom=false \
wolfi-act.apko.config.yaml \
wolfi-act:latest \
wolfi-act.tar "${debug_args}"
echo "done."
printf "[🐙] Loading ephemeral container image into Docker... "
eval docker load < wolfi-act.tar "${debug_args}"
echo "done."
# Capture runner env for the container, excluding INPUT_* vars and
# any var whose value contains embedded newlines (which no
# line-oriented env file format can represent). env -0 gives
# null-terminated records so multi-line values stay in one record;
# we read them in a while loop to avoid grep -v exit-code-1 when
# no records are filtered, which kills the pipeline under pipefail.
while IFS= read -r -d '' record; do
name="${record%%=*}"
value="${record#*=}"
[[ "$name" == INPUT_* ]] && continue
[[ "$value" == *$'\n'* ]] && continue
printf '%s\n' "$record"
done < <(env -0) > wolfi-act.github.env
echo "[🐙] Running the following command in ephemeral container image:"
echo "${INPUT_COMMAND}"
echo "[🐙] Output:"
docker run -i --rm --platform linux/amd64 \
-v "${PWD}":/work \
-w /work \
--env-file wolfi-act.github.env \
wolfi-act:latest-amd64 \
bash "${debug_args_image}" "${INPUT_COMMAND}"