Skip to content

Commit c3fa77e

Browse files
authored
frontend: use versatiledatakit/shared rc-builds for data-pipelines (#2312)
## Why? Linking shared-components to data-pipelines using npm fails to produce a working UI docker image. This is a CI-only issue. ## What? Introduce rc-versions for @versatiledatakit/shared On a successful build of shared, and rc-version is pushed to npm registry The data-pipelines build pulls the latest rc-version when running, instead of linking to the local installation of shared Versioning schema follows semver {major}.{minor}.{patch}-rc.{rc-number} The rc-number is incremented based on the latest rc-number for the pipeline-id. This helps avoid conflicts between different pipelines running builds for shared Regular shared versions are tagged with latest in npm registry Rc versions are tagged with rc, so they don't get pulled accidentally when running npm install ## How was this tested? Ran a build in CI and tested that the docker image starts locally as part of quickstart-vdk by changing the deployment tag https://gitlab.com/vmware-analytics/versatile-data-kit/-/pipelines/909682172 Docker image tag pushed by pipeline `5eb2c00` To check it locally, run quickstart-vdk and edit the deployment to use this tag. <img width="1654" alt="Screenshot 2023-06-26 at 12 17 49" src="https://github.com/vmware/versatile-data-kit/assets/91800778/1cf6ba0c-b899-46f1-8827-abd29c4fcbf9"> ## What kind of change is this? Feature/non-breaking Signed-off-by: Dilyan Marinov <[email protected]>
1 parent 019d1f0 commit c3fa77e

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

projects/frontend/cicd/.gitlab-ci.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ frontend-data-pipelines-build:
3838
before_script:
3939
- cd projects/frontend/
4040
script:
41-
- ./cicd/install_data_pipelines.sh
41+
# Note: if frontend-shared-components-build is not part of the pipeline and no rc-version exists, $SHARED_RC_VERSION will be empty.
42+
# If $SHARED_RC_VERSION is empty, calling install_data_pipelines.sh will install the latest @versatiledatakit/shared package from registry.
43+
- export SHARED_RC_VERSION=$(../../cicd/get_latest_shared_rc_version.sh $CI_PIPELINE_ID)
44+
- ./cicd/install_data_pipelines.sh $SHARED_RC_VERSION
4245
coverage: /^TOTAL\s+\d+\s+\d+\s+(\d+\%)$/
4346
retry: !reference [.retry, retry_options]
4447
rules:
@@ -93,7 +96,7 @@ frontend-data-pipelines-release:
9396
before_script:
9497
- cd projects/frontend/
9598
script:
96-
- ./cicd/publish_package_npm.sh data-pipelines $CI_PIPELINE_ID $NPM_TOKEN $NPM_REGISTRY
99+
- ./cicd/publish_package_npm.sh data-pipelines $CI_PIPELINE_ID $NPM_TOKEN $NPM_REGISTRY latest
97100
retry: !reference [.retry, retry_options]
98101
rules:
99102
- if: '$CI_PIPELINE_SOURCE == "schedule"'
@@ -124,6 +127,7 @@ frontend_publish_ui_image:
124127
changes: *frontend_data_pipelines_locations
125128
extends: .frontend_publish_docker_image
126129

130+
# TODO: Enable this when https://github.com/vmware/versatile-data-kit/issues/2332 is resolved
127131
# frontend_tag_ui_image_stable:
128132
# stage: release
129133
# before_script:
@@ -211,6 +215,9 @@ frontend-shared-components-build:
211215
- cd projects/frontend/shared-components/gui
212216
script:
213217
- ../../cicd/install_shared.sh
218+
# Note: if this is the first time the pipeline runs and no rc-version exists, $SHARED_RC_INCREMENT will equal 1.
219+
- export SHARED_RC_INCREMENT=$(../../cicd/get_next_shared_rc_version_number.sh $CI_PIPELINE_ID)
220+
- ../../cicd/publish_package_npm.sh shared-components $CI_PIPELINE_ID-rc.$SHARED_RC_INCREMENT $NPM_TOKEN $NPM_REGISTRY rc
214221
retry: !reference [.retry, retry_options]
215222
rules:
216223
- if: '$CI_COMMIT_BRANCH == "main" || $CI_PIPELINE_SOURCE == "external_pull_request_event"'
@@ -234,7 +241,7 @@ frontend-shared-components-release:
234241
before_script:
235242
- cd projects/frontend/
236243
script:
237-
- ./cicd/publish_package_npm.sh shared-components $CI_PIPELINE_ID $NPM_TOKEN $NPM_REGISTRY
244+
- ./cicd/publish_package_npm.sh shared-components $CI_PIPELINE_ID $NPM_TOKEN $NPM_REGISTRY latest
238245
retry: !reference [.retry, retry_options]
239246
rules:
240247
- if: '$CI_PIPELINE_SOURCE == "schedule"'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2021-2023 VMware, Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
7+
# Extracts the latest rc-version for the pipeline id that's passed
8+
if [ $# -eq 0 ]
9+
then
10+
echo "ERROR: No argument for pipeline id supplied"
11+
exit 3
12+
fi
13+
npm view @versatiledatakit/shared versions --json | grep $1-rc | cut -d \" -f 2 | tail -1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -e
2+
3+
# Copyright 2021-2023 VMware, Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Extracts the latest rc-version number for the pipeline id that's passed
7+
# and returns the incremented version number
8+
# e.g. if the latest rc-version is 1.3.${pipeline_id}-rc.3, the script will return 4
9+
if [ $# -eq 0 ]
10+
then
11+
echo "ERROR: No argument for pipeline id supplied"
12+
exit 3
13+
fi
14+
15+
out=$(npm view @versatiledatakit/shared versions --json | grep $1-rc | cut -d \" -f 2 | tail -1 | awk -F '.' '{print $4}')
16+
out=$((out+1))
17+
echo $out

projects/frontend/cicd/install_data_pipelines.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# lints them to verify format, builds the UI application and runs the unit tests.
1010
###
1111

12+
shared_version=$1
13+
1214
if ! which npm >/dev/null 2>&1 ; then
1315
echo "ERROR:"
1416
echo "Please install npm 8.5.5+. Install cannot continue without it."
@@ -26,8 +28,14 @@ rm -f "package-lock.json"
2628
shared_dist_dir="../../shared-components/gui/dist/shared"
2729
if [ -d "$shared_dist_dir" ]
2830
then
29-
echo "Linking the shared-components dist rebuild found..."
30-
npm link "$shared_dist_dir"
31+
if [ -n "$shared_version"]
32+
then
33+
echo "Installing the latest shared-components rc-version"
34+
npm install --no-save "@versatiledatakit/shared@$shared_version"
35+
else
36+
echo "Linking the shared-components dist rebuild found..."
37+
npm link "$shared_dist_dir"
38+
fi
3139
else
3240
echo "No shared-components dist rebuild found."
3341
fi

projects/frontend/cicd/publish_package_npm.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ if [ $# -eq 2 ]
5454
fi
5555
npm_token=$3
5656

57-
# optional; defaults to registry.npmjs.org public repo
5857
if [ $# -eq 3 ]
5958
then
60-
npm_registry="registry.npmjs.org"
61-
else
62-
npm_registry=$4
59+
echo "ERROR: No argument for npm registry url provided."
60+
exit 3
6361
fi
62+
npm_registry=$4
6463

64+
if [ $# -eq 4 ]
65+
then
66+
echo "ERROR: No argument for npm tag provided."
67+
exit 3
68+
fi
69+
npm_tag=$5
6570

6671
# Locate the project dist directory
6772
if [ -d "./dist/$project_type/" ]
@@ -87,4 +92,4 @@ npm set //$npm_registry/:_authToken $npm_token
8792

8893
# Publish
8994
echo "Publishing @vdk/$(basename "$PWD"):${package_version}..."
90-
npm publish --ignore-scripts --access public
95+
npm publish --ignore-scripts --access public --tag $npm_tag

0 commit comments

Comments
 (0)