-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for connector upgrades #51
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
FROM node:20-alpine | ||
ARG CONNECTOR_VERSION | ||
|
||
RUN apk add jq curl | ||
|
||
COPY /docker /scripts | ||
RUN : "${CONNECTOR_VERSION:?Connector version must be set}" | ||
RUN echo ${CONNECTOR_VERSION} > /scripts/CONNECTOR_VERSION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we bake in the version. |
||
|
||
COPY /functions /functions | ||
RUN /scripts/package-restore.sh | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env sh | ||
set -eu -o pipefail | ||
|
||
connector_path="${HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH:-/functions}" | ||
target_connector_version="$(cat /scripts/CONNECTOR_VERSION)" | ||
|
||
rm -rf /tmp/connector-upgrade | ||
mkdir /tmp/connector-upgrade | ||
|
||
# We copy the package.json and package-lock.json to a temporary directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had a thought about this, did you try running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I suppose you'd still need to do the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good suggestion, I didn't know about that flag. I'll give it a shot, it's worth it even if it just improves performance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like I can avoid all the copying and cat stuff with |
||
# so that we can upgrade the @hasura/ndc-lambda-sdk package without touching the | ||
# existing node_modules directory. This is because the existing node_modules directory | ||
# may have been installed on a different platform since it is being volume mounted | ||
# into a Linux container | ||
echo -n "Copying package.json, package-lock.json to a temporary location for upgrade... " | ||
cd "$connector_path" | ||
cp "package.json" "package-lock.json" /tmp/connector-upgrade/ | ||
echo "done" | ||
|
||
|
||
cd /tmp/connector-upgrade | ||
|
||
set +e | ||
existing_connector_version=$(jq '.dependencies["@hasura/ndc-lambda-sdk"]' -r package.json) | ||
exit_status=$? | ||
if [ $exit_status -ne 0 ]; then | ||
echo "Unable to read the @hasura/ndc-lambda-sdk version from your package.json" | ||
echo "Please manually upgrade the @hasura/ndc-lambda-sdk package in your package.json to version $target_connector_version" | ||
exit 1 | ||
fi | ||
|
||
if [ $existing_connector_version = "null" ]; then | ||
# This is very strange, their package.json must have the SDK installed but doesn't | ||
# We'll roll with it and just install the package | ||
echo "Missing the @hasura/ndc-lambda-sdk package in your package.json. Installing version $target_connector_version" | ||
else | ||
echo "Upgrading @hasura/ndc-lambda-sdk package from version $existing_connector_version to version $target_connector_version" | ||
fi | ||
|
||
npm install "@hasura/ndc-lambda-sdk@$target_connector_version" --save-exact --no-update-notifier | ||
exit_status=$? | ||
set -e | ||
|
||
if [ $exit_status -ne 0 ]; then | ||
echo "Failed to upgrade @hasura/ndc-lambda-sdk package to version $target_connector_version" | ||
echo "Please manually upgrade the @hasura/ndc-lambda-sdk package in your package.json to version $target_connector_version" | ||
exit 1 | ||
fi | ||
|
||
# We overwrite the existing file contents instead of copying because this causes the existing | ||
# file permissions/ownership to be retained, which is important since the container is likely | ||
# running as a different user to what's running on the docker host machine | ||
echo -n "Copying upgraded package.json, package-lock.json back to connector files... " | ||
cat package.json > "$connector_path/package.json" | ||
cat package-lock.json > "$connector_path/package-lock.json" | ||
echo "done" | ||
|
||
echo "Successfully upgraded @hasura/ndc-lambda-sdk package to version $target_connector_version" | ||
echo "You may need to run 'npm install' to install the new dependencies locally" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the version of? The
npm
binary itself?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or does this return the version field from
package.json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets the version field from package.json.