3
3
4
4
set -x
5
5
6
+ # Defaults for pause image
7
+ # This pause image is multi-arch
8
+ PAUSE_IMAGE_REPO_DEFAULT=" quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256"
9
+ PAUSE_IMAGE_VERSION_DEFAULT=" 7f3cb6f9d265291b47a7491c2ba4f4dd0752a18b661eee40584f9a5dbcbe13bb"
10
+ PAUSE_IMAGE_REPO_AUTH_FILE=" /tmp/regauth/auth.json"
11
+
6
12
# function to trap errors and exit
7
13
function error_exit() {
8
14
echo " $1 " 1>&2
@@ -22,6 +28,7 @@ function install_rpm_packages() {
22
28
" git"
23
29
" make"
24
30
" unzip"
31
+ " skopeo"
25
32
)
26
33
27
34
# Create a new array to store rpm packages that are not installed
@@ -58,16 +65,19 @@ function install_rpm_packages() {
58
65
# are available in the variable REQUIRED_BINARY_PACKAGES
59
66
# the function will download the packages, extract them and install them in /usr/local/bin
60
67
# Following are the packages that are installed:
68
+ # TBD: add multi-arch support for these binaries
61
69
# "packer=https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip"
62
70
# "kubectl=https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/4.14.9/openshift-client-linux.tar.gz"
63
71
# "yq=https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64.tar.gz"
72
+ # "umoci=https://github.com/opencontainers/umoci/releases/download/v0.4.7/umoci.amd64"
64
73
65
74
install_binary_packages () {
66
75
# Define the required binary packages
67
76
REQUIRED_BINARY_PACKAGES=(
68
77
" packer=https://releases.hashicorp.com/packer/1.9.4/packer_1.9.4_linux_amd64.zip"
69
78
" kubectl=https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/4.14.9/openshift-client-linux.tar.gz"
70
79
" yq=https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64.tar.gz"
80
+ " umoci=https://github.com/opencontainers/umoci/releases/download/v0.4.7/umoci.amd64"
71
81
)
72
82
73
83
# Specify the installation directory
@@ -94,8 +104,9 @@ install_binary_packages() {
94
104
tar -xf " ${download_path} " -C " ${install_dir} " ||
95
105
error_exit " Failed to extract ${package_name} "
96
106
else
97
- echo " Unsupported archive format for ${package_name} . Skipping."
98
- continue
107
+ echo " Copying ${download_path} to ${install_dir} /${package_name} "
108
+ cp " ${download_path} " " ${install_dir} /${package_name} " ||
109
+ error_exit " Failed to move ${package_name} to ${install_dir} "
99
110
fi
100
111
101
112
echo " Marking ${install_dir} /${package_name} executable"
@@ -122,20 +133,23 @@ function download_source_code() {
122
133
# Download source code from GitHub
123
134
# If any error occurs, exit the script with an error message
124
135
125
- # Delete the source code directory if it exists
126
- [[ -d " ${CAA_SRC_DIR} " ]] &&
127
- rm -rf " ${CAA_SRC_DIR} "
136
+ # CAA_SRC_DIR is set to CAA_SRC_DOWNLOAD_DIR/src/cloud-api-adaptor
137
+ # The default value of CAA_SRC_DOWNLOAD_DIR is /src/cloud-api-adaptor
138
+
139
+ # Delete the source code download directory if it exists
140
+ [[ -d " ${CAA_SRC_DOWNLOAD_DIR} " ]] &&
141
+ rm -rf " ${CAA_SRC_DOWNLOAD_DIR} "
128
142
129
143
# Create the root directory for source code
130
- mkdir -p " ${CAA_SRC_DIR } "
144
+ mkdir -p " ${CAA_SRC_DOWNLOAD_DIR } "
131
145
132
146
# Download the source code from GitHub
133
- git clone " ${CAA_SRC} " " ${CAA_SRC_DIR } " ||
147
+ git clone " ${CAA_SRC} " " ${CAA_SRC_DOWNLOAD_DIR } " ||
134
148
error_exit " Failed to download source code from GitHub"
135
149
136
150
# Checkout the required commit
137
- cd " ${CAA_SRC_DIR } " ||
138
- error_exit " Failed to change directory to ${CAA_SRC_DIR } "
151
+ cd " ${CAA_SRC_DOWNLOAD_DIR } " ||
152
+ error_exit " Failed to change directory to ${CAA_SRC_DOWNLOAD_DIR } "
139
153
140
154
git checkout " ${CAA_REF} " ||
141
155
error_exit " Failed to checkout the required commit"
@@ -156,12 +170,12 @@ function prepare_source_code() {
156
170
157
171
local podvm_dir=" ${CAA_SRC_DIR} /podvm"
158
172
173
+ mkdir -p " ${podvm_dir} " /files
174
+
159
175
# Download the podvm binaries and copy it to the podvm/files directory
160
176
tar xvf /payload/podvm-binaries.tar.gz -C " ${podvm_dir} " /files ||
161
177
error_exit " Failed to download podvm binaries"
162
178
163
- mkdir -p " ${podvm_dir} " /files/pause_bundle # workaround to avoid pause image requirement
164
-
165
179
# Set the NVIDIA_DRIVER_VERSION if variable is set
166
180
if [[ " ${NVIDIA_DRIVER_VERSION} " ]]; then
167
181
echo " NVIDIA_DRIVER_VERSION is set to ${NVIDIA_DRIVER_VERSION} "
@@ -183,7 +197,53 @@ function prepare_source_code() {
183
197
fi
184
198
}
185
199
200
+ # Download and extract pause container image
201
+ # Accepts three arguments:
202
+ # 1. pause_image_repo_url: The registry URL of the OCP pause image.
203
+ # 2. pause_image_tag: The tag of the OCP pause image.
204
+ # 2. auth_json_file (optional): Path to the registry secret file to use for downloading the image
205
+ function download_and_extract_pause_image() {
206
+
207
+ # Set default values for the OCP pause image
208
+ pause_image_repo_url=" ${1:- ${PAUSE_IMAGE_REPO_DEFAULT} } "
209
+ pause_image_tag=" ${2:- ${PAUSE_IMAGE_VERSION_DEFAULT} } "
210
+ auth_json_file=" ${3:- ${PAUSE_IMAGE_REPO_AUTH_FILE} } "
211
+
212
+ # If arguments are not provided, exit the script with an error message
213
+ [[ $# -lt 2 ]] &&
214
+ error_exit " Usage: download_and_extract_pause_image <pause_image_repo_url> <pause_image_tag> [registry_secret]"
215
+
216
+ # Ensure CAA_SRC_DIR is set
217
+ [[ -z " ${CAA_SRC_DIR} " ]] && error_exit " CAA_SRC_DIR is not set"
218
+
219
+ local podvm_dir=" ${CAA_SRC_DIR} /podvm"
220
+ local pause_src=" /tmp/pause"
221
+ local pause_bundle=" ${podvm_dir} /files/pause_bundle"
222
+
223
+ mkdir -p " ${pause_bundle} " ||
224
+ error_exit " Failed to create the pause_bundle directory"
225
+
226
+ # Form the skopeo CLI. Add authfile if provided
227
+ if [[ -n " ${3} " ]]; then
228
+ SKOPEO_CLI=" skopeo copy --authfile ${auth_json_file} "
229
+ else
230
+ SKOPEO_CLI=" skopeo copy"
231
+ fi
232
+
233
+ # Download the pause image
234
+ $SKOPEO_CLI " docker://${pause_image_repo_url} :${pause_image_tag} " " oci:${pause_src} :${pause_image_tag} " ||
235
+ error_exit " Failed to download the pause image"
236
+
237
+ # Extract the pause image using umoci into pause_bundle directory
238
+ umoci unpack --rootless --image " ${pause_src} :${pause_image_tag} " " ${pause_bundle} " ||
239
+ error_exit " Failed to extract the pause image"
240
+
241
+ }
242
+
186
243
# Global variables
187
244
188
245
# Set global variable for the source code directory
189
- export CAA_SRC_DIR=" /src/cloud-api-adaptor"
246
+ # The project layout has changed for the cloud-api-adaptor project
247
+ # https://github.com/confidential-containers/cloud-api-adaptor
248
+ export CAA_SRC_DOWNLOAD_DIR=" /src/cloud-api-adaptor"
249
+ export CAA_SRC_DIR=" /src/cloud-api-adaptor/src/cloud-api-adaptor"
0 commit comments