Skip to content

Commit

Permalink
Prepare for new Koslo CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Mar 13, 2023
1 parent 8a32e2b commit 883a9fe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 54 deletions.
6 changes: 3 additions & 3 deletions build_test_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exit_non_zero_unless_installed docker
exit_non_zero_unless_installed docker-compose
exit_non_zero_unless_installed jq
remove_old_images
on_ci_kosli_declare_pipeline
on_ci_kosli_create_flow
build_tagged_images "$@"
exit_zero_if_build_only "$@"
remove_zombie_containers
Expand All @@ -36,9 +36,9 @@ create_test_data_manifests_file
server_up_healthy_and_clean
client_up_healthy_and_clean "$@"
on_ci_publish_tagged_images
on_ci_kosli_log_artifact
on_ci_kosli_report_artifact
test_in_containers "$@"
on_ci_kosli_log_evidence
on_ci_kosli_report_evidence
containers_down

# Return non-zero for non-compliant artifact
Expand Down
99 changes: 48 additions & 51 deletions sh/kosli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@
# ROOT_DIR must be set

export KOSLI_OWNER=cyber-dojo
export KOSLI_PIPELINE=runner
export KOSLI_FLOW=runner

readonly KOSLI_HOST_STAGING=https://staging.app.kosli.com
readonly KOSLI_HOST_PRODUCTION=https://app.kosli.com

# - - - - - - - - - - - - - - - - - - -
kosli_declare_pipeline()
kosli_create_flow()
{
local -r hostname="${1}"

kosli pipeline declare \
kosli create flow "${KOSLI_FLOW}" \
--description "Test runner" \
--visibility public \
--host "${hostname}" \
--template artifact,branch-coverage \
--host "${hostname}"
--visibility public
}

# - - - - - - - - - - - - - - - - - - -
kosli_log_artifact()
kosli_report_artifact()
{
local -r hostname="${1}"

cd "$(root_dir)"
pushd "$(root_dir)"

kosli pipeline artifact report creation \
"$(artifact_name)" \
kosli report artifact "$(artifact_name)" \
--artifact-type docker \
--host "${hostname}"

popd
}

# - - - - - - - - - - - - - - - - - - -
kosli_log_evidence()
kosli_report_evidence()
{
local -r hostname="${1}"

kosli pipeline artifact report evidence generic $(artifact_name) \
kosli report evidence artifact generic $(artifact_name) \
--artifact-type docker \
--description "server & client branch-coverage reports" \
--evidence-type branch-coverage \
Expand Down Expand Up @@ -68,44 +69,12 @@ on_ci()
[ -n "${CI:-}" ]
}

# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_declare_pipeline()
{
if ! on_ci ; then
return
fi
kosli_declare_pipeline "${KOSLI_HOST_STAGING}"
kosli_declare_pipeline "${KOSLI_HOST_PRODUCTION}"
}

# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_log_artifact()
{
if ! on_ci ; then
return
fi
kosli_log_artifact "${KOSLI_HOST_STAGING}"
kosli_log_artifact "${KOSLI_HOST_PRODUCTION}"
}

# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_log_evidence()
{
if ! on_ci ; then
return
fi
write_evidence_json
kosli_log_evidence "${KOSLI_HOST_STAGING}"
kosli_log_evidence "${KOSLI_HOST_PRODUCTION}"
}

# - - - - - - - - - - - - - - - - - - -
kosli_assert_artifact()
{
local -r hostname="${1}"

kosli assert artifact \
"$(artifact_name)" \
kosli assert artifact "$(artifact_name)" \
--artifact-type docker \
--host "${hostname}"
}
Expand All @@ -120,16 +89,16 @@ kosli_expect_deployment()
# and the image must be present to get its sha256 fingerprint.
docker pull "$(artifact_name)"

kosli expect deployment \
"$(artifact_name)" \
kosli expect deployment "$(artifact_name)" \
--artifact-type docker \
--description "Deployed to ${environment} in Github Actions pipeline" \
--environment "${environment}" \
--host "${hostname}"
}

# - - - - - - - - - - - - - - - - - - -
artifact_name() {
artifact_name()
{
source "$(root_dir)/sh/echo_versioner_env_vars.sh"
export $(echo_versioner_env_vars)
echo "${CYBER_DOJO_RUNNER_IMAGE}:${CYBER_DOJO_RUNNER_TAG}"
Expand All @@ -143,12 +112,40 @@ root_dir()
git rev-parse --show-toplevel
}

# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_create_flow()
{
if on_ci; then
kosli_create_flow "${KOSLI_HOST_STAGING}"
kosli_create_flow "${KOSLI_HOST_PRODUCTION}"
fi
}

# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_report_artifact()
{
if on_ci; then
kosli_report_artifact "${KOSLI_HOST_STAGING}"
kosli_report_artifact "${KOSLI_HOST_PRODUCTION}"
fi
}

# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_report_evidence()
{
if on_ci; then
write_evidence_json
kosli_report_evidence "${KOSLI_HOST_STAGING}"
kosli_report_evidence "${KOSLI_HOST_PRODUCTION}"
fi
}


# - - - - - - - - - - - - - - - - - - -
on_ci_kosli_assert_artifact()
{
if ! on_ci ; then
return
if on_ci; then
kosli_assert_artifact "${KOSLI_HOST_STAGING}"
kosli_assert_artifact "${KOSLI_HOST_PRODUCTION}"
fi
kosli_assert_artifact "${KOSLI_HOST_STAGING}"
kosli_assert_artifact "${KOSLI_HOST_PRODUCTION}"
}

0 comments on commit 883a9fe

Please sign in to comment.