Skip to content

Commit 08ba057

Browse files
Add support for connector upgrades (#51)
1 parent 2711113 commit 08ba057

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
cd "$connector_path"
8+
9+
set +e
10+
existing_connector_version=$(jq '.dependencies["@hasura/ndc-lambda-sdk"]' -r package.json)
11+
exit_status=$?
12+
if [ $exit_status -ne 0 ]; then
13+
echo "Unable to read the @hasura/ndc-lambda-sdk version from your package.json"
14+
echo "Please manually upgrade the @hasura/ndc-lambda-sdk package in your package.json to version $target_connector_version"
15+
exit 1
16+
fi
17+
18+
if [ $existing_connector_version = "null" ]; then
19+
# This is very strange, their package.json must have the SDK installed but doesn't
20+
# We'll roll with it and just install the package
21+
echo "Missing the @hasura/ndc-lambda-sdk package in your package.json. Installing version $target_connector_version"
22+
else
23+
echo "Upgrading @hasura/ndc-lambda-sdk package from version $existing_connector_version to version $target_connector_version"
24+
fi
25+
26+
# We do a --package-lock-only because we don't want to change the node_modules directory.
27+
# This is because the existing node_modules directory may have been installed on a
28+
# different platform since it is being volume mounted into a Linux container
29+
npm install "@hasura/ndc-lambda-sdk@$target_connector_version" --save-exact --no-update-notifier --package-lock-only
30+
exit_status=$?
31+
set -e
32+
33+
if [ $exit_status -ne 0 ]; then
34+
echo "Failed to upgrade @hasura/ndc-lambda-sdk package to version $target_connector_version"
35+
echo "Please manually upgrade the @hasura/ndc-lambda-sdk package in your package.json to version $target_connector_version"
36+
exit 1
37+
fi
38+
39+
echo "Successfully upgraded @hasura/ndc-lambda-sdk package to version $target_connector_version"
40+
echo "You may need to run 'npm install' to install the new dependencies locally"

0 commit comments

Comments
 (0)