From 98c3f0fd89155ee038e432422573f7cfa6941d6c Mon Sep 17 00:00:00 2001 From: Benjamin Pelletier Date: Fri, 20 Oct 2023 16:21:11 -0700 Subject: [PATCH] [tooling] Use `make image` to build image (#273) * Use `make image` to build image * Make linter happy and clean up some scripts * Add explanatory content in placeholder file --- Makefile | 8 +++---- monitoring/.gitignore | 5 ++++- monitoring/Makefile | 4 ++-- monitoring/atproxy/run_locally.sh | 10 +++++---- monitoring/build.sh | 1 + monitoring/mock_uss/run_locally_msgsigning.sh | 21 ++++++++++++++----- .../mock_uss/run_locally_test_geoawareness.sh | 19 ++++++++++++----- monitoring/mock_uss/start_all_local_mocks.sh | 10 ++++----- monitoring/prober/README.md | 2 +- monitoring/prober/run_locally.sh | 12 ++++------- .../bin/generate_rid_test_definition.sh | 8 +++---- monitoring/uss_qualifier/bin/run.sh | 8 +++---- monitoring/uss_qualifier/run_locally.sh | 8 +++---- .../scripts/format_test_documentation.sh | 8 +++---- .../scripts/format_test_suite_docs.sh | 8 +++---- .../uss_qualifier/scripts/run_unit_tests.sh | 8 +++---- .../scripts/validate_test_definitions.sh | 8 +++---- schemas/manage_type_schemas.sh | 7 +++---- 18 files changed, 88 insertions(+), 67 deletions(-) diff --git a/Makefile b/Makefile index 26453f6cda..6368fad942 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ validate-uss-qualifier-docs: .PHONY: shell-lint shell-lint: - find . -name '*.sh' | grep -v '^./interfaces' | xargs docker run --rm -v "$(CURDIR):/monitoring" -w /monitoring koalaman/shellcheck + find . -name '*.sh' ! -path "./interfaces/*" | xargs docker run --rm -v "$(CURDIR):/monitoring" -w /monitoring koalaman/shellcheck .PHONY: json-schema json-schema: @@ -50,9 +50,9 @@ json-schema-lint: .PHONY: hygiene-tests hygiene-tests: check-hygiene -.PHONY: build-monitoring -build-monitoring: - cd monitoring && make build +.PHONY: image +image: + cd monitoring && make image tag: scripts/tag.sh $(UPSTREAM_OWNER)/monitoring/v$(VERSION) diff --git a/monitoring/.gitignore b/monitoring/.gitignore index 9ed27cd019..73f2ddb3e4 100644 --- a/monitoring/.gitignore +++ b/monitoring/.gitignore @@ -1,4 +1,7 @@ report.json config.json run_locally_list.txt -run_locally_scd_deploy_others.sh \ No newline at end of file +run_locally_scd_deploy_others.sh + +# Make target placeholders +image diff --git a/monitoring/Makefile b/monitoring/Makefile index 8df32f6bf3..663832e369 100644 --- a/monitoring/Makefile +++ b/monitoring/Makefile @@ -6,8 +6,8 @@ lint: format: cd uss_qualifier && make format -.PHONY: build -build: +image: ../requirements.txt $(shell find . -type f ! -path "*/output/*" ! -name image) $(shell find ../interfaces -type f) + # Building image due to changes in the following files: $? ./build.sh .PHONY: test diff --git a/monitoring/atproxy/run_locally.sh b/monitoring/atproxy/run_locally.sh index eb8262fe34..5f47c622e8 100755 --- a/monitoring/atproxy/run_locally.sh +++ b/monitoring/atproxy/run_locally.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -eo pipefail + # Find and change to repo root directory OS=$(uname) if [[ "$OS" == "Darwin" ]]; then @@ -10,10 +12,10 @@ else fi cd "${BASEDIR}/../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) CLIENT_BASIC_AUTH="local_client:local_client" PUBLIC_KEY="/var/test-certs/auth2.pem" diff --git a/monitoring/build.sh b/monitoring/build.sh index e767e69fc9..3aa79cd446 100755 --- a/monitoring/build.sh +++ b/monitoring/build.sh @@ -21,3 +21,4 @@ docker image build \ --build-arg commit_hash="$(git rev-parse HEAD)" \ . \ || exit 1 +echo "File created by monitoring/build.sh to keep track of the latest build run date time." > monitoring/image diff --git a/monitoring/mock_uss/run_locally_msgsigning.sh b/monitoring/mock_uss/run_locally_msgsigning.sh index 742fef289d..ae96a2135b 100755 --- a/monitoring/mock_uss/run_locally_msgsigning.sh +++ b/monitoring/mock_uss/run_locally_msgsigning.sh @@ -1,10 +1,21 @@ #!/usr/bin/env bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - "${SCRIPT_DIR}/../build.sh" || exit 1 - export DO_NOT_BUILD_MONITORING=true +set -eo pipefail + +# Find and change to repo root directory +OS=$(uname) +if [[ "$OS" == "Darwin" ]]; then + # OSX uses BSD readlink + BASEDIR="$(dirname "$0")" +else + BASEDIR=$(readlink -e "$(dirname "$0")") fi +cd "${BASEDIR}/../.." || exit 1 + +( +cd monitoring || exit 1 +make image +) AUTH="DummyOAuth(http://host.docker.internal:8085/token,uss1)" DSS="http://host.docker.internal:8082" @@ -32,7 +43,7 @@ docker run ${docker_args} --name ${container_name} \ -e MOCK_USS_BASE_URL="${BASE_URL}" \ -e MOCK_USS_SERVICES="scdsc,msgsigning" \ -p ${PORT}:5000 \ - -v "${SCRIPT_DIR}/../../build/test-certs:/var/test-certs:ro" \ + -v "$(pwd)/build/test-certs:/var/test-certs:ro" \ "$@" \ interuss/monitoring \ mock_uss/start.sh diff --git a/monitoring/mock_uss/run_locally_test_geoawareness.sh b/monitoring/mock_uss/run_locally_test_geoawareness.sh index d2c6f98168..ba11692bfd 100755 --- a/monitoring/mock_uss/run_locally_test_geoawareness.sh +++ b/monitoring/mock_uss/run_locally_test_geoawareness.sh @@ -1,10 +1,19 @@ #!/usr/bin/env bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - "${SCRIPT_DIR}/../build.sh" || exit 1 - export DO_NOT_BUILD_MONITORING=true +# Find and change to repo root directory +OS=$(uname) +if [[ "$OS" == "Darwin" ]]; then + # OSX uses BSD readlink + BASEDIR="$(dirname "$0")" +else + BASEDIR=$(readlink -e "$(dirname "$0")") fi +cd "${BASEDIR}/../.." || exit 1 + +( +cd monitoring || exit 1 +make image +) PUBLIC_KEY="/var/test-certs/auth2.pem" container_name="mock_uss_geoawareness_test" @@ -27,7 +36,7 @@ docker run ${docker_args} --rm --name ${container_name} \ -e MOCK_USS_TOKEN_AUDIENCE="${AUD}" \ -e MOCK_USS_SERVICES="geoawareness" \ -p ${PORT}:5000 \ - -v "${SCRIPT_DIR}/../../build/test-certs:/var/test-certs:ro" \ + -v "$(pwd)/build/test-certs:/var/test-certs:ro" \ "$@" \ interuss/monitoring \ ${docker_command} diff --git a/monitoring/mock_uss/start_all_local_mocks.sh b/monitoring/mock_uss/start_all_local_mocks.sh index 9f7776b812..8fb4e0d4df 100755 --- a/monitoring/mock_uss/start_all_local_mocks.sh +++ b/monitoring/mock_uss/start_all_local_mocks.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eo pipefail @@ -12,10 +12,10 @@ else fi cd "${BASEDIR}/../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - ./monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) ./monitoring/mock_uss/run_locally.sh up -d diff --git a/monitoring/prober/README.md b/monitoring/prober/README.md index f4568f8c8e..61468e0b36 100644 --- a/monitoring/prober/README.md +++ b/monitoring/prober/README.md @@ -36,7 +36,7 @@ First, build the monitoring image: (from the repo root) ```shell script -monitoring/build.sh +make image ``` ...then run prober: diff --git a/monitoring/prober/run_locally.sh b/monitoring/prober/run_locally.sh index 2babedc80f..7d4fda0b03 100755 --- a/monitoring/prober/run_locally.sh +++ b/monitoring/prober/run_locally.sh @@ -13,10 +13,10 @@ else fi cd "${BASEDIR}/../.." || exit 1 -if [ -z "$DO_NOT_BUILD_MONITORING" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) CORE_SERVICE_CONTAINER="local_infra-dss-1" OAUTH_CONTAINER="local_infra-oauth-1" @@ -26,10 +26,6 @@ for container_name in "${localhost_containers[@]}"; do if [ "$( docker container inspect -f '{{.State.Status}}' "$container_name" )" == "running" ]; then echo "$container_name available!" else - echo '#########################################################################' - echo '## Prerequisite to run this command is: ##' - echo '## Local DSS instance + Dummy OAuth server (/build/dev/run_locally.sh) ##' - echo '#########################################################################' echo "Error: $container_name not running. Execute 'build/dev/run_locally.sh up' before running monitoring/prober/run_locally.sh"; exit 1; fi diff --git a/monitoring/uss_qualifier/bin/generate_rid_test_definition.sh b/monitoring/uss_qualifier/bin/generate_rid_test_definition.sh index 33e00a296c..c0c4778120 100755 --- a/monitoring/uss_qualifier/bin/generate_rid_test_definition.sh +++ b/monitoring/uss_qualifier/bin/generate_rid_test_definition.sh @@ -12,10 +12,10 @@ else fi cd "${BASEDIR}/../../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) CONFIG_LOCATION="monitoring/uss_qualifier/config_run_locally.json" CONFIG='--config config_run_locally.json' diff --git a/monitoring/uss_qualifier/bin/run.sh b/monitoring/uss_qualifier/bin/run.sh index 92872cf1d9..c514c5059b 100755 --- a/monitoring/uss_qualifier/bin/run.sh +++ b/monitoring/uss_qualifier/bin/run.sh @@ -30,10 +30,10 @@ AUTH="${2:-NoAuth()}" QUALIFIER_OPTIONS="--auth $AUTH --config /config.json --report output/report.json" -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - "$(pwd)"/monitoring/build.sh - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) if [ "$CI" == "true" ]; then docker_args="--add-host host.docker.internal:host-gateway" # Required to reach other containers in Ubuntu (used for Github Actions) diff --git a/monitoring/uss_qualifier/run_locally.sh b/monitoring/uss_qualifier/run_locally.sh index ad157b6d86..4ac41fb7a5 100755 --- a/monitoring/uss_qualifier/run_locally.sh +++ b/monitoring/uss_qualifier/run_locally.sh @@ -12,10 +12,10 @@ else fi cd "${BASEDIR}/../.." || exit 1 -if [ -z "$DO_NOT_BUILD_MONITORING" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) CONFIG_NAME="${1:-ALL}" diff --git a/monitoring/uss_qualifier/scripts/format_test_documentation.sh b/monitoring/uss_qualifier/scripts/format_test_documentation.sh index 189f72856a..552f30b4e5 100755 --- a/monitoring/uss_qualifier/scripts/format_test_documentation.sh +++ b/monitoring/uss_qualifier/scripts/format_test_documentation.sh @@ -13,10 +13,10 @@ else fi cd "${BASEDIR}/../../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) # shellcheck disable=SC2086 docker run --name test_documentation_formatter \ diff --git a/monitoring/uss_qualifier/scripts/format_test_suite_docs.sh b/monitoring/uss_qualifier/scripts/format_test_suite_docs.sh index 22c421155d..9e0adfd073 100755 --- a/monitoring/uss_qualifier/scripts/format_test_suite_docs.sh +++ b/monitoring/uss_qualifier/scripts/format_test_suite_docs.sh @@ -13,10 +13,10 @@ else fi cd "${BASEDIR}/../../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) # shellcheck disable=SC2086 docker run --name test_suite_docs_formatter \ diff --git a/monitoring/uss_qualifier/scripts/run_unit_tests.sh b/monitoring/uss_qualifier/scripts/run_unit_tests.sh index 9db531c10a..6aba675a0b 100755 --- a/monitoring/uss_qualifier/scripts/run_unit_tests.sh +++ b/monitoring/uss_qualifier/scripts/run_unit_tests.sh @@ -13,10 +13,10 @@ else fi cd "${BASEDIR}/../../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) # shellcheck disable=SC2086 docker run --name uss_qualifier_unit_test \ diff --git a/monitoring/uss_qualifier/scripts/validate_test_definitions.sh b/monitoring/uss_qualifier/scripts/validate_test_definitions.sh index a39c8a1cc2..dfdb99a042 100755 --- a/monitoring/uss_qualifier/scripts/validate_test_definitions.sh +++ b/monitoring/uss_qualifier/scripts/validate_test_definitions.sh @@ -13,10 +13,10 @@ else fi cd "${BASEDIR}/../../.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +( +cd monitoring || exit 1 +make image +) # shellcheck disable=SC2086 docker run --name test_definition_validator \ diff --git a/schemas/manage_type_schemas.sh b/schemas/manage_type_schemas.sh index 3d1eae8cf2..aa3e296bf5 100755 --- a/schemas/manage_type_schemas.sh +++ b/schemas/manage_type_schemas.sh @@ -13,10 +13,9 @@ else fi cd "${BASEDIR}/.." || exit 1 -if [ -z "${DO_NOT_BUILD_MONITORING}" ]; then - monitoring/build.sh || exit 1 - export DO_NOT_BUILD_MONITORING=true -fi +cd monitoring +make image +cd .. action=${1:?The action must be specified as --check or --generate}