|
4 | 4 | [ "$DEBUG" == 'true' ] && set -x |
5 | 5 | set -e |
6 | 6 |
|
| 7 | +ECR_ACCOUNT="740797759474.dkr.ecr.us-west-2.amazonaws.com" |
| 8 | +ECR_REPO_URL="$ECR_ACCOUNT/opensearch-migrations/base-images" |
| 9 | + |
| 10 | +# Check load-images-to-ecr.sh for loading needed images into ECR |
| 11 | +pull_from_ecr() { |
| 12 | + local docker_image_tag=$1 |
| 13 | + local ecr_image_tag=$2 |
| 14 | + |
| 15 | + echo "Checking for local Docker image: $docker_image_tag" |
| 16 | + |
| 17 | + # Check if the image exists locally |
| 18 | + if docker image inspect $docker_image_tag >/dev/null 2>&1; then |
| 19 | + echo "Docker image already exists locally." |
| 20 | + else |
| 21 | + echo "Attempting to pull Docker image from ECR: $docker_image_tag" |
| 22 | + |
| 23 | + docker pull "$ECR_REPO_URL:$ecr_image_tag" |
| 24 | + docker tag "$ECR_REPO_URL:$ecr_image_tag" "$docker_image_tag" |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +pull_docker_image() { |
| 29 | + local image_name=$1 |
| 30 | + |
| 31 | + echo "Checking for Docker image: $image_name" |
| 32 | + |
| 33 | + # Check if the image exists locally |
| 34 | + if docker image inspect $image_name >/dev/null 2>&1; then |
| 35 | + echo "Docker image already exists locally." |
| 36 | + else |
| 37 | + echo "Attempting to pull Docker image: $image_name" |
| 38 | + |
| 39 | + # Try to pull the Docker image |
| 40 | + if docker pull $image_name; then |
| 41 | + echo "Docker image pulled successfully." |
| 42 | + else |
| 43 | + echo "Failed to pull Docker image. Aborting unit tests." |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + fi |
| 47 | +} |
7 | 48 |
|
8 | 49 | prepare_jest_coverage_report() { |
9 | 50 | local component_name=$1 |
@@ -31,33 +72,36 @@ run_python_tests() { |
31 | 72 | echo "cd $component_path" |
32 | 73 | cd "$component_path" |
33 | 74 |
|
34 | | - python3 -m venv .venv |
35 | | - source .venv/bin/activate |
36 | | - pip install -r requirements.txt |
37 | | - pip install -r dev-requirements.txt |
38 | | - python3 -m coverage run -m unittest |
39 | | - python3 -m coverage xml --omit "*/tests/*" |
| 75 | + echo "python3 -m pip install --upgrade pipenv" |
| 76 | + python3 -m pip install --upgrade pipenv |
| 77 | + echo "pipenv install --deploy --dev" |
| 78 | + pipenv install --deploy --dev |
| 79 | + echo "pipenv run python -m coverage run -m pytest" |
| 80 | + pipenv run python -m coverage run -m pytest |
| 81 | + |
| 82 | + echo "pipenv run python -m coverage xml --omit '*/tests/*'" |
| 83 | + pipenv run python -m coverage xml --omit "*/tests/*" |
| 84 | + |
40 | 85 | # The coverage module uses absolutes paths in its coverage output. To avoid dependencies of tools (such as SonarQube) |
41 | 86 | # on different absolute paths for source directories, this substitution is used to convert each absolute source |
42 | 87 | # directory path to the corresponding project relative path. The $source_dir holds the absolute path for source |
43 | 88 | # directory. |
44 | 89 | sed -i -e "s,<source>$source_dir,<source>source,g" coverage.xml |
45 | | - deactivate |
46 | | - rm -rf .venv |
47 | 90 | } |
48 | 91 |
|
49 | 92 |
|
50 | 93 | run_gradle_tests() { |
51 | 94 | local component_path=$1 |
52 | 95 | local component_name=$2 |
| 96 | + local gradle_arguments=$3 |
53 | 97 |
|
54 | 98 | echo "------------------------------------------------------------------------------" |
55 | 99 | echo "[Test] Run unit test with coverage for $component_name" |
56 | 100 | echo "------------------------------------------------------------------------------" |
57 | 101 | echo "cd $component_path" |
58 | 102 | cd "$component_path" |
59 | 103 |
|
60 | | - ./gradlew build copyDependencies jacocoTestReport |
| 104 | + ./gradlew $gradle_arguments |
61 | 105 | } |
62 | 106 |
|
63 | 107 | run_npm_tests() { |
@@ -96,18 +140,50 @@ check_test_failure() { |
96 | 140 | fi |
97 | 141 | } |
98 | 142 |
|
| 143 | +if aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin "$ECR_ACCOUNT" && pull_from_ecr "amazonlinux:2023" "amazonlinux-2023"; then |
| 144 | + echo "Successful accessed ECR account $ECR_ACCOUNT and pulled amazonlinux-2023, pulling remaining base images from here..." |
| 145 | + pull_from_ecr "opensearchproject/opensearch:1.3.16" "opensearch-1.3.16" |
| 146 | + pull_from_ecr "opensearchproject/opensearch:2.14.0" "opensearch-2.14.0" |
| 147 | + pull_from_ecr "docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2" "elasticsearch-oss-7.10.2" |
| 148 | + pull_from_ecr "docker.elastic.co/elasticsearch/elasticsearch:7.17.22" "elasticsearch-7.17.22" |
| 149 | + pull_from_ecr "docker.elastic.co/elasticsearch/elasticsearch:6.8.23" "elasticsearch-6.8.23" |
| 150 | + pull_from_ecr "httpd:alpine" "httpd-alpine" |
| 151 | + pull_from_ecr "alpine:3.16" "alpine-3.16" |
| 152 | + pull_from_ecr "confluentinc/cp-kafka:7.5.0" "cp-kafka-7.5.0" |
| 153 | + pull_from_ecr "ghcr.io/shopify/toxiproxy:latest" "toxiproxy-latest" |
| 154 | +else |
| 155 | + echo "Failed to access $ECR_ACCOUNT or pull image from this ECR, will not pull base images from this ECR" |
| 156 | + # com.rfs.framework.SearchClusterContainer Images |
| 157 | + pull_docker_image "docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2" |
| 158 | + pull_docker_image "docker.elastic.co/elasticsearch/elasticsearch:7.17.22" |
| 159 | + pull_docker_image "docker.elastic.co/elasticsearch/elasticsearch:6.8.23" |
| 160 | + pull_docker_image "opensearchproject/opensearch:1.3.16" |
| 161 | + pull_docker_image "opensearchproject/opensearch:2.14.0" |
| 162 | + # org.opensearch.migrations.trafficcapture.proxyserver.testcontainers.HttpdContainerTestBase |
| 163 | + pull_docker_image "httpd:alpine" |
| 164 | + pull_docker_image "alpine:3.16" |
| 165 | + # org.opensearch.migrations.trafficcapture.proxyserver.testcontainers.KafkaContainerTestBase |
| 166 | + pull_docker_image "confluentinc/cp-kafka:7.5.0" |
| 167 | + # org.opensearch.migrations.trafficcapture.proxyserver.testcontainers.ToxiproxyContainerTestBase |
| 168 | + pull_docker_image "ghcr.io/shopify/toxiproxy:latest" |
| 169 | + # TrafficCapture/dockerSolution/src/main/docker/elasticsearchTestConsole/Dockerfile |
| 170 | + pull_docker_image "amazonlinux:2023" |
| 171 | +fi |
| 172 | + |
| 173 | +echo "Images pulled successfully. Continuing to unit tests." |
| 174 | + |
99 | 175 | # Run unit tests |
100 | 176 | echo "Running unit tests" |
101 | 177 |
|
102 | 178 | # Get reference for source folder |
103 | 179 | source_dir="$(cd $PWD/../source; pwd -P)" |
104 | 180 | coverage_reports_top_path=$source_dir/test/coverage-reports |
105 | 181 |
|
106 | | -run_gradle_tests "$source_dir/opensearch-migrations/TrafficCapture" "TrafficCapture" |
107 | | -check_test_failure "TrafficCapture" |
| 182 | +run_gradle_tests "$source_dir/opensearch-migrations" "opensearch-migrations" "build copyDependencies mergeJacocoReports -x spotlessCheck" |
| 183 | +check_test_failure "opensearch-migrations" |
108 | 184 |
|
109 | | -run_python_tests "$source_dir/opensearch-migrations/FetchMigration/python" "FetchMigration" |
110 | | -check_test_failure "FetchMigration" |
| 185 | +run_python_tests "$source_dir/opensearch-migrations/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link" "ConsoleLibrary" |
| 186 | +check_test_failure "ConsoleLibrary" |
111 | 187 |
|
112 | 188 | # Test packages from /source directory |
113 | 189 | declare -a packages=( |
|
0 commit comments