Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extraBuildArtifact staging and push fix #115

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .devcontainer/artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ config:
pull_enabled: true
login_enabled: false
extraBuildArtifacts:
- file: testartifact.txt
directory: tmp/test
repository: test
tag: 0.11.0
- file: push-build-artifact-test.txt
directory: tmp
repository: buildartifacts/txt/push-build-artifact-test
tag: 0.11.0-nightly

3 changes: 2 additions & 1 deletion .devcontainer/test-feature/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"app_name": "spacesdk-setup",
"app_type": "none",
"extract_setup_files": "false",
"addl_config_yamls":"/workspaces/azure-orbital-space-sdk-setup/.devcontainer/artifacts.yaml"
"addl_config_yamls":"/workspaces/azure-orbital-space-sdk-setup/.devcontainer/artifacts.yaml",
"download_artifacts": "push-build-artifact-test.txt"
}
},
"hostRequirements": {
Expand Down
25 changes: 18 additions & 7 deletions build/push_build_artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function check_for_preset_config() {

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

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

# Check if we have a tag suffix from our config file
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
run_a_script "basename ${ARTIFACT}" fileName --disable_log

if [[ -n "${tag_suffix}" ]]; then
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}${tag_suffix}"
DEST_SPACEFX_TAG="${SPACEFX_VERSION}${tag_suffix}"
fi
# Look in extraBuildArtifacts to see if a specfic tag is required
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

# Found the in extraBuildArtifacts, confirmed static artifact
if [[ -n "${build_artifact}" ]]; then
info_log "..found '${fileName}' in build artifacts."
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}"
DEST_SPACEFX_TAG="${ARTIFACT_VERSION}"
else
# artifact is not static, check if we have a tag suffix from our config file
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

if [[ -n "${tag_suffix}" ]]; then
DEST_ARTIFACT_TAG="${ARTIFACT_VERSION}${tag_suffix}"
DEST_SPACEFX_TAG="${SPACEFX_VERSION}${tag_suffix}"
fi
fi

write_parameter_to_log DEST_ARTIFACT_TAG
write_parameter_to_log DEST_SPACEFX_TAG
Expand Down
4 changes: 4 additions & 0 deletions modules/m_60_container_registries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,12 @@ function find_registry_for_image(){
login_to_container_registry --container_registry "${container_registry}" --container_registry_username_file "${login_username_file}" --container_registry_password_file "${login_password_file}"
fi

debug_log "Running 'regctl image manifest ${container_registry}/${_find_registry_for_image_repo}'"
run_a_script "regctl image manifest ${container_registry}/${_find_registry_for_image_repo}" _find_registry_for_image_result --ignore_error --disable_log
debug_log "_find_registry_for_image_result:"
debug_log "${_find_registry_for_image_result}"


if [[ "${_find_registry_for_image_result}" == *"unauthorized"* ]]; then
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"
fi
Expand Down
25 changes: 14 additions & 11 deletions scripts/stage/stage_build_artifact.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ function download_artifact() {
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

if [[ -z "${build_artifact}" ]]; then
# We don't have the artifact in the main build artifacts. Look in extraArtifacts
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
# We don't have the artifact in the main build artifacts. Look in extraBuildArtifacts
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
fi

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

info_log "Found '${fileName}' in registry '${artifact_registry}' (${artifact_registry}/${artifact_repo}:${artifact_tag})"
info_log "Found '${fileName}' in registry '${artifact_registry}'"

get_image_name --registry "${artifact_registry}" --repo "${artifact_repo}" --result artifact_full_image_name

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

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

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

info_log "Artifact: ${fileName}"
info_log "Full Image Name: ${artifact_full_image_name}"
info_log "Full Image Name: ${artifact_full_image_name}:${artifact_tag}"
info_log "Directory: ${artifact_directory}"
info_log "Hash: ${artifact_hash}"
info_log "Remote Hash: ${artifact_hash}"
info_log "Repository: ${artifact_repo}"
info_log "Tag: ${artifact_tag}"
info_log "Static Artifact: ${static_artifact}"
Expand All @@ -229,14 +228,18 @@ function download_artifact() {

info_log "Local Hash: ${local_artifact_hash}"

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

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

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

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"
info_log "...successfully downloaded '${artifact_full_image_name}:${artifact_tag}' to '${SPACEFX_DIR}/${artifact_directory}/${fileName}'."
Expand Down
7 changes: 7 additions & 0 deletions tests/dev_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ if [[ ! -f "${artifact_yaml}" ]]; then
exit 1
fi

echo "Checking for push-build-artifact-test.txt in /var/spacedev/tmp"
artifact="/var/spacedev/tmp/push-build-artifact-test.txt"
if [[ ! -f "${artifact}" ]]; then
echo "push-build-artifact-test.txt not found in /var/spacedev/tmp. Please ensure the artifact exists and is configured correctly within artifacts.yaml."
exit 1
fi

echo ""
echo ""
echo ""
Expand Down
Loading