diff --git a/.devcontainer/artifacts.yaml b/.devcontainer/artifacts.yaml index 1d5ae76..a3ff3b0 100644 --- a/.devcontainer/artifacts.yaml +++ b/.devcontainer/artifacts.yaml @@ -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 \ No newline at end of file diff --git a/.devcontainer/test-feature/devcontainer.json b/.devcontainer/test-feature/devcontainer.json index c2638e7..2fccb30 100644 --- a/.devcontainer/test-feature/devcontainer.json +++ b/.devcontainer/test-feature/devcontainer.json @@ -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": { diff --git a/build/push_build_artifact.sh b/build/push_build_artifact.sh index 7102fb4..18278b9 100755 --- a/build/push_build_artifact.sh +++ b/build/push_build_artifact.sh @@ -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 @@ -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 diff --git a/modules/m_60_container_registries.sh b/modules/m_60_container_registries.sh index d697d0f..356e181 100755 --- a/modules/m_60_container_registries.sh +++ b/modules/m_60_container_registries.sh @@ -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 --pass , or use the config login_username_file and login_password_file configuration options" fi diff --git a/scripts/stage/stage_build_artifact.sh b/scripts/stage/stage_build_artifact.sh index 93bad87..d5ddaa1 100644 --- a/scripts/stage/stage_build_artifact.sh +++ b/scripts/stage/stage_build_artifact.sh @@ -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 @@ -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 @@ -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}" @@ -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}'." diff --git a/tests/dev_cluster.sh b/tests/dev_cluster.sh index 8343ada..633174c 100755 --- a/tests/dev_cluster.sh +++ b/tests/dev_cluster.sh @@ -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 ""