-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
152 lines (142 loc) · 5.15 KB
/
action.yml
File metadata and controls
152 lines (142 loc) · 5.15 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
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
name: "Machinefile executor"
description: "A simple Dockerfile/Containerfile interpreter to set up the local machine"
author: "Gerard Braad <me@gbraad.nl>"
inputs:
version:
description: 'Version of machinefile to download'
required: false
default: '0.9.0'
containerfile:
description: 'Path to the Dockerfile/Containerfile to execute'
required: true
default: 'Containerfile'
context:
description: 'Directory to use as build context'
required: true
default: '.'
runner:
description: 'Runner to use (local, podman, or ssh)'
required: false
default: 'local'
podman-name:
description: 'Name of the Podman container when using podman runner'
required: false
podman-connection:
description: 'Podman connection name'
required: false
podman-binary:
description: 'Path to Podman binary'
required: false
default: 'podman'
ssh-host:
description: 'SSH host for remote execution'
required: false
ssh-user:
description: 'SSH user for remote execution'
required: false
ssh-key:
description: 'Path to SSH private key'
required: false
ssh-password:
description: 'SSH password (not recommended, use secrets)'
required: false
arguments:
description: 'Additional arguments to pass to the machinefile tool (e.g., --arg=USER=gbraad --arg=GROUP=wheel)'
required: false
default: ''
args:
description: 'Build arguments (ARG) in KEY=VALUE format (new style, each on new line)'
required: false
default: ''
binarypath:
description: 'Path to the machinefile binary'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Setup Machinefile executor
id: setup
shell: bash
run: |
VERSION="${{ inputs.version }}"
DOWNLOAD_BASEURL="https://github.com/gbraad-redhat/Machinefile/releases/download/${VERSION}"
if [[ -z "${{ inputs.binarypath }}" ]]; then
arch=$(uname -m)
if [[ "$arch" == "x86_64" ]]; then
DOWNLOAD_URL="${DOWNLOAD_BASEURL}/linux-amd64.tar.gz"
elif [[ "$arch" == "aarch64" ]]; then
DOWNLOAD_URL="${DOWNLOAD_BASEURL}/linux-arm64.tar.gz"
else
echo "::error::Unsupported architecture: $arch. Only x86_64 and aarch64 are supported."
exit 1
fi
echo "Downloading Machinefile executor from $DOWNLOAD_URL"
mkdir -p /tmp/machinefile-executor
curl -sSL $DOWNLOAD_URL | tar -xz -C /tmp/machinefile-executor
chmod +x /tmp/machinefile-executor/machinefile
BINARY_PATH="/tmp/machinefile-executor/machinefile"
echo "Downloaded and extracted Machinefile executor binary"
else
BINARY_PATH="${{ inputs.binarypath }}"
echo "Using specified binary path: $BINARY_PATH"
fi
echo "MACHINEFILE=$BINARY_PATH" >> $GITHUB_ENV
- name: Execute Containerfile commands
shell: bash
run: |
ARGS=""
# Handle runner selection
case "${{ inputs.runner }}" in
"podman")
ARGS="$ARGS -p"
if [[ -n "${{ inputs.podman-name }}" ]]; then
ARGS="$ARGS -n ${{ inputs.podman-name }}"
fi
if [[ -n "${{ inputs.podman-connection }}" ]]; then
ARGS="$ARGS --connection ${{ inputs.podman-connection }}"
fi
if [[ -n "${{ inputs.podman-binary }}" ]]; then
ARGS="$ARGS --podman-binary ${{ inputs.podman-binary }}"
fi
;;
"ssh")
ARGS="$ARGS -s"
if [[ -n "${{ inputs.ssh-host }}" ]]; then
ARGS="$ARGS -H ${{ inputs.ssh-host }}"
fi
if [[ -n "${{ inputs.ssh-user }}" ]]; then
ARGS="$ARGS -u ${{ inputs.ssh-user }}"
fi
if [[ -n "${{ inputs.ssh-key }}" ]]; then
ARGS="$ARGS --key ${{ inputs.ssh-key }}"
fi
if [[ -n "${{ inputs.ssh-password }}" ]]; then
ARGS="$ARGS --password ${{ inputs.ssh-password }}"
fi
;;
"local"|"")
ARGS="$ARGS -l"
;;
*)
echo "::error::Invalid runner type: ${{ inputs.runner }}. Must be one of: local, podman, ssh"
exit 1
;;
esac
# Handle both old-style arguments and new-style args
if [[ -n "${{ inputs.arguments }}" ]]; then
ARGS="$ARGS ${{ inputs.arguments }}"
fi
# Add any build arguments
if [[ -n "${{ inputs.args }}" ]]; then
# Split args on newlines and spaces
echo "${{ inputs.args }}" | while read -r arg || [[ -n "$arg" ]]; do
if [[ -n "$arg" ]]; then
ARGS="$ARGS --arg $arg"
fi
done
fi
echo "Running Containerfile: ${{ inputs.containerfile }}"
echo "Context directory: ${{ inputs.context }}"
echo "Arguments: $ARGS"
sudo $MACHINEFILE $ARGS "${{ inputs.containerfile }}" "${{ inputs.context }}"