Skip to content

Commit 0a59dba

Browse files
authored
Connector packaging (#1)
* Expect service account file path in env var * Dump API metadata into intermediate configuration.json file * Add Dockerfile to build the connector * GH_TOKEN -> GITHUB_TOKEN * Expand root .dockerignore with git related stuff * Update package-lock.json * Fix Dockerfile and file path append * Update README * Add date format in field descriptions * Push down dimension and metrics filters to APIs * Implement more filters * Include descriptions of dimensions and metrics in the schema
1 parent b093020 commit 0a59dba

File tree

18 files changed

+1007
-184
lines changed

18 files changed

+1007
-184
lines changed

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
google_auth_config.json
2+
configuration.json
3+
node_modules/
4+
dist/
5+
.env
6+
.DS_Store
7+
*.log
8+
*.tmp
9+
coverage/
10+
.vscode/
11+
.idea/
12+
*.swp
13+
*.bak
14+
*.orig
15+
.gitignore
16+
.git
17+
.github
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build and Push Multi-arch Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to build and push'
8+
required: true
9+
type: string
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: hasura/ndc-promptql-ga4
14+
15+
jobs:
16+
build-and-push:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Login to GitHub Container Registry
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Build and push Docker image
37+
env:
38+
VERSION: ${{ inputs.version }}
39+
run: |
40+
docker buildx build \
41+
--platform linux/amd64,linux/arm64 \
42+
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} \
43+
--push .

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
config.json
1+
google_auth_config.json
2+
configuration.json
23
node_modules/
34
dist/
45
.env
@@ -10,4 +11,4 @@ coverage/
1011
.idea/
1112
*.swp
1213
*.bak
13-
*.orig
14+
*.orig

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:20-alpine
2+
3+
RUN apk add --no-cache bash
4+
5+
RUN npm update -g npm
6+
7+
COPY ./ /app/
8+
WORKDIR /app
9+
10+
RUN --mount=type=cache,target=/root/.npm npm ci
11+
RUN npm run install-bin
12+
13+
RUN mkdir /etc/connector
14+
WORKDIR /etc/connector
15+
16+
CMD ["ga4-connector", "serve", "--configuration", "configuration.json"]

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
# promptql-GA4
22

3-
Requires config.json to be added in the root directory
3+
Requires `google_auth_config.json` to be added in the root directory
4+
5+
```json
6+
{
7+
"property_id": "123456789",
8+
"domain": "example.com",
9+
"credentials": { <service account json credentials> }
10+
}
11+
```
412

513
### To compile:
6-
`npx ts`
714

15+
`npm run build`
16+
17+
### To generate `configuration.json`:
18+
19+
`npm run generate-config`
20+
21+
### To start connector:
822

9-
### To run locally:
10-
`node dist/index.js serve --port 8200 --configuration config.json`
23+
`npm run start`

connector-definition/.dockerignore

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

connector-definition/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google_auth_config.json
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: v2
2+
ndcSpecGeneration: v0.2
3+
packagingDefinition:
4+
type: PrebuiltDockerImage
5+
dockerImage: ghcr.io/hasura/ndc-promptql-ga4:v0.1.0
6+
supportedEnvironmentVariables:
7+
- name: GOOGLE_AUTH_CONFIG_FILEPATH
8+
description: Filepath for the Google Auth config file relative to the connector directory.
9+
required: false
10+
defaultValue: "google_auth_config.json"
11+
commands:
12+
update:
13+
type: Dockerized
14+
dockerImage: ghcr.io/hasura/ndc-promptql-ga4:v0.1.0
15+
commandArgs:
16+
- "ga4-connector-cli"
17+
- "update"
18+
- "--outfile"
19+
- "/etc/connector/configuration.json"
20+
cliPlugin:
21+
type: Docker
22+
dockerImage: ghcr.io/hasura/ndc-promptql-ga4:v0.1.0
23+
dockerComposeWatch:
24+
# Rebuild the container if a new package restore is required because package[-lock].json changed
25+
- path: package.json
26+
target: /app/package.json
27+
action: rebuild
28+
- path: package-lock.json
29+
target: /app/package-lock.json
30+
action: rebuild
31+
# For any other file change, simply copy it into the existing container and restart it
32+
- path: ./
33+
target: /app
34+
action: sync+restart

package-lock.json

Lines changed: 20 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
{
22
"name": "ga4-connector",
3-
"version": "1.0.0",
4-
"main": "index.js",
3+
"version": "0.1.0",
54
"scripts": {
6-
"test": "echo \"Error: no test specified\" && exit 1"
5+
"test": "echo \"Error: no test specified\" && exit 1",
6+
"format": "npx prettier --write src/**/*.ts",
7+
"build": "tsc",
8+
"generate-config": "HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH=./ GOOGLE_AUTH_CONFIG_FILEPATH=google_auth_config.json node dist/cli.js update --output configuration.json",
9+
"start": "HASURA_CONFIGURATION_DIRECTORY=./ GOOGLE_AUTH_CONFIG_FILEPATH=google_auth_config.json node dist/index.js serve --port 8200 --configuration configuration.json",
10+
"install-bin": "npm run build && npm install -g ."
11+
},
12+
"bin": {
13+
"ga4-connector": "./dist/index.js",
14+
"ga4-connector-cli": "./dist/cli.js"
715
},
816
"keywords": [],
917
"author": "",
@@ -12,6 +20,7 @@
1220
"dependencies": {
1321
"@google-analytics/data": "^5.1.0",
1422
"@hasura/ndc-sdk-typescript": "^7.1.0",
23+
"commander": "^14.0.0",
1524
"google-auth-library": "^10.1.0",
1625
"undici": "^7.13.0",
1726
"undici-types": "^7.13.0"

0 commit comments

Comments
 (0)