From e9b14fe5a56e890860ad911f47e1b0bd11fa7cf7 Mon Sep 17 00:00:00 2001 From: Dilyan Marinov Date: Mon, 22 May 2023 12:57:15 +0300 Subject: [PATCH] frontend: ping frontend on docker image release Why The frontend is now part of quickstart-vdk. On changes to the docker image, the helm chart needs to be redeployed. We need to make sure that the frontend is operational once the helm chart is deployed. What Introduce new post_release_image stage to ci Introduce new post_release_image_test stage to ci Trigger deployment of test control service on frontend changes merged into main Ping the frontend using heartbeat once control service is deployed Tag the frontend image as stable once heartbeat test passes How has this been tested n/a What kind of change is this feature/non-breaking Signed-off-by: Dilyan Marinov --- .gitlab-ci.yml | 2 + .../pipelines-control-service/values.yaml | 4 +- projects/frontend/cicd/.gitlab-ci.yml | 52 ++++++++++++++++++- .../cicd/ping_frontend_heartbeat_config.ini | 5 ++ .../frontend/cicd/publish_image_dockerhub.sh | 3 +- 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 projects/frontend/cicd/ping_frontend_heartbeat_config.ini diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe3b59048f..b0ba778dbc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,6 +21,8 @@ stages: - pre_release_test - release - release_image + - post_release_image + - post_release_image_test - end build-check-prerequisites: diff --git a/projects/control-service/projects/helm_charts/pipelines-control-service/values.yaml b/projects/control-service/projects/helm_charts/pipelines-control-service/values.yaml index 7668a07230..220f15c2cf 100644 --- a/projects/control-service/projects/helm_charts/pipelines-control-service/values.yaml +++ b/projects/control-service/projects/helm_charts/pipelines-control-service/values.yaml @@ -14,7 +14,7 @@ global: {} image: registry: registry.hub.docker.com/versatiledatakit repository: pipelines-control-service - tag: "99a4957" + tag: "stable" ## Specify a imagePullPolicy ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images @@ -32,7 +32,7 @@ operationsUi: image: registry: registry.hub.docker.com/versatiledatakit repository: vdk-operations-ui - tag: "latest" + tag: "stable" username: password: replicaCount: 1 diff --git a/projects/frontend/cicd/.gitlab-ci.yml b/projects/frontend/cicd/.gitlab-ci.yml index ea24f6ed13..d6f181401e 100644 --- a/projects/frontend/cicd/.gitlab-ci.yml +++ b/projects/frontend/cicd/.gitlab-ci.yml @@ -23,6 +23,12 @@ - "projects/frontend/data-pipelines/gui/Dockerfile" - "projects/frontend/data-pipelines/gui/config/nginx.conf" +.frontend_retry: + retry_options: + max: 1 + when: + - always + frontend-data-pipelines-build: image: "versatiledatakit/vdk-cicd-base-gui:2.0.0" stage: build @@ -102,7 +108,7 @@ frontend-data-pipelines-release: expire_in: 1 week frontend_publish_ui_image: - stage: release + stage: release_image before_script: - cd projects/frontend script: @@ -118,8 +124,50 @@ frontend_publish_ui_image: changes: *frontend_data_pipelines_locations extends: .frontend_publish_docker_image +frontend_deploy_testing_data_pipelines: + stage: post_release_image + image: docker:23.0.1 + script: + - apk --no-cache add bash openssl curl git gettext zip py-pip + - pip install --upgrade pip && pip install awscli + - export DESIRED_VERSION=v3.11.3 # helm version 3.11.3 + - export TAG=latest + - export FRONTEND_TAG=$(git rev-parse --short HEAD) + - curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash + - bash -ex ./projects/control-service/cicd/deploy-testing-pipelines-service.sh + retry: !reference [.frontend_retry, retry_options] + rules: + - if: '$CI_PIPELINE_SOURCE == "schedule"' + when: never + - if: '$CI_COMMIT_BRANCH == "main"' + changes: *frontend_shared_components_locations + - if: '$CI_COMMIT_BRANCH == "main"' + changes: *frontend_data_pipelines_locations + +frontend_post_deployment_test: + stage: post_release_image_test + image: python:3.7 + script: + - set -x + - pip install quickstart-vdk + - pip install vdk-heartbeat[trino] + - vdk version + - export IMAGE_TAG="$(git rev-parse --short HEAD)" + - export VDKCLI_OAUTH2_REFRESH_TOKEN=$VDK_API_TOKEN + - export VDK_HEARTBEAT_OP_ID="vdkcs-$CI_PIPELINE_ID" + - vdk-heartbeat -f projects/frontend/cicd/ping_frontend_heartbeat_config.ini + - bash -ex ./projects/control-service/cicd/tag_image_dockerhub.sh pipelines-control-service $IMAGE_TAG stable + retry: !reference [.frontend_retry, retry_options] + rules: + - if: '$CI_PIPELINE_SOURCE == "schedule"' + when: never + - if: '$CI_COMMIT_BRANCH == "main"' + changes: *frontend_shared_components_locations + - if: '$CI_COMMIT_BRANCH == "main"' + changes: *frontend_data_pipelines_locations + frontend_publish_test_image: - stage: release + stage: release_image script: - docker login --username "${VDK_DOCKER_REGISTRY_USERNAME}" --password "${VDK_DOCKER_REGISTRY_PASSWORD}" "${VDK_DOCKER_REGISTRY_URL}" - cd projects/frontend/cicd diff --git a/projects/frontend/cicd/ping_frontend_heartbeat_config.ini b/projects/frontend/cicd/ping_frontend_heartbeat_config.ini new file mode 100644 index 0000000000..66112b0e68 --- /dev/null +++ b/projects/frontend/cicd/ping_frontend_heartbeat_config.ini @@ -0,0 +1,5 @@ +[DEFAULT] +JOB_RUN_TEST_MODULE_NAME=vdk.internal.heartbeat.ping_frontend_test +JOB_RUN_TEST_CLASS_NAME=PingFrontendTest + +CONTROL_API_URL=http://cicd-control-service-ui:80 diff --git a/projects/frontend/cicd/publish_image_dockerhub.sh b/projects/frontend/cicd/publish_image_dockerhub.sh index dcb14257ce..46aed12de2 100755 --- a/projects/frontend/cicd/publish_image_dockerhub.sh +++ b/projects/frontend/cicd/publish_image_dockerhub.sh @@ -19,7 +19,8 @@ version_tag=$(awk -v id=$patch_version 'BEGIN { FS="."; OFS = "."; ORS = "" } { image_repo="$VDK_DOCKER_REGISTRY_URL/$name" image_tag="$image_repo:$version_tag" +commit_sha=$(git rev-parse --short HEAD) -docker build -t "$image_tag" -t "$image_repo:latest" $ui_path +docker build -t "$image_tag" -t "$image_repo:latest" -t "$image_repo:$commit_sha" $ui_path docker push "$image_tag" docker push "$image_repo:latest"