Skip to content

Commit d24db94

Browse files
alexlianidesalexlianides
and
alexlianides
authored
extraBuildArtifact staging and push fix (#115)
* Updated pull_build_artifact process for extraBuildArtifacts. Updated dev-test to test feature * updated push_build_artifacts.sh to search config for extraBuildArtifacts for tag as well as repository and directory. Updated logging for login container registry * fix push_build_artifacts to utilize image tag from extraBuildArtifacts if present --------- Co-authored-by: alexlianides <alianides@microsoft.com>
1 parent 26568af commit d24db94

File tree

6 files changed

+49
-23
lines changed

6 files changed

+49
-23
lines changed

.devcontainer/artifacts.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ config:
1212
pull_enabled: true
1313
login_enabled: false
1414
extraBuildArtifacts:
15-
- file: testartifact.txt
16-
directory: tmp/test
17-
repository: test
18-
tag: 0.11.0
15+
- file: push-build-artifact-test.txt
16+
directory: tmp
17+
repository: buildartifacts/txt/push-build-artifact-test
18+
tag: 0.11.0-nightly
1919

.devcontainer/test-feature/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"app_name": "spacesdk-setup",
1212
"app_type": "none",
1313
"extract_setup_files": "false",
14-
"addl_config_yamls":"/workspaces/azure-orbital-space-sdk-setup/.devcontainer/artifacts.yaml"
14+
"addl_config_yamls":"/workspaces/azure-orbital-space-sdk-setup/.devcontainer/artifacts.yaml",
15+
"download_artifacts": "push-build-artifact-test.txt"
1516
}
1617
},
1718
"hostRequirements": {

build/push_build_artifact.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function check_for_preset_config() {
129129

130130
run_a_script "jq -r '.config.buildArtifacts[] | select(.file == \"${fileName}\") | @base64' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" build_artifact --ignore_error --disable_log
131131

132-
# We don't have the artifact in the main build artifacts. Look in extraArtifacts
132+
# We don't have the artifact in the main build artifacts. Look in extraBuildArtifacts
133133
if [[ -z "${build_artifact}" ]]; then
134134
run_a_script "jq -r '.config.extraBuildArtifacts[] | select(.file == \"${fileName}\") | @base64' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" build_artifact --ignore_error --disable_log
135135
fi
@@ -302,14 +302,25 @@ function main() {
302302
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}"
303303
DEST_SPACEFX_TAG="${SPACEFX_VERSION}"
304304

305-
# Check if we have a tag suffix from our config file
306-
run_a_script "jq -r 'if (.config | has(\"tagSuffix\")) then .config.tagSuffix else \"\" end' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" tag_suffix --disable_log
305+
run_a_script "basename ${ARTIFACT}" fileName --disable_log
307306

308-
if [[ -n "${tag_suffix}" ]]; then
309-
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}${tag_suffix}"
310-
DEST_SPACEFX_TAG="${SPACEFX_VERSION}${tag_suffix}"
311-
fi
307+
# Look in extraBuildArtifacts to see if a specfic tag is required
308+
run_a_script "jq -r '.config.extraBuildArtifacts // empty | map(select(.file == \"${fileName}\")) | if length > 0 then .[0] | @base64 else \"\" end' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" build_artifact --disable_log --ignore_error
309+
310+
# Found the in extraBuildArtifacts, confirmed static artifact
311+
if [[ -n "${build_artifact}" ]]; then
312+
info_log "..found '${fileName}' in build artifacts."
313+
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}"
314+
DEST_SPACEFX_TAG="${ARTIFACT_VERSION}"
315+
else
316+
# artifact is not static, check if we have a tag suffix from our config file
317+
run_a_script "jq -r 'if (.config | has(\"tagSuffix\")) then .config.tagSuffix else \"\" end' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" tag_suffix --disable_log
312318

319+
if [[ -n "${tag_suffix}" ]]; then
320+
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}${tag_suffix}"
321+
DEST_SPACEFX_TAG="${SPACEFX_VERSION}${tag_suffix}"
322+
fi
323+
fi
313324

314325
write_parameter_to_log DEST_ARTIFACT_TAG
315326
write_parameter_to_log DEST_SPACEFX_TAG

modules/m_60_container_registries.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ function find_registry_for_image(){
239239
login_to_container_registry --container_registry "${container_registry}" --container_registry_username_file "${login_username_file}" --container_registry_password_file "${login_password_file}"
240240
fi
241241

242+
debug_log "Running 'regctl image manifest ${container_registry}/${_find_registry_for_image_repo}'"
242243
run_a_script "regctl image manifest ${container_registry}/${_find_registry_for_image_repo}" _find_registry_for_image_result --ignore_error --disable_log
244+
debug_log "_find_registry_for_image_result:"
245+
debug_log "${_find_registry_for_image_result}"
243246

247+
244248
if [[ "${_find_registry_for_image_result}" == *"unauthorized"* ]]; then
245249
exit_with_error "Unauthorized to access image to container registry '${container_registry}'. Please login with docker login '${container_registry}', regctl registry login '${container_registry}' --user <username> --pass <password>, or use the config login_username_file and login_password_file configuration options"
246250
fi

scripts/stage/stage_build_artifact.sh

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ function download_artifact() {
166166
run_a_script "jq -r '.config.buildArtifacts // empty | map(select(.file == \"${fileName}\")) | if length > 0 then .[0] | @base64 else \"\" end' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" build_artifact --disable_log --ignore_error
167167

168168
if [[ -z "${build_artifact}" ]]; then
169-
# We don't have the artifact in the main build artifacts. Look in extraArtifacts
170-
run_a_script "jq -r '.config.extraArtifacts // empty | map(select(.file == \"${fileName}\")) | if length > 0 then .[0] | @base64 else \"\" end' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" build_artifact --disable_log --ignore_error
169+
# We don't have the artifact in the main build artifacts. Look in extraBuildArtifacts
170+
run_a_script "jq -r '.config.extraBuildArtifacts // empty | map(select(.file == \"${fileName}\")) | if length > 0 then .[0] | @base64 else \"\" end' ${SPACEFX_DIR}/tmp/config/spacefx-config.json" build_artifact --disable_log --ignore_error
171171
fi
172172

173173
# Found the artifact - parse the values
@@ -196,10 +196,11 @@ function download_artifact() {
196196
exit_with_error "Unable to find a registry for '${artifact_repo}:${artifact_tag}'"
197197
fi
198198

199-
info_log "Found '${fileName}' in registry '${artifact_registry}' (${artifact_registry}/${artifact_repo}:${artifact_tag})"
199+
info_log "Found '${fileName}' in registry '${artifact_registry}'"
200+
201+
get_image_name --registry "${artifact_registry}" --repo "${artifact_repo}" --result artifact_full_image_name
200202

201203
if [[ "${static_artifact}" == "false" ]]; then
202-
get_image_name --registry "${artifact_registry}" --repo "${artifact_repo}" --result artifact_full_image_name
203204

204205
run_a_script "regctl manifest get ${artifact_full_image_name}:${artifact_tag} --format '{{json .}}'" artifact_manifest
205206

@@ -212,14 +213,12 @@ function download_artifact() {
212213
debug_log "Found manifest for architecture '${ARCHITECTURE}'."
213214
run_a_script "jq -r '.manifests[] | select(.artifactType == \"application/vnd.spacefx.${ARCHITECTURE}.buildartifact\") | .annotations.\"org.spacefx.artifact.directory\"' <<< \${artifact_manifest}" artifact_directory
214215
run_a_script "jq -r '.manifests[] | select(.artifactType == \"application/vnd.spacefx.${ARCHITECTURE}.buildartifact\") | .annotations.\"org.spacefx.artifact.hash\"' <<< \${artifact_manifest}" artifact_hash
215-
else
216-
artifact_full_image_name="${artifact_repo}/${artifact_repo}:${artifact_tag}"
217216
fi
218217

219218
info_log "Artifact: ${fileName}"
220-
info_log "Full Image Name: ${artifact_full_image_name}"
219+
info_log "Full Image Name: ${artifact_full_image_name}:${artifact_tag}"
221220
info_log "Directory: ${artifact_directory}"
222-
info_log "Hash: ${artifact_hash}"
221+
info_log "Remote Hash: ${artifact_hash}"
223222
info_log "Repository: ${artifact_repo}"
224223
info_log "Tag: ${artifact_tag}"
225224
info_log "Static Artifact: ${static_artifact}"
@@ -229,14 +228,18 @@ function download_artifact() {
229228

230229
info_log "Local Hash: ${local_artifact_hash}"
231230

232-
if [[ "${artifact_hash}" == "${local_artifact_hash}" ]]; then
231+
if [[ -n "${local_file_hash}" ]] && [[ "${artifact_hash}" == "${local_artifact_hash}" ]]; then
233232
info_log "Hash for '${SPACEFX_DIR}/${artifact_directory}/${fileName}' matches container registry hash ('${local_artifact_hash}' = '${artifact_hash}'). Nothing to do."
234233
return
235234
fi
236235

237-
info_log "Hash for '${SPACEFX_DIR}/${artifact_directory}/${fileName}' doesn't match container registry hash ('${local_artifact_hash}' <> '${artifact_hash}')."
238-
info_log "Downloading '${artifact_full_image_name}:${artifact_tag}' to '${SPACEFX_DIR}/${artifact_directory}/${fileName}'..."
236+
if [[ -z "${local_file_hash}" ]]; then
237+
info_log "Local hash for '${SPACEFX_DIR}/${artifact_directory}/${fileName} is empty."
238+
else
239+
info_log "Hash for '${SPACEFX_DIR}/${artifact_directory}/${fileName}' doesn't match container registry hash ('${local_artifact_hash}' <> '${artifact_hash}')."
240+
fi
239241

242+
info_log "Downloading '${artifact_full_image_name}:${artifact_tag}' to '${SPACEFX_DIR}/${artifact_directory}/${fileName}'..."
240243

241244
run_a_script "regctl artifact get ${artifact_full_image_name}:${artifact_tag} --output ${SPACEFX_DIR}/${artifact_directory} --filter-artifact-type application/vnd.spacefx.${ARCHITECTURE}.buildartifact"
242245
info_log "...successfully downloaded '${artifact_full_image_name}:${artifact_tag}' to '${SPACEFX_DIR}/${artifact_directory}/${fileName}'."

tests/dev_cluster.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ if [[ ! -f "${artifact_yaml}" ]]; then
176176
exit 1
177177
fi
178178

179+
echo "Checking for push-build-artifact-test.txt in /var/spacedev/tmp"
180+
artifact="/var/spacedev/tmp/push-build-artifact-test.txt"
181+
if [[ ! -f "${artifact}" ]]; then
182+
echo "push-build-artifact-test.txt not found in /var/spacedev/tmp. Please ensure the artifact exists and is configured correctly within artifacts.yaml."
183+
exit 1
184+
fi
185+
179186
echo ""
180187
echo ""
181188
echo ""

0 commit comments

Comments
 (0)