From bf42019d0a4a3b0b55e0040d271c92b7e6944009 Mon Sep 17 00:00:00 2001 From: josiahzimmerman-caci Date: Thu, 6 Feb 2025 23:12:42 +0000 Subject: [PATCH 1/2] enable server test 99% but allows to fail, force client on all PR, set sha for image, add more timeout on wait --- .gitlab-ci.yml | 118 +++++++++++++++++++++++++++++++----- Makefile | 69 +++++++++------------ scripts/rds-snapshot-app-db | 6 +- scripts/run-server-test | 9 ++- 4 files changed, 145 insertions(+), 57 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dcf1897da35..0a86b26efa1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,8 @@ variables: #Docker config DOCKER_AUTH_CONFIG: "{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD\"}}}" - DOCKER_APP_IMAGE: milmove01/transcom-docker:milmove-app + #hard code sha as newer version of debian is needed for pre-test + DOCKER_APP_IMAGE: milmove01/transcom-docker:milmove-app@sha256:ee774e9244afa2063bbbb7f9b973b17f1f5139366a1b7a676155df0b5268a7e1 DOCKER_BASE_IMAGE: milmove01/transcom-docker:base DOCKERHUB_USERNAME: DOCKERHUB_USERNAME DOCKERHUB_PASSWORD: DOCKERHUB_PASSWORD @@ -24,7 +25,7 @@ variables: #CIRCLE_TOKEN: "$GITLAB_API_TOKEN" # GitLab API token for querying pipelines CIRCLE_BUILD_NUM: "$CI_PIPELINE_ID" - GOPATH: "$CI_PROJECT_DIR/go" + GOPATH: "/home/transcom/go" #Go path on the app image GOLANGCI_LINT_CONCURRENCY: "4" GOLANGCI_LINT_VERBOSE: "-v" @@ -63,7 +64,7 @@ stages: #set safe directory and path .setup_milmove_env: &setup_milmove_env - git config --global --add safe.directory /builds/milmove/mymove - - export PATH=${PATH}:${GOPATH}/bin:~/transcom/mymove/builds/milmove/mymove:/builds/milmove/mymove/scripts + - export PATH=${PATH}:${GOPATH}/bin:~/transcom/mymove/builds/milmove/mymove:/builds/milmove/mymove/scripts:/builds/milmove/mymove/bin - export REACT_APP_ERROR_LOGGING=otel .announce_failure: &announce_failure @@ -389,6 +390,89 @@ pre_deps_golang: # - $GOPATH/pkg/mod # - /builds/milmove/mymove/bin # Ensure this path is correct and writable. # Optionally, you can define an after_script for cleanup or notifications. +golang_lint: + stage: pre_checks + interruptible: true + tags: + - $DOCKER_RUNNER_TAG + image: golangci/golangci-lint:latest # Refer to https://hub.docker.com/r/golangci/golangci-lint + script: + - golangci-lint run --print-issued-lines=false --out-format code-climate:gl-code-quality-report.json,line-number + artifacts: + reports: + codequality: gl-code-quality-report.json + paths: + - gl-code-quality-report.json + when: always + allow_failure: true + +# WIP but failing and will need to get back to see if this is a viable option for go test coverage +# golang_coverage: +# stage: pre_checks +# interruptible: true +# tags: +# - $DOCKER_RUNNER_TAG +# image: $DOCKER_APP_IMAGE +# services: +# - name: docker:dind +# alias: docker +# - name: $postgres +# - name: $redis +# before_script: +# - *setup_milmove_env +# variables: +# KUBERNETES_CPU_REQUEST: "4" +# KUBERNETES_MEMORY_REQUEST: "8Gi" +# KUBERNETES_MEMORY_LIMIT: "8Gi" +# DOCKER_HOST: "tcp://docker-backend.gitlab-runner.svc.cluster.local:2375" +# DOCKER_TLS_CERTDIR: "" +# APPLICATION: app +# # 8 since this runs on xlarge with 8 CPUs +# GOTEST_PARALLEL: 8 +# DB_PASSWORD: mysecretpassword +# DB_USER_LOW_PRIV: crud +# DB_PASSWORD_LOW_PRIV: mysecretpassword +# DB_USER: postgres +# DB_HOST: localhost +# DB_PORT_TEST: 5432 +# DB_PORT: 5432 +# DB_NAME: test_db +# DB_NAME_TEST: test_db +# DTOD_USE_MOCK: 'true' +# MIGRATION_MANIFEST: '/builds/milmove/mymove/migrations/app/migrations_manifest.txt' +# MIGRATION_PATH: 'file:///builds/milmove/mymove/migrations/app/schema;file:///builds/milmove/mymove/migrations/app/secure' +# EIA_KEY: db2522a43820268a41a802a16ae9fd26 # dummy key generated with openssl rand -hex 16 +# ENV: test +# ENVIRONMENT: test +# SERVER_REPORT: 1 +# COVERAGE: 1 +# SERVE_API_INTERNAL: 'true' +# OKTA_CUSTOMER_CLIENT_ID: 1q2w3e4r5t6y7u8i9o +# OKTA_ADMIN_CLIENT_ID: AQ1SW2DE3FR4G5 +# OKTA_OFFICE_CLIENT_ID: 9f9f9s8s90gig9 +# OKTA_API_KEY: notrealapikey8675309 +# OKTA_OFFICE_GROUP_ID: notrealgroupId +# OKTA_CUSTOMER_GROUP_ID: notrealcustomergroupId +# POSTGRES_DB: test_db #for postgres container +# POSTGRES_USER: postgres +# POSTGRES_PASSWORD: mysecretpassword +# POSTGRES_HOST_AUTH_METHOD: trust +# DPS_AUTH_SECRET_KEY: placeholder +# CSRF_AUTH_KEY: d096fd8529eefaa46497849d11d2ff2e979ddfaed1aff058524ada9bceadd67c +# IWS_RBS_ENABLED: 0 +# IWS_RBS_HOST: "pkict.dmdc.osd.mil" +# script: +# - go test ./... -coverprofile=coverage.txt -covermode count +# - go get github.com/boumenot/gocover-cobertura +# - go run github.com/boumenot/gocover-cobertura < coverage.txt > coverage.xml +# allow_failure: true +# after_script: +# - *announce_failure +# artifacts: +# reports: +# coverage_report: +# coverage_format: cobertura +# path: /builds/milmove/mymove/coverage.xml pre_deps_yarn: stage: pre_checks @@ -698,7 +782,7 @@ server_test: DB_PASSWORD_LOW_PRIV: mysecretpassword DB_USER: postgres DB_HOST: localhost - DB_PORT_TEST: 5433 + DB_PORT_TEST: 5432 DB_PORT: 5432 DB_NAME: test_db DB_NAME_TEST: test_db @@ -717,18 +801,22 @@ server_test: OKTA_API_KEY: notrealapikey8675309 OKTA_OFFICE_GROUP_ID: notrealgroupId OKTA_CUSTOMER_GROUP_ID: notrealcustomergroupId + POSTGRES_DB: test_db #for postgres container + POSTGRES_USER: postgres + POSTGRES_PASSWORD: mysecretpassword + POSTGRES_HOST_AUTH_METHOD: trust + DPS_AUTH_SECRET_KEY: placeholder + CSRF_AUTH_KEY: d096fd8529eefaa46497849d11d2ff2e979ddfaed1aff058524ada9bceadd67c + IWS_RBS_ENABLED: 0 + IWS_RBS_HOST: "pkict.dmdc.osd.mil" script: - - psql --version - for i in $(seq 1 5); do go mod download && break || s=$? && sleep 5; done; (exit $s) - scripts/check-generated-code go.sum - make bin/swagger - - echo "server test -- TODO Add steps need to potentially pass job id to file and persist" + - echo "server test -- build gotestsum and run scripts for report" - make -j 2 bin/milmove bin/gotestsum - make server_test for app - # - go install gotest.tools/gotestsum@latest - # - go mod tidy - #- bin/gotestsum --junitfile server_test_report.xml --format server_test - allow_failure: true + allow_failure: true #leaving true until 5 tests failing tests are working artifacts: paths: - /builds/milmove/mymove/bin/gotestsum @@ -738,8 +826,9 @@ server_test: junit: /builds/milmove/mymove/tmp/test-results/gotest/app/go-test-report.xml after_script: - *announce_failure - rules: - - *check_server_ignore_branch + # we want to make this run on every branch bc webhooks don't exist currently + # rules: + # - *check_server_ignore_branch server_test_coverage: stage: test @@ -806,8 +895,9 @@ client_test: - /builds/milmove/mymove/jest-junit-reports after_script: - *announce_failure - rules: - - *check_client_ignore_branch + # we want to make this run on every branch bc webhooks don't exist currently + # rules: + # - *check_client_ignore_branch client_test_coverage: stage: test diff --git a/Makefile b/Makefile index 6017c9b15f5..e2f29bde50e 100644 --- a/Makefile +++ b/Makefile @@ -32,15 +32,6 @@ DB_PORT_DEPLOYED_MIGRATIONS=5434 DB_PORT_DOCKER=5432 REDIS_PORT=6379 REDIS_PORT_DOCKER=6379 -ifdef CIRCLECI - DB_PORT_DEV=5432 - DB_PORT_TEST=5432 - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - LDFLAGS=-linkmode external -extldflags -static - endif -endif - ifdef GITLAB DB_PORT_DEV=5432 DB_PORT_TEST=5432 @@ -96,10 +87,10 @@ prereqs: ## Check that pre-requirements are installed, includes dependency scrip .PHONY: check_hosts check_hosts: .check_hosts.stamp ## Check that hosts are in the /etc/hosts file .check_hosts.stamp: scripts/check-hosts-file -ifndef CIRCLECI +ifndef GITLAB scripts/check-hosts-file else - @echo "Not checking hosts on CircleCI." + @echo "Not checking hosts on GitLab." endif touch .check_hosts.stamp @@ -112,10 +103,10 @@ check_go_version: .check_go_version.stamp ## Check that the correct Golang versi .PHONY: check_gopath check_gopath: .check_gopath.stamp ## Check that $GOPATH exists in $PATH .check_gopath.stamp: scripts/check-gopath go.sum # Make sure any go binaries rebuild if version possibly changes -ifndef CIRCLECI +ifndef GITLAB scripts/check-gopath else - @echo "No need to check go path on CircleCI." + @echo "No need to check go path on GitLab." endif touch .check_gopath.stamp @@ -344,7 +335,7 @@ swagger_generate: .swagger_build.stamp ## Check that the build files haven't bee # if API docs have changed, swagger regeneration will capture those # changes. On Circle CI, or if the user has set # SWAGGER_AUTOREBUILD, rebuild automatically without asking -ifdef CIRCLECI +ifdef GITLAB SWAGGER_AUTOREBUILD=1 endif SWAGGER_FILES = $(shell find swagger swagger-def -type f) @@ -476,16 +467,16 @@ server_test_coverage: db_test_reset db_test_migrate redis_reset server_test_cove .PHONY: redis_pull redis_pull: ## Pull redis image -ifdef CIRCLECI - @echo "Relying on CircleCI to setup redis." +ifdef GITLAB + @echo "Relying on GitLab to setup redis." else docker pull $(REDIS_DOCKER_CONTAINER_IMAGE) endif .PHONY: redis_destroy redis_destroy: ## Destroy Redis -ifdef CIRCLECI - @echo "Relying on CircleCI to setup redis." +ifdef GITLAB + @echo "Relying on GitLab to setup redis." else @echo "Destroying the ${REDIS_DOCKER_CONTAINER} docker redis container..." docker rm -f $(REDIS_DOCKER_CONTAINER) || echo "No Redis container" @@ -493,8 +484,8 @@ endif .PHONY: redis_run redis_run: redis_pull ## Run Redis -ifdef CIRCLECI - @echo "Relying on CircleCI to setup redis." +ifdef GITLAB + @echo "Relying on GitLab to setup redis." else @echo "Stopping the Redis brew service in case it's running..." brew services stop redis 2> /dev/null || true @@ -522,17 +513,17 @@ db_pull: ## Pull db image .PHONY: db_dev_destroy db_dev_destroy: ## Destroy Dev DB -ifndef CIRCLECI +ifndef GITLAB @echo "Destroying the ${DB_DOCKER_CONTAINER_DEV} docker database container..." docker rm -f $(DB_DOCKER_CONTAINER_DEV) || echo "No database container" rm -fr mnt/db_dev # delete mount directory if exists else - @echo "Relying on CircleCI's database setup to destroy the DB." + @echo "Relying on GitLab's database setup to destroy the DB." endif .PHONY: db_dev_start db_dev_start: ## Start Dev DB -ifndef CIRCLECI +ifndef GITLAB brew services stop postgresql 2> /dev/null || true @echo "Starting the ${DB_DOCKER_CONTAINER_DEV} docker database container..." # If running do nothing, if not running try to start, if can't start then run @@ -542,16 +533,16 @@ ifndef CIRCLECI -p $(DB_PORT_DEV):$(DB_PORT_DOCKER)\ $(DB_DOCKER_CONTAINER_IMAGE) else - @echo "Relying on CircleCI's database setup to start the DB." + @echo "Relying on GitLab's database setup to start the DB." endif .PHONY: db_dev_create db_dev_create: ## Create Dev DB -ifndef CIRCLECI +ifndef GITLAB @echo "Create the ${DB_NAME_DEV} database..." DB_NAME=postgres scripts/wait-for-db && DB_NAME=postgres psql-wrapper "CREATE DATABASE $(DB_NAME_DEV);" || true else - @echo "Relying on CircleCI's database setup to create the DB." + @echo "Relying on GitLab's database setup to create the DB." psql postgres://postgres:$(PGPASSWORD)@localhost:$(DB_PORT)?sslmode=disable -c 'CREATE DATABASE $(DB_NAME_DEV);' endif @@ -616,17 +607,17 @@ db_dev_bandwidth_up: check_app bin/generate-test-data db_dev_truncate ## Truncat .PHONY: db_deployed_migrations_destroy db_deployed_migrations_destroy: ## Destroy Deployed Migrations DB -ifndef CIRCLECI +ifndef GITLAB @echo "Destroying the ${DB_DOCKER_CONTAINER_DEPLOYED_MIGRATIONS} docker database container..." docker rm -f $(DB_DOCKER_CONTAINER_DEPLOYED_MIGRATIONS) || echo "No database container" rm -fr mnt/db_deployed_migrations # delete mount directory if exists else - @echo "Relying on CircleCI's database setup to destroy the DB." + @echo "Relying on GitLab's database setup to destroy the DB." endif .PHONY: db_deployed_migrations_start db_deployed_migrations_start: ## Start Deployed Migrations DB -ifndef CIRCLECI +ifndef GITLAB brew services stop postgresql 2> /dev/null || true endif @echo "Starting the ${DB_DOCKER_CONTAINER_DEPLOYED_MIGRATIONS} docker database container..." @@ -671,18 +662,18 @@ db_deployed_psql: ## Open PostgreSQL shell for Deployed Migrations DB .PHONY: db_test_destroy db_test_destroy: ## Destroy Test DB -ifndef CIRCLECI +ifndef GITLAB @echo "Destroying the ${DB_DOCKER_CONTAINER_TEST} docker database container..." docker rm -f $(DB_DOCKER_CONTAINER_TEST) || \ echo "No database container" else - @echo "Relying on CircleCI's database setup to destroy the DB." + @echo "Relying on GitLab's database setup to destroy the DB." psql postgres://postgres:$(PGPASSWORD)@localhost:$(DB_PORT_TEST)?sslmode=disable -c 'DROP DATABASE IF EXISTS $(DB_NAME_TEST);' endif .PHONY: db_test_start db_test_start: ## Start Test DB -ifndef CIRCLECI +ifndef GITLAB brew services stop postgresql 2> /dev/null || true @echo "Starting the ${DB_DOCKER_CONTAINER_TEST} docker database container..." docker start $(DB_DOCKER_CONTAINER_TEST) || \ @@ -694,17 +685,17 @@ ifndef CIRCLECI --mount type=tmpfs,destination=/var/lib/postgresql/data \ $(DB_DOCKER_CONTAINER_IMAGE) else - @echo "Relying on CircleCI's database setup to start the DB." + @echo "Relying on GitLab's database setup to start the DB." endif .PHONY: db_test_create db_test_create: ## Create Test DB -ifndef CIRCLECI +ifndef GITLAB @echo "Create the ${DB_NAME_TEST} database..." DB_NAME=postgres DB_PORT=$(DB_PORT_TEST) scripts/wait-for-db && \ createdb -p $(DB_PORT_TEST) -h $(DB_HOST) -U postgres $(DB_NAME_TEST) || true else - @echo "Relying on CircleCI's database setup to create the DB." + @echo "Relying on GitLab's database setup to create the DB." psql postgres://postgres:$(PGPASSWORD)@localhost:$(DB_PORT_TEST)?sslmode=disable -c 'CREATE DATABASE $(DB_NAME_TEST);' endif @@ -721,7 +712,7 @@ db_test_truncate: .PHONY: db_test_migrate_standalone db_test_migrate_standalone: bin/milmove ## Migrate Test DB directly -ifndef CIRCLECI +ifndef GITLAB @echo "Migrating the ${DB_NAME_TEST} database..." DB_DEBUG=0 DB_NAME=$(DB_NAME_TEST) DB_PORT=$(DB_PORT_TEST) bin/milmove migrate -p "file://migrations/${APPLICATION}/secure;file://migrations/${APPLICATION}/schema" -m "migrations/${APPLICATION}/migrations_manifest.txt" else @@ -1046,7 +1037,7 @@ run_prime_docker: ## Runs the docker that spins up the Prime API and data to tes # .PHONY: make_test -make_test: ## Test make targets not checked by CircleCI +make_test: ## Test make targets not checked by GitLab scripts/make-test # @@ -1074,7 +1065,7 @@ pretty: gofmt ## Run code through JS and Golang formatters npx prettier --write --loglevel warn "src/**/*.{js,jsx}" .PHONY: docker_circleci -docker_circleci: ## Run CircleCI container locally with project mounted +docker_circleci: ## Run GitLab container locally with project mounted docker run -it --pull=always --rm=true -v $(PWD):$(PWD) -w $(PWD) -e CIRCLECI=1 milmove/circleci-docker:milmove-app-3d9acdaa37c81a87b5fc1c6193a8e528dd56e4ed bash .PHONY: docker_local_ssh_server_with_password @@ -1288,4 +1279,4 @@ multi_branch: check_local_env clone_repo check_cloned_env success_message ## Set # ----- END SETUP MULTI BRANCH ----- # -default: help +default: help \ No newline at end of file diff --git a/scripts/rds-snapshot-app-db b/scripts/rds-snapshot-app-db index 6a3e1a704c6..580c30776c1 100755 --- a/scripts/rds-snapshot-app-db +++ b/scripts/rds-snapshot-app-db @@ -21,15 +21,15 @@ readonly tags=("Key=Environment,Value=$environment" "Key=Tool,Value=$(basename " echo echo "Wait for concurrent database snapshots for ${db_instance_identifier} to complete before continuing ..." -time aws rds wait db-snapshot-completed --db-instance-identifier "$db_instance_identifier" +time aws rds wait db-snapshot-completed --cli-read-timeout 2100 --cli-connect-timeout 2100 --db-instance-identifier "$db_instance_identifier" echo echo "Create database snapshot for ${db_instance_identifier} with identifier ${db_snapshot_identifier}" -aws rds create-db-snapshot --cli-read-timeout 0 --cli-connect-timeout 0 --db-instance-identifier "$db_instance_identifier" --db-snapshot-identifier "$db_snapshot_identifier" --tags "${tags[@]}" +aws rds create-db-snapshot --cli-read-timeout 2100 --cli-connect-timeout 2100 --db-instance-identifier "$db_instance_identifier" --db-snapshot-identifier "$db_snapshot_identifier" --tags "${tags[@]}" echo echo "Wait for current database snapshot ${db_snapshot_identifier} to complete before continuing ..." -time aws rds wait db-snapshot-completed --db-snapshot-identifier "$db_snapshot_identifier" +time aws rds wait db-snapshot-completed --cli-read-timeout 2100 --cli-connect-timeout 2100 --db-snapshot-identifier "$db_snapshot_identifier" echo echo "Describe the database snapshot ${db_snapshot_identifier}" diff --git a/scripts/run-server-test b/scripts/run-server-test index 0ead8674b81..45e8ab87afe 100755 --- a/scripts/run-server-test +++ b/scripts/run-server-test @@ -97,8 +97,15 @@ function server_report_cleanup() # https://unix.stackexchange.com/questions/305190/remove-last-character-from-string-captured-with-awk percent=$(grep '(statements)' "${test_dir}/go-coverage.txt" | awk '{print substr($NF, 1, length($NF)-1)}') goal_percent=50 + + #check if gitlab uses python3 + if [[ "${GITLAB:-}" == "1" ]]; then + python_exe="python3" + else + python_exe="python" + fi # using a oneline python function to test if percent is less than goal and return a proper exit code - if python -c "exit(1) if ${percent} < ${goal_percent} else exit()"; then + if exec "$python_exe" -c "exit(1) if ${percent} < ${goal_percent} else exit()"; then # coverage is good echo "total coverage is ${percent}%" else From ce288f68b1edd5aa25137a889b9ad82c3b3f5e6f Mon Sep 17 00:00:00 2001 From: josiahzimmerman-caci Date: Fri, 7 Feb 2025 09:16:09 -0600 Subject: [PATCH 2/2] Clean up export and add timeout; ready to go to main --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a86b26efa1..4e44992cc3f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -255,6 +255,7 @@ stages: export OKTA_API_KEY=notrealapikey8675309 export OKTA_OFFICE_GROUP_ID=notrealgroupId export OKTA_CUSTOMER_GROUP_ID=notrealcustomergroupId + export IWS_RBS_HOST=pkict.dmdc.osd.mil .setup_env_intergration_mtls: &setup_env_intergration_mtls - | @@ -397,7 +398,7 @@ golang_lint: - $DOCKER_RUNNER_TAG image: golangci/golangci-lint:latest # Refer to https://hub.docker.com/r/golangci/golangci-lint script: - - golangci-lint run --print-issued-lines=false --out-format code-climate:gl-code-quality-report.json,line-number + - golangci-lint run --print-issued-lines=false --timeout=25m --out-format code-climate:gl-code-quality-report.json,line-number artifacts: reports: codequality: gl-code-quality-report.json