|
| 1 | +#!/usr/bin/env sh |
| 2 | +set -eu -o pipefail |
| 3 | + |
| 4 | +connector_path="${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH:-/functions}" |
| 5 | +target_connector_version="$(cat /scripts/CONNECTOR_VERSION)" |
| 6 | + |
| 7 | +rm -rf /tmp/connector-upgrade |
| 8 | +mkdir /tmp/connector-upgrade |
| 9 | + |
| 10 | +# We copy the package.json and package-lock.json to a temporary directory |
| 11 | +# so that we can upgrade the @hasura/ndc-lambda-sdk package without touching the |
| 12 | +# existing node_modules directory. This is because the existing node_modules directory |
| 13 | +# may have been installed on a different platform since it is being volume mounted |
| 14 | +# into a Linux container |
| 15 | +echo -n "Copying package.json, package-lock.json to a temporary location for upgrade... " |
| 16 | +cd "$connector_path" |
| 17 | +cp "package.json" "package-lock.json" /tmp/connector-upgrade/ |
| 18 | +echo "done" |
| 19 | + |
| 20 | + |
| 21 | +cd /tmp/connector-upgrade |
| 22 | + |
| 23 | +set +e |
| 24 | +existing_connector_version=$(jq '.dependencies["@hasura/ndc-lambda-sdk"]' -r package.json) |
| 25 | +exit_status=$? |
| 26 | +if [ $exit_status -ne 0 ]; then |
| 27 | + echo "Unable to read the @hasura/ndc-lambda-sdk version from your package.json" |
| 28 | + echo "Please manually upgrade the @hasura/ndc-lambda-sdk package in your package.json to version $target_connector_version" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +if [ $existing_connector_version = "null" ]; then |
| 33 | + # This is very strange, their package.json must have the SDK installed but doesn't |
| 34 | + # We'll roll with it and just install the package |
| 35 | + echo "Missing the @hasura/ndc-lambda-sdk package in your package.json. Installing version $target_connector_version" |
| 36 | +else |
| 37 | + echo "Upgrading @hasura/ndc-lambda-sdk package from version $existing_connector_version to version $target_connector_version" |
| 38 | +fi |
| 39 | + |
| 40 | +npm install "@hasura/ndc-lambda-sdk@$target_connector_version" --save-exact --no-update-notifier |
| 41 | +exit_status=$? |
| 42 | +set -e |
| 43 | + |
| 44 | +if [ $exit_status -ne 0 ]; then |
| 45 | + echo "Failed to upgrade @hasura/ndc-lambda-sdk package to version $target_connector_version" |
| 46 | + echo "Please manually upgrade the @hasura/ndc-lambda-sdk package in your package.json to version $target_connector_version" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +# We overwrite the existing file contents instead of copying because this causes the existing |
| 51 | +# file permissions/ownership to be retained, which is important since the container is likely |
| 52 | +# running as a different user to what's running on the docker host machine |
| 53 | +echo -n "Copying upgraded package.json, package-lock.json back to connector files... " |
| 54 | +cat package.json > "$connector_path/package.json" |
| 55 | +cat package-lock.json > "$connector_path/package-lock.json" |
| 56 | +echo "done" |
| 57 | + |
| 58 | +echo "Successfully upgraded @hasura/ndc-lambda-sdk package to version $target_connector_version" |
| 59 | +echo "You may need to run 'npm install' to install the new dependencies locally" |
0 commit comments