Skip to content

Commit d9c4cc1

Browse files
Add support for connector upgrades
1 parent 2711113 commit d9c4cc1

File tree

6 files changed

+82
-2
lines changed

6 files changed

+82
-2
lines changed

.github/workflows/ndc-nodejs-lambda-connector.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,19 @@ jobs:
9494
with:
9595
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
9696

97+
- name: Get npm package version
98+
id: get-npm-package-version
99+
run: |
100+
PACKAGE_VERSION=`npm version | sed -rn "2 s/.*: '([^']*)'.*/\1/g; 2 p"`
101+
echo "package_version=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
102+
shell: bash
103+
working-directory: ./ndc-lambda-sdk
104+
97105
- uses: docker/build-push-action@v6
98106
with:
99107
context: .
108+
build-args: |
109+
CONNECTOR_VERSION=${{ steps.get-npm-package-version.outputs.package_version }}
100110
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
101111
platforms: linux/amd64,linux/arm64
102112
tags: ${{ steps.docker-metadata.outputs.tags }}

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ This changelog documents the changes between release versions.
44
## [Unreleased]
55
Changes to be included in the next upcoming release
66

7+
### Added
8+
- The connector now supports being upgraded with the forthcoming `ddn connector upgrade` command ([#51](https://github.com/hasura/ndc-nodejs-lambda/pull/51))
9+
710
## [1.10.0] - 2024-11-21
8-
- The connector now exits during startup if there are compiler errors in the functions code. The compiler errors are printed to stderr. Previously the connector would print the errors and start "successfully", but with an empty schema. The new behaviour ensures that when the connector is used with `ddn connector introspect`, `ddn` is aware that a problem has occurred (because the connector fails to start) and will prompt the user to print the logs to see the compiler errors.
11+
- The connector now exits during startup if there are compiler errors in the functions code. The compiler errors are printed to stderr. Previously the connector would print the errors and start "successfully", but with an empty schema. The new behaviour ensures that when the connector is used with `ddn connector introspect`, `ddn` is aware that a problem has occurred (because the connector fails to start) and will prompt the user to print the logs to see the compiler errors. ([#50](https://github.com/hasura/ndc-nodejs-lambda/pull/50))
912

1013
## [1.9.0] - 2024-10-24
1114

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
FROM node:20-alpine
2+
ARG CONNECTOR_VERSION
23

34
RUN apk add jq curl
45

56
COPY /docker /scripts
7+
RUN : "${CONNECTOR_VERSION:?Connector version must be set}"
8+
RUN echo ${CONNECTOR_VERSION} > /scripts/CONNECTOR_VERSION
69

710
COPY /functions /functions
811
RUN /scripts/package-restore.sh

connector-definition/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dist dist/.hasura-connector:
1717

1818
dist/.hasura-connector/connector-metadata.yaml: connector-metadata.yaml dist
1919
cp -f connector-metadata.yaml dist/.hasura-connector
20+
sed -i -E 's/\{\{VERSION\}\}/$(RELEASE_VERSION)/g' dist/.hasura-connector/connector-metadata.yaml
2021

2122
dist/.hasura-connector/Dockerfile: Dockerfile dist/.hasura-connector $(RELEASE_VERSION_DEP)
2223
cp -f Dockerfile dist/.hasura-connector/

connector-definition/connector-metadata.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ nativeToolchainDefinition:
1111
bash: ./watch.sh
1212
powershell: ./watch.ps1
1313
supportedEnvironmentVariables: []
14-
commands: {}
14+
commands:
15+
upgradeConfiguration:
16+
type: Dockerized
17+
dockerImage: ghcr.io/hasura/ndc-nodejs-lambda:v{{VERSION}}
18+
dockerCommand: ["/scripts/upgrade-connector.sh"]
1519
dockerComposeWatch:
1620
# Rebuild the container if a new package restore is required because package[-lock].json changed
1721
- path: package.json

docker/upgrade-connector.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)