Skip to content

Commit 3090f60

Browse files
Add build of the Connector Definition and the base Docker image (#9)
1 parent d51218e commit 3090f60

File tree

12 files changed

+292
-81
lines changed

12 files changed

+292
-81
lines changed

.github/workflows/generator-hasura-ndc-nodejs-lambda.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ on:
33
pull_request:
44
branches:
55
- main
6+
- test-ci/**
67
push:
78
branches:
89
- 'main'
10+
- test-ci/**
911
tags:
1012
- v**
1113

.github/workflows/ndc-lambda-sdk.yaml

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: "ndc-nodejs-lambda connector"
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
- test-ci/**
7+
push:
8+
branches:
9+
- 'main'
10+
- test-ci/**
11+
tags:
12+
- v**
13+
14+
env:
15+
DOCKER_REGISTRY: ghcr.io
16+
DOCKER_IMAGE_NAME: hasura/ndc-nodejs-lambda
17+
18+
jobs:
19+
build-npm:
20+
name: Build ndc-lambda-sdk npm package
21+
defaults:
22+
run:
23+
working-directory: ./ndc-lambda-sdk
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version-file: .nvmrc
30+
registry-url: https://registry.npmjs.org
31+
cache: npm
32+
cache-dependency-path: ./ndc-lambda-sdk/package-lock.json
33+
- run: npm ci
34+
- run: npm run build
35+
- run: npm test
36+
37+
publish-npm:
38+
name: Publish ndc-lambda-sdk to npm
39+
defaults:
40+
run:
41+
working-directory: ./ndc-lambda-sdk
42+
needs: build-npm
43+
runs-on: ubuntu-latest
44+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
- uses: actions/setup-node@v4
48+
with:
49+
node-version-file: .nvmrc
50+
registry-url: https://registry.npmjs.org
51+
cache: npm
52+
cache-dependency-path: ./ndc-lambda-sdk/package-lock.json
53+
- run: |
54+
PACKAGE_VERSION=`npm version | sed -rn "2 s/.*: '([^']*)'.*/\1/g; 2 p"`
55+
TAG=`echo "$GITHUB_REF"| sed -r "s#.*/##g"`
56+
echo '$TAG' = "$TAG"
57+
echo '$GITHUB_REF' = "$GITHUB_REF"
58+
echo '$PACKAGE_VERSION' = "$PACKAGE_VERSION"
59+
if [ "$TAG" = "v$PACKAGE_VERSION" ]
60+
then
61+
echo "Success! Versions match."
62+
else
63+
echo "Package version (v$PACKAGE_VERSION) must match tag (GITHUB_REF: $GITHUB_REF) in order to publish" 1>&2
64+
exit 1
65+
fi
66+
- run: npm ci
67+
- run: npm run build
68+
- run: npm publish --access public
69+
env:
70+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
71+
72+
docker:
73+
name: Build base docker image
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v4
77+
- uses: docker/login-action@v3
78+
with:
79+
registry: ${{ env.DOCKER_REGISTRY }}
80+
username: ${{ github.actor }}
81+
password: ${{ secrets.GITHUB_TOKEN }}
82+
- name: Extract metadata (tags, labels) for Docker
83+
id: docker-metadata
84+
uses: docker/metadata-action@v5
85+
with:
86+
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}
87+
- uses: docker/build-push-action@v5
88+
with:
89+
context: .
90+
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
91+
tags: ${{ steps.docker-metadata.outputs.tags }}
92+
labels: ${{ steps.docker-metadata.outputs.labels }}
93+
94+
release-connector:
95+
name: Release connector
96+
defaults:
97+
run:
98+
working-directory: ./connector-definition
99+
runs-on: ubuntu-latest
100+
needs:
101+
- publish-npm
102+
- docker
103+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
104+
steps:
105+
- uses: actions/checkout@v4
106+
- uses: actions/setup-node@v4
107+
with:
108+
node-version-file: .nvmrc
109+
registry-url: https://registry.npmjs.org
110+
cache: npm
111+
cache-dependency-path: ./ndc-lambda-sdk/package-lock.json
112+
- name: Build connector definition
113+
run: make build
114+
- uses: actions/upload-artifact@v4
115+
with:
116+
name: connector-definition.tgz
117+
path: ./connector-definition/dist/connector-definition.tgz
118+
compression-level: 0 # Already compressed
119+
- name: Get version from tag
120+
id: get-version
121+
run: |
122+
echo "tagged_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
123+
shell: bash
124+
- uses: mindsers/changelog-reader-action@v2
125+
id: changelog-reader
126+
with:
127+
version: ${{ steps.get-version.outputs.tagged_version }}
128+
path: ./CHANGELOG.md
129+
- uses: softprops/action-gh-release@v1
130+
with:
131+
draft: false
132+
tag_name: v${{ steps.get-version.outputs.tagged_version }}
133+
body: ${{ steps.changelog-reader.outputs.changes }}
134+
files: |
135+
./connector-definition/dist/connector-definition.tgz
136+
fail_on_unmatched_files: true

CHANGELOG.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# NodeJS Lambda Connector Changelog
22
This changelog documents the changes between release versions.
33

4-
## Unreleased
4+
## [Unreleased]
55
Changes to be included in the next upcoming release
66

7+
### ndc-lambda-sdk
78
- Support for NDC Spec v0.1.0-rc.15 via the NDC TypeScript SDK v4.1.0 ([#8](https://github.com/hasura/ndc-nodejs-lambda/pull/8), [#10](https://github.com/hasura/ndc-nodejs-lambda/pull/11), [#13](https://github.com/hasura/ndc-nodejs-lambda/pull/13)). This is a breaking change and must be used with the latest Hasura engine.
89
- Support for nested object/array selection
910
- New function calling convention that relies on nested object queries
@@ -12,33 +13,36 @@ Changes to be included in the next upcoming release
1213
- The default port is now 8080 instead of 8100
1314
- OpenTelemetry support improved, with additional spans covering work done around function invocation
1415

15-
## v0.15.0
16+
### Yeoman template
17+
- Prompts the user to pick between a version of ndc-lambda-sdk that works for Hasura DDN Alpha or Hasura DDN Beta
18+
19+
## [0.15.0] - 2024-02-21
1620
- OpenTelemetry support added via support for NDC TypeScript SDK v1.3.0 ([#12](https://github.com/hasura/ndc-nodejs-lambda/pull/12))
1721

18-
## v0.14.0
22+
## [0.14.0] - 2024-02-16
1923
- Support for "relaxed types" ([#10](https://github.com/hasura/ndc-nodejs-lambda/pull/10))
2024

21-
## v0.13.0
25+
## [0.13.0] - 2024-02-09
2226
- Add support for treating 'true | false' as a Boolean type ([#7](https://github.com/hasura/ndc-nodejs-lambda/pull/7))
2327

24-
## v0.12.0
28+
## [0.12.0] - 2024-01-31
2529
- Add support for JSDoc descriptions from object types ([#3](https://github.com/hasura/ndc-nodejs-lambda/pull/3))
2630
- Fix type name conflicts when using generic interfaces ([#4](https://github.com/hasura/ndc-nodejs-lambda/pull/4))
2731
- Improve error handling of errors thrown from functions ([#5](https://github.com/hasura/ndc-nodejs-lambda/pull/5))
2832
- The entire causal stack trace is now captured as an error detail for unhandled errors
2933
- `sdk.Forbidden`, `sdk.Conflict`, `sdk.UnprocessableContent` can be thrown to return error details to GraphQL API clients
3034

31-
## v0.11.0
35+
## [0.11.0] - 2024-01-25
3236
- Add support for parallel execution of readonly functions ([#2](https://github.com/hasura/ndc-nodejs-lambda/pull/2))
3337

34-
## v0.10.0
38+
## [0.10.0] - 2024-01-23
3539
- Add missing query.variables capability
3640

37-
## v0.9.0
41+
## [0.9.0] - 2024-01-22
3842
- Disallow use of Map types and types with index signatures
3943
- Add support for re-exporting functions from other files
4044

41-
## v0.8.0
45+
## [0.8.0] - 2024-01-18
4246
### ndc-lambda-sdk
4347
- Fix queries with variables returning incorrect result format
4448
- If a scalar value validation fails, return the error as an UnprocessableContent error
@@ -48,28 +52,28 @@ Changes to be included in the next upcoming release
4852
- Use pretty printing of logs in watch mode in the template
4953
- Add latest version check to yeoman generator
5054

51-
## v0.7.0
55+
## [0.7.0] - 2024-01-17
5256
- Rename `@pure` to `@readonly`
5357
- Add JSONValue type for arbitrary JSON
5458
- Block use of never, object, unknown, any and tuple types
5559
- Block use of function types as args/return values
5660
- Disallow use of union types in args and return types
5761
- Remove custom scalar generation as an unknown type fallback
5862

59-
## v0.6.0
63+
## [0.6.0] - 2024-01-15
6064
- Prevent usage of null or undefined literals on their own
6165
- Add support for literal types
6266
- Fix queries not using new response reshaping code
6367

64-
## v0.5.0
68+
## [0.5.0] - 2024-01-11
6569
- Fix SIGTERM signal handling for clean docker container shutdowns
6670
- Add BigInt support and rework scalar type handling
6771
- Add support for Date types
6872

69-
## v0.4.0
73+
## [0.4.0] - 2024-01-04
7074
- Allow promise typed return values
7175
- Fix tsconfig relative pathing
7276
- Fix error when no user tsconfig exists
7377

74-
## v0.3.0
78+
## [0.3.0] - 2023-12-22
7579
- Initial release

connector-definition/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.hasura-connector/
2+
*.hml

connector-definition/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ghcr.io/hasura/ndc-nodejs-lambda:v{{VERSION}}
2+
3+
COPY package-lock.json package.json /functions/
4+
5+
WORKDIR /functions
6+
RUN --mount=type=cache,target=/root/.npm \
7+
npm ci
8+
9+
COPY ./ /functions

connector-definition/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.DEFAULT_GOAL := build
2+
SHELL = /usr/bin/env bash
3+
4+
RELEASE_VERSION_DEP := ../ndc-lambda-sdk/package.json
5+
RELEASE_VERSION := $(shell jq -r '.version' $(RELEASE_VERSION_DEP))
6+
7+
.PHONY: build
8+
build: dist/connector-definition.tgz
9+
10+
.PHONY: clean
11+
clean:
12+
rm -rf dist
13+
rm -f connector-definition.tgz
14+
15+
dist dist/.hasura-connector:
16+
mkdir dist
17+
mkdir dist/.hasura-connector
18+
19+
dist/.hasura-connector/connector-metadata.yaml: connector-metadata.yaml dist
20+
cp -f connector-metadata.yaml dist/.hasura-connector
21+
22+
dist/.hasura-connector/Dockerfile: Dockerfile dist/.hasura-connector $(RELEASE_VERSION_DEP)
23+
cp -f Dockerfile dist/.hasura-connector/
24+
sed -i -E 's/\{\{VERSION\}\}/$(RELEASE_VERSION)/g' dist/.hasura-connector/Dockerfile
25+
26+
dist/.hasura-connector/.dockerignore: .dockerignore dist/.hasura-connector
27+
cp -f .dockerignore dist/.hasura-connector/
28+
29+
template_files := $(filter-out %/package.json,$(wildcard template/*))
30+
dist_template_files := $(patsubst template/%,dist/%,$(template_files))
31+
32+
$(dist_template_files): $(template_files)
33+
cp -f $(template_files) dist/
34+
35+
dist/package.json: template/package.json $(RELEASE_VERSION_DEP)
36+
cp -f template/package.json dist/
37+
jq '.dependencies["@hasura/ndc-lambda-sdk"] = "$(RELEASE_VERSION)"' dist/package.json > dist/package.json.tmp
38+
mv -f dist/package.json.tmp dist/package.json
39+
40+
dist/package-lock.json: dist/package.json
41+
cd dist && npm install
42+
rm -rf dist/node_modules
43+
44+
dist/connector-definition.tgz: dist/.hasura-connector/connector-metadata.yaml dist/.hasura-connector/Dockerfile dist/.hasura-connector/.dockerignore $(dist_template_files) dist/package-lock.json
45+
shopt -s dotglob && cd dist && tar -czvf connector-definition.tgz *
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packagingDefinition:
2+
type: ManagedDockerBuild
3+
supportedEnvironmentVariables: []
4+
commands: {}
5+
dockerComposeWatch:
6+
# Rebuild the container if a new package restore is required because package[-lock].json changed
7+
- path: package.json
8+
target: /functions/package.json
9+
action: rebuild
10+
- path: package-lock.json
11+
target: /functions/package-lock.json
12+
action: rebuild
13+
# For any other file change, simply copy it into the existing container and restart it
14+
- path: ./
15+
target: /functions
16+
action: sync+restart
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @readonly Exposes the function as an NDC function (the function should only query data without making modifications)
3+
*/
4+
export function hello(name?: string) {
5+
return `hello ${name ?? "world"}`;
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"engines": {
4+
"node": ">=18"
5+
},
6+
"scripts": {
7+
"start": "ndc-lambda-sdk host -f functions.ts serve --configuration ./",
8+
"watch": "ndc-lambda-sdk host -f functions.ts --watch serve --configuration ./ --pretty-print-logs"
9+
},
10+
"dependencies": {
11+
"@hasura/ndc-lambda-sdk": "*"
12+
}
13+
}

0 commit comments

Comments
 (0)